Class AbstractListenableFuture<T,​L extends GenericCompletionListener>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<GenericCompletionListener<? extends java.util.concurrent.Future<T>>> listeners
      Holds the list of listeners which will be notified upon completion.
      private java.util.concurrent.ExecutorService service
      The ExecutorService in which the notifications will be handled.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.concurrent.Future<T> addToListeners​(GenericCompletionListener<? extends java.util.concurrent.Future<T>> listener)
      Add the given listener to the total list of listeners to be notified.
      protected java.util.concurrent.ExecutorService executor()
      Returns the current executor.
      protected void notifyListener​(java.util.concurrent.ExecutorService executor, java.util.concurrent.Future<?> future, GenericCompletionListener listener)
      Notify a specific listener of completion.
      protected void notifyListeners()
      Notify all registered listeners of future completion.
      protected void notifyListeners​(java.util.concurrent.Future<?> future)
      Notify all registered listeners with a special future on completion.
      protected java.util.concurrent.Future<T> removeFromListeners​(GenericCompletionListener<? extends java.util.concurrent.Future<T>> listener)
      Remove a listener from the list of registered listeners.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.concurrent.Future

        cancel, get, get, isCancelled, isDone
    • Field Detail

      • service

        private final java.util.concurrent.ExecutorService service
        The ExecutorService in which the notifications will be handled.
      • listeners

        private java.util.List<GenericCompletionListener<? extends java.util.concurrent.Future<T>>> listeners
        Holds the list of listeners which will be notified upon completion.
    • Constructor Detail

      • AbstractListenableFuture

        protected AbstractListenableFuture​(java.util.concurrent.ExecutorService executor)
        Parameters:
        executor - the executor in which the callbacks will be executed in.
    • Method Detail

      • executor

        protected java.util.concurrent.ExecutorService executor()
        Returns the current executor.
        Returns:
        the current executor service.
      • addToListeners

        protected java.util.concurrent.Future<T> addToListeners​(GenericCompletionListener<? extends java.util.concurrent.Future<T>> listener)
        Add the given listener to the total list of listeners to be notified.

        If the future is already done, the listener will be notified immediately.

        Parameters:
        listener - the listener to add.
        Returns:
        the current future to allow chaining.
      • notifyListener

        protected void notifyListener​(java.util.concurrent.ExecutorService executor,
                                      java.util.concurrent.Future<?> future,
                                      GenericCompletionListener listener)
        Notify a specific listener of completion.
        Parameters:
        executor - the executor to use.
        future - the future to hand over.
        listener - the listener to notify.
      • notifyListeners

        protected void notifyListeners()
        Notify all registered listeners of future completion.
      • notifyListeners

        protected void notifyListeners​(java.util.concurrent.Future<?> future)
        Notify all registered listeners with a special future on completion. This method can be used if a different future should be used for notification than the current one (for example if an enclosing future is used, but the enclosed future should be notified on).
        Parameters:
        future - the future to pass on to the listeners.
      • removeFromListeners

        protected java.util.concurrent.Future<T> removeFromListeners​(GenericCompletionListener<? extends java.util.concurrent.Future<T>> listener)
        Remove a listener from the list of registered listeners.
        Parameters:
        listener - the listener to remove.
        Returns:
        the current future to allow for chaining.