java.lang.Object
org.glassfish.grizzly.impl.SafeFutureImpl<R>
- All Implemented Interfaces:
Future<R>,Cacheable,GrizzlyFuture<R>,FutureImpl<R>
Safe
FutureImpl implementation.
(Based on the JDK FutureTask)- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCompletionHandler(CompletionHandler<R> completionHandler) Adds aCompletionHandler, which will be notified once the asynchronous computation, represented by this Future, is complete.booleancancel(boolean mayInterruptIfRunning) static <R> SafeFutureImpl<R>create()ConstructSafeFutureImpl.protected voiddone()Protected method invoked when this task transitions to state isDone (whether normally or via cancellation).voidNotify about the failure, occurred during asynchronous operation execution.get()Get current result value without any blocking.booleanbooleanisDone()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 voidThe method is called when this SafeFutureImpl is marked as completed.voidrecycle()voidrecycle(boolean recycleResult) Recycle GrizzlyFuture now.voidSet the result value and notify about operation completion.
-
Constructor Details
-
SafeFutureImpl
public SafeFutureImpl()Creates SafeFutureImpl
-
-
Method Details
-
addCompletionHandler
Adds aCompletionHandler, which will be notified once the asynchronous computation, represented by this Future, is complete.- Specified by:
addCompletionHandlerin interfaceGrizzlyFuture<R>- Parameters:
completionHandler-CompletionHandler
-
create
ConstructSafeFutureImpl. -
result
Set the result value and notify about operation completion.- Specified by:
resultin interfaceFutureImpl<R>- Parameters:
result- the result value
-
failure
Notify about the failure, occurred during asynchronous operation execution.- Specified by:
failurein interfaceFutureImpl<R>- Parameters:
failure-
-
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.
-
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.
-
recycle
public void recycle() -
getResult
Description copied from interface:FutureImplGet current result value without any blocking.- Specified by:
getResultin interfaceFutureImpl<R>- Returns:
- current result value without any blocking.
-
onComplete
protected void onComplete()The method is called when this SafeFutureImpl is marked as completed. Subclasses can override this method. -
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceFuture<R>
-
isDone
public boolean isDone() -
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
get
- Specified by:
getin interfaceFuture<R>- Throws:
CancellationExceptionInterruptedExceptionExecutionException
-
get
public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
getin interfaceFuture<R>- Throws:
CancellationExceptionInterruptedExceptionExecutionExceptionTimeoutException
-
done
protected void done()Protected method invoked when this task transitions to state isDone (whether normally or via cancellation). The default implementation does nothing. Subclasses may override this method to invoke completion callbacks or perform bookkeeping. Note that you can query status inside the implementation of this method to determine whether this task has been cancelled.
-