org.glassfish.grizzly.utils
Class Futures

java.lang.Object
  extended by org.glassfish.grizzly.utils.Futures

public class Futures
extends Object

Set of utilities.

Author:
Alexey Stashok

Constructor Summary
Futures()
           
 
Method Summary
static
<R> Future<R>
createReadyFuture(R result)
          Create a Future, which has a preset result.
static
<R> Future<R>
createReadyFuture(Throwable error)
          Create a Future, which has a preset failure.
static
<R> FutureImpl<R>
createSafeFuture()
          Returns thread-safe FutureImpl implementation.
static
<R> FutureImpl<R>
createUnsafeFuture()
          Returns non thread-safe FutureImpl implementation.
static
<R> void
notifyCancel(FutureImpl<R> future, CompletionHandler completionHandler)
          Complete passed FutureImpl and CompletionHandler via the cancellation notification.
static
<R> void
notifyFailure(FutureImpl<R> future, CompletionHandler completionHandler, Throwable error)
          Complete passed FutureImpl and CompletionHandler using the passed error
static
<R> void
notifyResult(FutureImpl<R> future, CompletionHandler<R> completionHandler, R result)
          Complete passed FutureImpl and CompletionHandler using the passed result object.
static
<A,B> CompletionHandler<B>
toAdaptedCompletionHandler(FutureImpl<A> future, CompletionHandler<A> completionHandler, GenericAdapter<B,A> adapter)
          Creates CompletionHandler, which may serve as a bridge for passed FutureImpl and CompletionHandler.
static
<A,B> CompletionHandler<B>
toAdaptedCompletionHandler(FutureImpl<A> future, GenericAdapter<B,A> adapter)
          Creates CompletionHandler, which may serve as a bridge for passed FutureImpl.
static
<R> CompletionHandler<R>
toCompletionHandler(FutureImpl<R> future)
          Creates CompletionHandler, which may serve as a bridge for passed FutureImpl.
static
<R> CompletionHandler<R>
toCompletionHandler(FutureImpl<R> future, CompletionHandler<R> completionHandler)
          Creates CompletionHandler, which may serve as a bridge for passed FutureImpl and CompletionHandler objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Futures

public Futures()
Method Detail

createSafeFuture

public static <R> FutureImpl<R> createSafeFuture()
Returns thread-safe FutureImpl implementation. (Based on the JDK FutureTask).

Returns:
thread-safe FutureImpl implementation.

createUnsafeFuture

public static <R> FutureImpl<R> createUnsafeFuture()
Returns non thread-safe FutureImpl implementation.

Returns:
non thread-safe FutureImpl implementation.

createReadyFuture

public static <R> Future<R> createReadyFuture(R result)
Create a Future, which has a preset result.

Parameters:
result - the result
Returns:
a Future, which has a preset result.

createReadyFuture

public static <R> Future<R> createReadyFuture(Throwable error)
Create a Future, which has a preset failure.

Parameters:
error - the failure
Returns:
a Future, which has a preset failure.

notifyResult

public static <R> void notifyResult(FutureImpl<R> future,
                                    CompletionHandler<R> completionHandler,
                                    R result)
Complete passed FutureImpl and CompletionHandler using the passed result object.

Parameters:
future - FutureImpl to be notified
completionHandler - CompletionHandler to be notified
result - the result

notifyFailure

public static <R> void notifyFailure(FutureImpl<R> future,
                                     CompletionHandler completionHandler,
                                     Throwable error)
Complete passed FutureImpl and CompletionHandler using the passed error

Parameters:
future - FutureImpl to be notified
completionHandler - CompletionHandler to be notified
error - the error.

notifyCancel

public static <R> void notifyCancel(FutureImpl<R> future,
                                    CompletionHandler completionHandler)
Complete passed FutureImpl and CompletionHandler via the cancellation notification.

Parameters:
future - FutureImpl to be notified
completionHandler - CompletionHandler to be notified

toCompletionHandler

public static <R> CompletionHandler<R> toCompletionHandler(FutureImpl<R> future)
Creates CompletionHandler, which may serve as a bridge for passed FutureImpl. All the notifications coming to the returned CompletionHandler will be passed to the passed FutureImpl.

Returns:
CompletionHandler, which may serve as a bridge for passed FutureImpl. All the notifications coming to the returned CompletionHandler will be passed to the passed FutureImpl.

toCompletionHandler

public static <R> CompletionHandler<R> toCompletionHandler(FutureImpl<R> future,
                                                           CompletionHandler<R> completionHandler)
Creates CompletionHandler, which may serve as a bridge for passed FutureImpl and CompletionHandler objects. All the notifications coming to the returned CompletionHandler will be passed to the FutureImpl and CompletionHandler passed as parameters.

Returns:
CompletionHandler, which may serve as a bridge for passed FutureImpl and CompletionHandler objects. All the notifications coming to the returned CompletionHandler will be passed to the FutureImpl and CompletionHandler passed as parameters.

toAdaptedCompletionHandler

public static <A,B> CompletionHandler<B> toAdaptedCompletionHandler(FutureImpl<A> future,
                                                                    GenericAdapter<B,A> adapter)
Creates CompletionHandler, which may serve as a bridge for passed FutureImpl. All the notifications coming to the returned CompletionHandler will be adapted using GenericAdapter and passed to the FutureImpl.

Returns:
CompletionHandler, which may serve as a bridge for passed FutureImpl. All the notifications coming to the returned CompletionHandler will be adapted using GenericAdapter and passed to the FutureImpl.

toAdaptedCompletionHandler

public static <A,B> CompletionHandler<B> toAdaptedCompletionHandler(FutureImpl<A> future,
                                                                    CompletionHandler<A> completionHandler,
                                                                    GenericAdapter<B,A> adapter)
Creates CompletionHandler, which may serve as a bridge for passed FutureImpl and CompletionHandler. All the notifications coming to the returned CompletionHandler will be adapted using GenericAdapter and passed to the FutureImpl and CompletionHandler.

Returns:
CompletionHandler, which may serve as a bridge for passed FutureImpl and CompletionHandler. All the notifications coming to the returned CompletionHandler will be adapted using GenericAdapter and passed to the FutureImpl and CompletionHandler.


Copyright © 2012 Oracle Corporation. All Rights Reserved.