Package org.glassfish.grizzly.impl
Class UnsafeFutureImpl<R>
- java.lang.Object
-
- org.glassfish.grizzly.impl.UnsafeFutureImpl<R>
-
- All Implemented Interfaces:
java.util.concurrent.Future<R>,Cacheable,GrizzlyFuture<R>,FutureImpl<R>
public final class UnsafeFutureImpl<R> extends java.lang.Object implements FutureImpl<R>
Simple thread-unsafeFutureimplementation.- Author:
- Alexey Stashok
- See Also:
Future
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<CompletionHandler<R>>completionHandlersprotected java.lang.Throwablefailureprotected booleanisCancelledprotected booleanisDoneprotected intrecycleMarkprotected Rresult
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCompletionHandler(CompletionHandler<R> completionHandler)Adds aCompletionHandler, which will be notified once the asynchronous computation, represented by this Future, is complete.booleancancel(boolean mayInterruptIfRunning)static <R> UnsafeFutureImpl<R>create()ConstructFuture.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()voidmarkForRecycle(boolean recycleResult)Mark GrizzlyFuture as recyclable, so once result will come - GrizzlyFuture object will be recycled and returned to a thread local object pool.protected voidnotifyHaveResult()Notify blocked listeners threads about operation completion.voidrecycle()voidrecycle(boolean recycleResult)Recycle GrizzlyFuture now.protected voidreset()voidresult(R result)Set the result value and notify about operation completion.
-
-
-
Field Detail
-
isDone
protected boolean isDone
-
isCancelled
protected boolean isCancelled
-
failure
protected java.lang.Throwable failure
-
completionHandlers
protected java.util.Set<CompletionHandler<R>> completionHandlers
-
result
protected R result
-
recycleMark
protected int recycleMark
-
-
Method Detail
-
create
public static <R> UnsafeFutureImpl<R> create()
ConstructFuture.
-
addCompletionHandler
public void addCompletionHandler(CompletionHandler<R> completionHandler)
Adds aCompletionHandler, which will be notified once the asynchronous computation, represented by this Future, is complete.- Specified by:
addCompletionHandlerin interfaceGrizzlyFuture<R>- Parameters:
completionHandler-CompletionHandler
-
getResult
public R getResult()
Get current result value without any blocking.- Specified by:
getResultin interfaceFutureImpl<R>- Returns:
- current result value without any blocking.
-
result
public void result(R result)
Set the result value and notify about operation completion.- Specified by:
resultin interfaceFutureImpl<R>- 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.- Specified by:
failurein interfaceFutureImpl<R>- Parameters:
failure-
-
notifyHaveResult
protected void notifyHaveResult()
Notify blocked listeners threads about operation completion.
-
markForRecycle
public void markForRecycle(boolean recycleResult)
Description copied from interface:GrizzlyFutureMark GrizzlyFuture as recyclable, so once result will come - GrizzlyFuture object will be recycled and returned to a thread local object pool. You can consider to use this method, if you're not interested in using this GrizzlyFuture object.- Specified by:
markForRecyclein interfaceGrizzlyFuture<R>- Parameters:
recycleResult- if true - the GrizzlyFuture result, if it support recyclable mechanism, will be also recycled together with this GrizzlyFuture object.
-
reset
protected void reset()
-
recycle
public void recycle(boolean recycleResult)
Description copied from interface:GrizzlyFutureRecycle GrizzlyFuture now. This method could be used, if you're not interested in using this GrizzlyFuture object, and you're sure this object is not used by any other application part.- Specified by:
recyclein interfaceGrizzlyFuture<R>- Parameters:
recycleResult- if true - the GrizzlyFuture result, if it support recyclable mechanism, will be also recycled together with this GrizzlyFuture object.
-
-