Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.infinispan.commons.util.concurrent;
 
 import java.util.List;
Utilities for org.infinispan.commons.util.concurrent.NotifyingFuture composition.

Author(s):
gustavonalle
Since:
7.1
public final class Futures {
   private Futures() {
   }

   
Returns a new org.infinispan.commons.util.concurrent.NotifyingFuture that will be completed when all of the given futures completes.

Parameters:
futures List of NotifyingFutures
Returns:
a new composite NotifyingFuture
   public static <T> NotifyingFuture<List<T>> combine(final List<NotifyingFuture<T>> futures) {
      if (futures == null || futures.isEmpty()) return new NoOpFuture<>(null);
      return new CompositeNotifyingFuture<>(futures);
   }

   
   public static <T> NotifyingFuture<VoidandThen(final NotifyingFuture<T> futurefinal Runnable after) {
      return andThen(futureafter, Executors.newSingleThreadExecutor());
   }

   
Executes a task asynchronously after a future completion

Parameters:
future NotifyingFuture input
after Runnable to be executed after the input future completion
executorService The executor in order to run the task
Returns:
NotifyingFuture with the result
   public static <T> NotifyingFuture<VoidandThen(final NotifyingFuture<T> futurefinal Runnable afterfinal ExecutorService executorService) {
      final NotifyingFutureImpl<Voidresult = new NotifyingFutureImpl<>();
      final CountDownLatch countDownLatch = new CountDownLatch(1);
      Future afterFuture = executorService.submit(new Runnable() {
         @Override
         public void run() {
            try {
               countDownLatch.await();
               future.get();
               after.run();
               result.notifyDone(null);
            } catch (InterruptedException e) {
               future.cancel(true);
               Thread.currentThread().interrupt();
            } catch (Exception e) {
               result.notifyException(e);
            }
         }
      });
      result.setFuture(afterFuture);
      FutureListener<T> listener = new FutureListener<T>() {
         @Override
         public void futureDone(Future<T> future) {
            countDownLatch.countDown();
         }
      };
      future.attachListener(listener);
      return result;
   }
New to GrepCode? Check out our FAQ X