Class FutureEventWrapper<O,C>

  • Type Parameters:
    O - Type of original result
    C - Type of converted result
    All Implemented Interfaces:
    java.util.concurrent.Future<O>, FutureEvent<C>


    public abstract class FutureEventWrapper<O,C>
    extends java.lang.Object
    implements FutureEvent<C>
    Base class for converters of FutureEvent results.
    • Constructor Summary

      Constructors 
      Constructor Description
      FutureEventWrapper​(FutureEvent<O> wrapped)
      Wrap wrapped into new FutureEvent with converted result.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addEventHandler​(FutureEventHandler<C> futureEventHandler)
      Add handler for handling result of the future.
      void addEventHandler​(FutureEventHandler<C> futureEventHandler, java.util.concurrent.Executor executor)
      Add handler for handling result of the future and executor with thread for execution of handling.
      boolean cancel​(boolean mayInterruptIfRunning)  
      protected abstract C createResult​(O value)
      Create result for the wrapper by converting original value.
      C get​()  
      C get​(long timeout, java.util.concurrent.TimeUnit unit)  
      boolean isCancelled​()  
      boolean isDone​()  
      • Methods inherited from class java.lang.Object

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

      • FutureEventWrapper

        public FutureEventWrapper​(FutureEvent<O> wrapped)
        Wrap wrapped into new FutureEvent with converted result.
        Parameters:
        wrapped - original
    • Method Detail

      • createResult

        protected abstract C createResult​(O value)
                                   throws java.lang.Exception
        Create result for the wrapper by converting original value. Method is called immediately after the original result is available.
        Parameters:
        value - original value
        Returns:
        converted value
        Throws:
        java.lang.Exception - when something bad happens. It would be wrapped into ExecutionException and rethrown from get().
      • addEventHandler

        public void addEventHandler​(FutureEventHandler<C> futureEventHandler)
        Description copied from interface: FutureEvent
        Add handler for handling result of the future.

        In case that result of the future has been available prior this call, the futureEventHandler will be invoked immediately on calling thread. Otherwise it will be invoked when result of the future is available on thread that provided result of the future.

        Warning: handling of the result should be quick, because it can slow-down the system. Use FutureEvent.addEventHandler(FutureEventHandler, Executor) for adding long-running handlers.

        Specified by:
        addEventHandler in interface FutureEvent<O>
        Parameters:
        futureEventHandler - handler of future result
      • addEventHandler

        public void addEventHandler​(FutureEventHandler<C> futureEventHandler,
                                    java.util.concurrent.Executor executor)
        Description copied from interface: FutureEvent
        Add handler for handling result of the future and executor with thread for execution of handling.

        In case that result of the future has been available prior this call, the futureEventHandler will be passed to executor immediately. Otherwise it will be passed when result of the future is available.

        Specified by:
        addEventHandler in interface FutureEvent<O>
        Parameters:
        futureEventHandler - handler of future result
        executor - encapsulation of thread that will execute result's handling
      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface java.util.concurrent.Future<O>
      • get

        public C get​()
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<O>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • get

        public C get​(long timeout,
                     java.util.concurrent.TimeUnit unit)
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException,
                     java.util.concurrent.TimeoutException
        Specified by:
        get in interface java.util.concurrent.Future<O>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • isCancelled

        public boolean isCancelled​()
        Specified by:
        isCancelled in interface java.util.concurrent.Future<O>
      • isDone

        public boolean isDone​()
        Specified by:
        isDone in interface java.util.concurrent.Future<O>