Package org.glassfish.grizzly.utils
Class Futures
- java.lang.Object
-
- org.glassfish.grizzly.utils.Futures
-
-
Constructor Summary
Constructors Constructor Description Futures()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <R> GrizzlyFuture<R>
createReadyFuture(Throwable error)
Create aFuture
, which has a preset failure.static <R> GrizzlyFuture<R>
createReadyFuture(R result)
Create aFuture
, which has a preset result.static <R> FutureImpl<R>
createSafeFuture()
Returns thread-safeFutureImpl
implementation.static <R> FutureImpl<R>
createUnsafeFuture()
Returns non thread-safeFutureImpl
implementation.static <R> void
notifyCancel(FutureImpl<R> future, CompletionHandler completionHandler)
Complete passedFutureImpl
andCompletionHandler
via the cancellation notification.static <R> void
notifyFailure(FutureImpl<R> future, CompletionHandler completionHandler, Throwable error)
Complete passedFutureImpl
andCompletionHandler
using the passed errorstatic <R> void
notifyResult(FutureImpl<R> future, CompletionHandler<R> completionHandler, R result)
Complete passedFutureImpl
andCompletionHandler
using the passed result object.static <A,B>
CompletionHandler<B>toAdaptedCompletionHandler(FutureImpl<A> future, CompletionHandler<A> completionHandler, GenericAdapter<B,A> adapter)
static <A,B>
CompletionHandler<B>toAdaptedCompletionHandler(FutureImpl<A> future, GenericAdapter<B,A> adapter)
CreatesCompletionHandler
, which may serve as a bridge for passedFutureImpl
.static <R> CompletionHandler<R>
toCompletionHandler(FutureImpl<R> future)
CreatesCompletionHandler
, which may serve as a bridge for passedFutureImpl
.static <R> CompletionHandler<R>
toCompletionHandler(FutureImpl<R> future, CompletionHandler<R> completionHandler)
CreatesCompletionHandler
, which may serve as a bridge for passedFutureImpl
andCompletionHandler
objects.
-
-
-
Method Detail
-
createSafeFuture
public static <R> FutureImpl<R> createSafeFuture()
Returns thread-safeFutureImpl
implementation. (Based on the JDKFutureTask
).- Returns:
- thread-safe
FutureImpl
implementation.
-
createUnsafeFuture
public static <R> FutureImpl<R> createUnsafeFuture()
Returns non thread-safeFutureImpl
implementation.- Returns:
- non thread-safe
FutureImpl
implementation.
-
createReadyFuture
public static <R> GrizzlyFuture<R> createReadyFuture(R result)
Create aFuture
, which has a preset result.- Parameters:
result
- the result- Returns:
- a
Future
, which has a preset result.
-
createReadyFuture
public static <R> GrizzlyFuture<R> createReadyFuture(Throwable error)
Create aFuture
, 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 passedFutureImpl
andCompletionHandler
using the passed result object.- Parameters:
future
-FutureImpl
to be notifiedcompletionHandler
-CompletionHandler
to be notifiedresult
- the result
-
notifyFailure
public static <R> void notifyFailure(FutureImpl<R> future, CompletionHandler completionHandler, Throwable error)
Complete passedFutureImpl
andCompletionHandler
using the passed error- Parameters:
future
-FutureImpl
to be notifiedcompletionHandler
-CompletionHandler
to be notifiederror
- the error.
-
notifyCancel
public static <R> void notifyCancel(FutureImpl<R> future, CompletionHandler completionHandler)
Complete passedFutureImpl
andCompletionHandler
via the cancellation notification.- Parameters:
future
-FutureImpl
to be notifiedcompletionHandler
-CompletionHandler
to be notified
-
toCompletionHandler
public static <R> CompletionHandler<R> toCompletionHandler(FutureImpl<R> future)
CreatesCompletionHandler
, which may serve as a bridge for passedFutureImpl
. All the notifications coming to the returnedCompletionHandler
will be passed to the passedFutureImpl
.- Returns:
CompletionHandler
, which may serve as a bridge for passedFutureImpl
. All the notifications coming to the returnedCompletionHandler
will be passed to the passedFutureImpl
.
-
toCompletionHandler
public static <R> CompletionHandler<R> toCompletionHandler(FutureImpl<R> future, CompletionHandler<R> completionHandler)
CreatesCompletionHandler
, which may serve as a bridge for passedFutureImpl
andCompletionHandler
objects. All the notifications coming to the returnedCompletionHandler
will be passed to theFutureImpl
andCompletionHandler
passed as parameters.- Returns:
CompletionHandler
, which may serve as a bridge for passedFutureImpl
andCompletionHandler
objects. All the notifications coming to the returnedCompletionHandler
will be passed to theFutureImpl
andCompletionHandler
passed as parameters.
-
toAdaptedCompletionHandler
public static <A,B> CompletionHandler<B> toAdaptedCompletionHandler(FutureImpl<A> future, GenericAdapter<B,A> adapter)
CreatesCompletionHandler
, which may serve as a bridge for passedFutureImpl
. All the notifications coming to the returnedCompletionHandler
will be adapted usingGenericAdapter
and passed to theFutureImpl
.- Returns:
CompletionHandler
, which may serve as a bridge for passedFutureImpl
. All the notifications coming to the returnedCompletionHandler
will be adapted usingGenericAdapter
and passed to theFutureImpl
.
-
toAdaptedCompletionHandler
public static <A,B> CompletionHandler<B> toAdaptedCompletionHandler(FutureImpl<A> future, CompletionHandler<A> completionHandler, GenericAdapter<B,A> adapter)
CreatesCompletionHandler
, which may serve as a bridge for passedFutureImpl
andCompletionHandler
. All the notifications coming to the returnedCompletionHandler
will be adapted usingGenericAdapter
and passed to theFutureImpl
andCompletionHandler
.- Returns:
CompletionHandler
, which may serve as a bridge for passedFutureImpl
andCompletionHandler
. All the notifications coming to the returnedCompletionHandler
will be adapted usingGenericAdapter
and passed to theFutureImpl
andCompletionHandler
.
-
-