org.glassfish.grizzly.impl
Class SafeFutureImpl<R>

java.lang.Object
  extended by java.util.concurrent.FutureTask<R>
      extended by org.glassfish.grizzly.impl.SafeFutureImpl<R>
All Implemented Interfaces:
Runnable, Future<R>, RunnableFuture<R>, Cacheable, GrizzlyFuture<R>, FutureImpl<R>

public class SafeFutureImpl<R>
extends FutureTask<R>
implements FutureImpl<R>

Safe FutureImpl implementation. (Based on the JDK FutureTask)

Author:
Alexey Stashok
See Also:
Future

Constructor Summary
SafeFutureImpl()
          Creates SafeFutureImpl
 
Method Summary
static
<R> SafeFutureImpl<R>
create()
          Construct SafeFutureImpl.
 void failure(Throwable failure)
          Notify about the failure, occurred during asynchronous operation execution.
 R getResult()
          Get current result value without any blocking.
 void markForRecycle(boolean recycleResult)
          Mark GrizzlyFuture as recycleable, so once result will come - GrizzlyFuture object will be recycled and returned to a thread local object pool.
 void recycle()
           
 void recycle(boolean recycleResult)
          Recycle GrizzlyFuture now.
 void result(R result)
          Set the result value and notify about operation completion.
 
Methods inherited from class java.util.concurrent.FutureTask
cancel, done, get, get, isCancelled, isDone, run, runAndReset, set, setException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.Future
cancel, get, get, isCancelled, isDone
 

Constructor Detail

SafeFutureImpl

public SafeFutureImpl()
Creates SafeFutureImpl

Method Detail

create

public static <R> SafeFutureImpl<R> create()
Construct SafeFutureImpl.


result

public void result(R result)
Set the result value and notify about operation completion.

Specified by:
result in interface FutureImpl<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 interface FutureImpl<R>
Parameters:
failure -

markForRecycle

public void markForRecycle(boolean recycleResult)
Description copied from interface: GrizzlyFuture
Mark GrizzlyFuture as recycleable, 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 interface GrizzlyFuture<R>
Parameters:
recycleResult - if true - the GrizzlyFuture result, if it support recycleable 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 interface GrizzlyFuture<R>
Parameters:
recycleResult - if true - the GrizzlyFuture result, if it support recycleable mechanism, will be also recycled together with this GrizzlyFuture object.

recycle

public void recycle()
Specified by:
recycle in interface Cacheable

getResult

public R getResult()
Description copied from interface: FutureImpl
Get current result value without any blocking.

Specified by:
getResult in interface FutureImpl<R>
Returns:
current result value without any blocking.


Copyright © 2012 Oracle Corporation. All Rights Reserved.