Package com.google.code.yanf4j.core.impl
Class FutureImpl<R>
- java.lang.Object
-
- com.google.code.yanf4j.core.impl.FutureImpl<R>
-
- All Implemented Interfaces:
java.util.concurrent.Future<R>
- Direct Known Subclasses:
ConnectFuture
public class FutureImpl<R> extends java.lang.Object implements java.util.concurrent.Future<R>SimpleFutureimplementation, which uses synchronizationObjectto synchronize during the lifecycle.- See Also:
Future
-
-
Constructor Summary
Constructors Constructor Description FutureImpl()FutureImpl(java.lang.Object sync)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancancel(boolean mayInterruptIfRunning)voidfailure(java.lang.Throwable failure)Notify about the failure, occured during asynchronous operation execution.Rget()Rget(long timeout, java.util.concurrent.TimeUnit unit)RgetResult()Get current result value without any blocking.booleanisCancelled()booleanisDone()protected voidnotifyHaveResult()Notify blocked listeners threads about operation completion.voidsetResult(R result)Set the result value and notify about operation completion.
-
-
-
Field Detail
-
sync
private final java.lang.Object sync
-
isDone
private boolean isDone
-
isCancelled
private boolean isCancelled
-
failure
private java.lang.Throwable failure
-
result
protected R result
-
-
Method Detail
-
getResult
public R getResult()
Get current result value without any blocking.- Returns:
- current result value without any blocking.
-
setResult
public void setResult(R result)
Set the result value and notify about operation completion.- Parameters:
result- the result value
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancelin interfacejava.util.concurrent.Future<R>
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfacejava.util.concurrent.Future<R>
-
isDone
public boolean isDone()
- Specified by:
isDonein interfacejava.util.concurrent.Future<R>
-
get
public R get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
getin interfacejava.util.concurrent.Future<R>- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionException
-
get
public R 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<R>- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException
-
failure
public void failure(java.lang.Throwable failure)
Notify about the failure, occured during asynchronous operation execution.- Parameters:
failure-
-
notifyHaveResult
protected void notifyHaveResult()
Notify blocked listeners threads about operation completion.
-
-