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 ofFutureEvent
results.
-
-
Constructor Summary
Constructors Constructor Description FutureEventWrapper(FutureEvent<O> wrapped)
Wrapwrapped
into newFutureEvent
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 originalvalue
.C
get()
C
get(long timeout, java.util.concurrent.TimeUnit unit)
boolean
isCancelled()
boolean
isDone()
-
-
-
Constructor Detail
-
FutureEventWrapper
public FutureEventWrapper(FutureEvent<O> wrapped)
Wrapwrapped
into newFutureEvent
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 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 intoExecutionException
and rethrown fromget()
.
-
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 interfaceFutureEvent<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 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:
cancel
in interfacejava.util.concurrent.Future<O>
-
get
public C get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
get
in interfacejava.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 interfacejava.util.concurrent.Future<O>
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfacejava.util.concurrent.Future<O>
-
isDone
public boolean isDone()
- Specified by:
isDone
in interfacejava.util.concurrent.Future<O>
-
-