Package org.glassfish.grizzly.impl
Class SafeFutureImpl<R>
- java.lang.Object
-
- org.glassfish.grizzly.impl.SafeFutureImpl<R>
-
- All Implemented Interfaces:
Future<R>
,Cacheable
,GrizzlyFuture<R>
,FutureImpl<R>
public class SafeFutureImpl<R> extends Object implements FutureImpl<R>
SafeFutureImpl
implementation. (Based on the JDKFutureTask
)- See Also:
Future
-
-
Constructor Summary
Constructors Constructor Description SafeFutureImpl()
Creates SafeFutureImpl
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCompletionHandler(CompletionHandler<R> completionHandler)
Adds aCompletionHandler
, which will be notified once the asynchronous computation, represented by this Future, is complete.boolean
cancel(boolean mayInterruptIfRunning)
static <R> SafeFutureImpl<R>
create()
ConstructSafeFutureImpl
.protected void
done()
Protected method invoked when this task transitions to state isDone (whether normally or via cancellation).void
failure(Throwable failure)
Notify about the failure, occurred during asynchronous operation execution.R
get()
R
get(long timeout, TimeUnit unit)
R
getResult()
Get current result value without any blocking.boolean
isCancelled()
boolean
isDone()
void
markForRecycle(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 void
onComplete()
The method is called when this SafeFutureImpl is marked as completed.void
recycle()
void
recycle(boolean recycleResult)
Recycle GrizzlyFuture now.void
result(R result)
Set the result value and notify about operation completion.
-
-
-
Method Detail
-
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:
addCompletionHandler
in interfaceGrizzlyFuture<R>
- Parameters:
completionHandler
-CompletionHandler
-
create
public static <R> SafeFutureImpl<R> create()
ConstructSafeFutureImpl
.
-
result
public void result(R result)
Set the result value and notify about operation completion.- Specified by:
result
in interfaceFutureImpl<R>
- Parameters:
result
- the result value
-
failure
public void failure(Throwable failure)
Notify about the failure, occurred during asynchronous operation execution.- Specified by:
failure
in interfaceFutureImpl<R>
- Parameters:
failure
-
-
markForRecycle
public void markForRecycle(boolean recycleResult)
Description copied from interface:GrizzlyFuture
Mark 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:
markForRecycle
in 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:GrizzlyFuture
Recycle 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:
recycle
in interfaceGrizzlyFuture<R>
- Parameters:
recycleResult
- if true - the GrizzlyFuture result, if it support recyclable mechanism, will be also recycled together with this GrizzlyFuture object.
-
getResult
public R getResult()
Description copied from interface:FutureImpl
Get current result value without any blocking.- Specified by:
getResult
in 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:
isCancelled
in interfaceFuture<R>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
get
public R get() throws InterruptedException, ExecutionException
- Specified by:
get
in interfaceFuture<R>
- Throws:
CancellationException
InterruptedException
ExecutionException
-
get
public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
get
in interfaceFuture<R>
- Throws:
CancellationException
InterruptedException
ExecutionException
TimeoutException
-
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.
-
-