Search in sources :

Example 1 with AutoCloseableAsync

use of org.apache.flink.util.AutoCloseableAsync in project flink by apache.

the class RpcUtils method terminateAsyncCloseables.

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AutoCloseableAsync(org.apache.flink.util.AutoCloseableAsync) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AutoCloseableAsync (org.apache.flink.util.AutoCloseableAsync)1