Package sk.ipesoft.d2000.async
Class FutureEventWrapper<O,C>
- java.lang.Object
-
- sk.ipesoft.d2000.async.FutureEventWrapper<O,C>
-
- Type Parameters:
O- Type of original resultC- 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 ofFutureEventresults.
-
-
Constructor Summary
Constructors Constructor Description FutureEventWrapper(FutureEvent<O> wrapped)Wrapwrappedinto newFutureEventwith converted result.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddEventHandler(FutureEventHandler<C> futureEventHandler)Add handler for handling result of the future.voidaddEventHandler(FutureEventHandler<C> futureEventHandler, java.util.concurrent.Executor executor)Add handler for handling result of the future and executor with thread for execution of handling.booleancancel(boolean mayInterruptIfRunning)protected abstract CcreateResult(O value)Create result for the wrapper by converting originalvalue.Cget()Cget(long timeout, java.util.concurrent.TimeUnit unit)booleanisCancelled()booleanisDone()
-
-
-
Constructor Detail
-
FutureEventWrapper
public FutureEventWrapper(FutureEvent<O> wrapped)
Wrapwrappedinto newFutureEventwith 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 originalvalue. 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 intoExecutionExceptionand rethrown fromget().
-
addEventHandler
public void addEventHandler(FutureEventHandler<C> futureEventHandler)
Description copied from interface:FutureEventAdd handler for handling result of the future.In case that result of the future has been available prior this call, the
futureEventHandlerwill 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:
addEventHandlerin interfaceFutureEvent<O>- Parameters:
futureEventHandler- handler of future result
-
addEventHandler
public void addEventHandler(FutureEventHandler<C> futureEventHandler, java.util.concurrent.Executor executor)
Description copied from interface:FutureEventAdd 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
futureEventHandlerwill be passed to executor immediately. Otherwise it will be passed when result of the future is available.- Specified by:
addEventHandlerin interfaceFutureEvent<O>- Parameters:
futureEventHandler- handler of future resultexecutor- encapsulation of thread that will execute result's handling
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancelin interfacejava.util.concurrent.Future<O>
-
get
public C get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
getin interfacejava.util.concurrent.Future<O>- Throws:
java.lang.InterruptedExceptionjava.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:
getin interfacejava.util.concurrent.Future<O>- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfacejava.util.concurrent.Future<O>
-
isDone
public boolean isDone()
- Specified by:
isDonein interfacejava.util.concurrent.Future<O>
-
-