Top Description Fields Constructors Methods
org.glassfish.grizzly.impl

public final Class UnsafeFutureImpl<R>

extends Object
implements FutureImpl<R>
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.impl.FutureImpl, org.glassfish.grizzly.GrizzlyFuture, org.glassfish.grizzly.Cacheable, java.util.concurrent.Future
Imports
java.util.HashSet, .Set, java.util.concurrent.CancellationException, .ExecutionException, .Future, .TimeUnit, .TimeoutException, org.glassfish.grizzly.Cacheable, .CompletionHandler, .ThreadCache

Simple thread-unsafe Future implementation.
Author
Alexey Stashok
See Also
Future

Field Summary

Modifier and TypeField and Description
private static final ThreadCache.CachedTypeIndex<UnsafeFutureImpl<R>>
protected Set<CompletionHandler<R>>
protected Throwable
protected boolean
protected boolean
protected int
protected R

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
addCompletionHandler(final CompletionHandler<R> completionHandler)

Implements org.glassfish.grizzly.GrizzlyFuture.addCompletionHandler.

Adds a CompletionHandler, which will be notified once the asynchronous computation, represented by this Future, is complete.

public boolean
cancel(boolean mayInterruptIfRunning)

Implements java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task.

public static <R> UnsafeFutureImpl<R>
create()

Construct Future.

public void
failure(Throwable failure)

Implements org.glassfish.grizzly.impl.FutureImpl.failure.

Notify about the failure, occurred during asynchronous operation execution.

public R
get()

Implements java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

public R
get(long timeout, TimeUnit unit)

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

public R

Returns:

current result value without any blocking.
getResult
()

Implements org.glassfish.grizzly.impl.FutureImpl.getResult.

Get current result value without any blocking.

public boolean
isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

public boolean
isDone()

Implements java.util.concurrent.Future.isDone.

Returns true if this task completed.

public void
markForRecycle(boolean recycleResult)

Implements org.glassfish.grizzly.GrizzlyFuture.markForRecycle.

Mark GrizzlyFuture as recyclable, so once result will come - GrizzlyFuture object will be recycled and returned to a thread local object pool.

private void
notifyCompletionHandler(final CompletionHandler<R> completionHandler)

Notify single CompletionHandler about the result.

private void
notifyCompletionHandlers()

Notify registered CompletionHandlers about the result.

protected void
notifyHaveResult()

Notify blocked listeners threads about operation completion.

public void
recycle(boolean recycleResult)

Implements org.glassfish.grizzly.GrizzlyFuture.recycle.

Recycle GrizzlyFuture now.

public void
protected void
public void
result(R
the result value
result
)

Implements org.glassfish.grizzly.impl.FutureImpl.result.

Set the result value and notify about operation completion.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CACHE_IDXback to summary
private static final ThreadCache.CachedTypeIndex<UnsafeFutureImpl<R>> CACHE_IDX
completionHandlersback to summary
protected Set<CompletionHandler<R>> completionHandlers
failureback to summary
protected Throwable failure
isCancelledback to summary
protected boolean isCancelled
isDoneback to summary
protected boolean isDone
recycleMarkback to summary
protected int recycleMark
resultback to summary
protected R result

Constructor Detail

UnsafeFutureImplback to summary
private UnsafeFutureImpl()

Method Detail

addCompletionHandlerback to summary
public void addCompletionHandler(final CompletionHandler<R> completionHandler)

Implements org.glassfish.grizzly.GrizzlyFuture.addCompletionHandler.

Doc from org.glassfish.grizzly.GrizzlyFuture.addCompletionHandler.

Adds a CompletionHandler, which will be notified once the asynchronous computation, represented by this Future, is complete.

Annotations
@Override
cancelback to summary
public boolean cancel(boolean mayInterruptIfRunning)

Implements java.util.concurrent.Future.cancel.

Doc from java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task. This method has no effect if the task is already completed or cancelled, or could not be cancelled for some other reason. Otherwise, if this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task (when known by the implementation) is interrupted in an attempt to stop the task.

The return value from this method does not necessarily indicate whether the task is now cancelled; use isCancelled.

Annotations
@Override
createback to summary
public static <R> UnsafeFutureImpl<R> create()

Construct Future.

Annotations
@SuppressWarnings:unchecked
failureback to summary
public void failure(Throwable failure)

Implements org.glassfish.grizzly.impl.FutureImpl.failure.

Notify about the failure, occurred during asynchronous operation execution.

Annotations
@Override
getback to summary
public R get() throws InterruptedException, ExecutionException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

Annotations
@Override
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception
getback to summary
public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Annotations
@Override
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception
TimeoutException:
if the wait timed out
getResultback to summary
public R getResult()

Implements org.glassfish.grizzly.impl.FutureImpl.getResult.

Get current result value without any blocking.

Returns:R

current result value without any blocking.

Annotations
@Override
isCancelledback to summary
public boolean isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Doc from java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

Annotations
@Override
isDoneback to summary
public boolean isDone()

Implements java.util.concurrent.Future.isDone.

Doc from java.util.concurrent.Future.isDone.

Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

Annotations
@Override
markForRecycleback to summary
public void markForRecycle(boolean recycleResult)

Implements org.glassfish.grizzly.GrizzlyFuture.markForRecycle.

Doc from org.glassfish.grizzly.GrizzlyFuture.markForRecycle.

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.

Annotations
@Override
notifyCompletionHandlerback to summary
private void notifyCompletionHandler(final CompletionHandler<R> completionHandler)

Notify single CompletionHandler about the result.

notifyCompletionHandlersback to summary
private void notifyCompletionHandlers()

Notify registered CompletionHandlers about the result.

notifyHaveResultback to summary
protected void notifyHaveResult()

Notify blocked listeners threads about operation completion.

recycleback to summary
public void recycle(boolean recycleResult)

Implements org.glassfish.grizzly.GrizzlyFuture.recycle.

Doc from org.glassfish.grizzly.GrizzlyFuture.recycle.

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.

Annotations
@Override
recycleback to summary
public void recycle()

Implements org.glassfish.grizzly.Cacheable.recycle.

Annotations
@Override
resetback to summary
protected void reset()
resultback to summary
public void result(R result)

Implements org.glassfish.grizzly.impl.FutureImpl.result.

Set the result value and notify about operation completion.

Parameters
result:R

the result value

Annotations
@Override