Class CompletionListenerFuture

  • All Implemented Interfaces:
    java.util.concurrent.Future<java.lang.Void>, CompletionListener

    public class CompletionListenerFuture
    extends java.lang.Object
    implements CompletionListener, java.util.concurrent.Future<java.lang.Void>
    A CompletionListenerFuture is a CompletionListener implementation that supports being used as a Future.

    For example:

    
     //create a completion future to use to wait for loadAll
     CompletionListenerFuture future = new CompletionListenerFuture();
     
     //load the values for the set of keys, replacing those that may already exist
     //in the cache
     cache.loadAll(keys, true, future);
     
     //wait for the cache to load the keys
     future.get();
     

    A CompletionListenerFuture may only be used once. Attempts to use an instance multiple times, as part of multiple asynchronous calls will result in an IllegalStateException being raised.

    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Exception exception  
      private boolean isCompleted  
      private java.lang.Object lock  
    • Constructor Summary

      Constructors 
      Constructor Description
      CompletionListenerFuture()
      Constructs a CompletionListenerFuture.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean cancel​(boolean b)
      Cancelling is not supported, always throws exception.
      java.lang.Void get()
      Waits if necessary for the operation to complete.
      java.lang.Void get​(long timeout, java.util.concurrent.TimeUnit unit)
      Waits if necessary for at most the given time for the operation to complete.
      boolean isCancelled()
      Cancelling is not supported, always returns false
      boolean isDone()  
      private void markAsCompleted()
      Mark operation as completed and wakeup all listeners, called under lock.
      void onCompletion()
      Notifies the application that the operation completed successfully.
      void onException​(java.lang.Exception e)
      Notifies the application that the operation failed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • lock

        private final java.lang.Object lock
      • isCompleted

        private boolean isCompleted
      • exception

        private java.lang.Exception exception
    • Constructor Detail

      • CompletionListenerFuture

        public CompletionListenerFuture()
        Constructs a CompletionListenerFuture.
    • Method Detail

      • onCompletion

        public void onCompletion()
                          throws java.lang.IllegalStateException
        Notifies the application that the operation completed successfully.
        Specified by:
        onCompletion in interface CompletionListener
        Throws:
        java.lang.IllegalStateException - if the instance is used more than once
      • onException

        public void onException​(java.lang.Exception e)
                         throws java.lang.IllegalStateException
        Notifies the application that the operation failed.
        Specified by:
        onException in interface CompletionListener
        Parameters:
        e - the Exception that occurred
        Throws:
        java.lang.IllegalStateException - if the instance is used more than once
      • markAsCompleted

        private void markAsCompleted()
        Mark operation as completed and wakeup all listeners, called under lock.
      • cancel

        public boolean cancel​(boolean b)
        Cancelling is not supported, always throws exception.
        Specified by:
        cancel in interface java.util.concurrent.Future<java.lang.Void>
        Throws:
        java.lang.UnsupportedOperationException - thrown always
      • isCancelled

        public boolean isCancelled()
        Cancelling is not supported, always returns false
        Specified by:
        isCancelled in interface java.util.concurrent.Future<java.lang.Void>
        Returns:
        always false.
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface java.util.concurrent.Future<java.lang.Void>
      • get

        public java.lang.Void get()
                           throws java.lang.InterruptedException,
                                  java.util.concurrent.ExecutionException
        Waits if necessary for the operation to complete. Always returns null.
        Specified by:
        get in interface java.util.concurrent.Future<java.lang.Void>
        Returns:
        always null
        Throws:
        java.util.concurrent.ExecutionException - if the computation threw an exception. This wraps the exception received by (Exception)
        java.lang.InterruptedException - if the current thread was interrupted while waiting
      • get

        public java.lang.Void get​(long timeout,
                                  java.util.concurrent.TimeUnit unit)
                           throws java.lang.InterruptedException,
                                  java.util.concurrent.ExecutionException,
                                  java.util.concurrent.TimeoutException
        Waits if necessary for at most the given time for the operation to complete. Always returns null.
        Specified by:
        get in interface java.util.concurrent.Future<java.lang.Void>
        Parameters:
        timeout - the maximum time to wait
        unit - the time unit of the timeout argument
        Returns:
        always null
        Throws:
        java.util.concurrent.ExecutionException - if the computation threw an exception. This wraps the exception received by (Exception)
        java.lang.InterruptedException - if the current thread was interrupted while waiting
        java.util.concurrent.TimeoutException - if the wait timed out