Package org.pipecraft.infra.concurrent
Class CheckedFutureTransformer<S,T,E extends Exception>
- java.lang.Object
-
- org.pipecraft.infra.concurrent.CheckedFutureTransformer<S,T,E>
-
- All Implemented Interfaces:
com.google.common.util.concurrent.ListenableFuture<T>,Future<T>,CheckedFuture<T,E>
public class CheckedFutureTransformer<S,T,E extends Exception> extends Object implements CheckedFuture<T,E>
ACheckedFuturedecorator converting a checked future with value type S to a checked future with value type T. Preserves the exception type.- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description CheckedFutureTransformer(AbstractCheckedFuture<S,E> future, Function<S,T> mappingFunction)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(Runnable listener, Executor executor)booleancancel(boolean mayInterruptIfRunning)TcheckedGet()A simplified version ofFuture.get()which mapsExecutionExceptionto a more indicative exception typeTcheckedGet(long timeout, TimeUnit unit)A simplified version ofFuture.get(long, TimeUnit)which mapsExecutionExceptionto a more indicative exception typeTget()Tget(long timeout, TimeUnit unit)booleanisCancelled()booleanisDone()
-
-
-
Method Detail
-
checkedGet
public T checkedGet() throws InterruptedException, E extends Exception
A simplified version ofFuture.get()which mapsExecutionExceptionto a more indicative exception type- Specified by:
checkedGetin interfaceCheckedFuture<S,T>- Returns:
- the result of executing the future.
- Throws:
InterruptedException- When the waiting for completion is interruptedE- when an execution exception is detected and mappedCancellationException- if the computation was cancelledE extends Exception
-
checkedGet
public T checkedGet(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException, E extends Exception
A simplified version ofFuture.get(long, TimeUnit)which mapsExecutionExceptionto a more indicative exception type- Specified by:
checkedGetin interfaceCheckedFuture<S,T>- Parameters:
timeout- The timeout to applyunit- The time unit of the timeout parameter- Returns:
- the result of executing the future.
- Throws:
TimeoutException- In case that the timeout period elapsesInterruptedException- When the waiting for completion is interruptedE- when an execution exception is detected and mappedCancellationException- if the computation was cancelledE extends Exception
-
addListener
public void addListener(Runnable listener, Executor executor)
- Specified by:
addListenerin interfacecom.google.common.util.concurrent.ListenableFuture<S>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfaceFuture<S>
-
get
public T get() throws InterruptedException, ExecutionException
- Specified by:
getin interfaceFuture<S>- Throws:
InterruptedExceptionExecutionException
-
get
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
getin interfaceFuture<S>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
-