Java源码示例:org.apache.flink.util.AutoCloseableAsync
示例1
private FutureUtils.ConjunctFuture<Void> closeHandlersAsync() {
return FutureUtils.waitForAll(handlers.stream()
.map(tuple -> tuple.f1)
.filter(handler -> handler instanceof AutoCloseableAsync)
.map(handler -> ((AutoCloseableAsync) handler).closeAsync())
.collect(Collectors.toList()));
}
示例2
private FutureUtils.ConjunctFuture<Void> closeHandlersAsync() {
return FutureUtils.waitForAll(handlers.stream()
.map(tuple -> tuple.f1)
.filter(handler -> handler instanceof AutoCloseableAsync)
.map(handler -> ((AutoCloseableAsync) handler).closeAsync())
.collect(Collectors.toList()));
}
示例3
/**
* Shuts the given rpc services down and waits for their termination.
*
* @param rpcServices to shut down
* @param timeout for this operation
* @throws InterruptedException if the operation has been interrupted
* @throws ExecutionException if a problem occurred
* @throws TimeoutException if a timeout occurred
*/
public static void terminateRpcServices(
Time timeout,
RpcService... rpcServices) throws InterruptedException, ExecutionException, TimeoutException {
terminateAsyncCloseables(
Arrays.stream(rpcServices)
.map(rpcService -> (AutoCloseableAsync) rpcService::stopService)
.collect(Collectors.toList()),
timeout);
}
示例4
private static void terminateAsyncCloseables(Collection<? extends AutoCloseableAsync> closeables, Time timeout) throws InterruptedException, ExecutionException, TimeoutException {
final Collection<CompletableFuture<?>> terminationFutures = new ArrayList<>(closeables.size());
for (AutoCloseableAsync closeableAsync : closeables) {
if (closeableAsync != null) {
terminationFutures.add(closeableAsync.closeAsync());
}
}
FutureUtils.waitForAll(terminationFutures).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
}
示例5
private FutureUtils.ConjunctFuture<Void> closeHandlersAsync() {
return FutureUtils.waitForAll(handlers.stream()
.map(tuple -> tuple.f1)
.filter(handler -> handler instanceof AutoCloseableAsync)
.map(handler -> ((AutoCloseableAsync) handler).closeAsync())
.collect(Collectors.toList()));
}