Class AbstractListenableFuture<T,L extends GenericCompletionListener>

java.lang.Object
net.spy.memcached.compat.SpyObject
net.spy.memcached.internal.AbstractListenableFuture<T,L>
All Implemented Interfaces:
Future<T>, ListenableFuture<T,L>
Direct Known Subclasses:
BulkGetFuture, GetFuture, OperationFuture

public abstract class AbstractListenableFuture<T,L extends GenericCompletionListener> extends SpyObject implements ListenableFuture<T,L>
The AbstractListenableFuture implements common functionality shared by all futures that implement the ListenableFuture. It handles storage and notification of listeners and making sure this is done in a thread-safe manner. The subclassing methods need to implement the abstract methods, which in turn need to call both addToListeners(GenericCompletionListener) and removeFromListeners(GenericCompletionListener). See the OperationFuture as an example.
  • Field Details

  • Constructor Details

    • AbstractListenableFuture

      protected AbstractListenableFuture(ExecutorService executor)
      Parameters:
      executor - the executor in which the callbacks will be executed in.
  • Method Details

    • executor

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

      protected Future<T> addToListeners(GenericCompletionListener<? extends 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(ExecutorService executor, 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(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 Future<T> removeFromListeners(GenericCompletionListener<? extends 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.