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-safeFutureImplimplementation.static <R> FutureImpl<R>createUnsafeFuture()Returns non thread-safeFutureImplimplementation.static <R> voidnotifyCancel(FutureImpl<R> future, CompletionHandler completionHandler)Complete passedFutureImplandCompletionHandlervia the cancellation notification.static <R> voidnotifyFailure(FutureImpl<R> future, CompletionHandler completionHandler, Throwable error)Complete passedFutureImplandCompletionHandlerusing the passed errorstatic <R> voidnotifyResult(FutureImpl<R> future, CompletionHandler<R> completionHandler, R result)Complete passedFutureImplandCompletionHandlerusing 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 passedFutureImplandCompletionHandlerobjects.
-
-
-
Method Detail
-
createSafeFuture
public static <R> FutureImpl<R> createSafeFuture()
Returns thread-safeFutureImplimplementation. (Based on the JDKFutureTask).- Returns:
- thread-safe
FutureImplimplementation.
-
createUnsafeFuture
public static <R> FutureImpl<R> createUnsafeFuture()
Returns non thread-safeFutureImplimplementation.- Returns:
- non thread-safe
FutureImplimplementation.
-
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 passedFutureImplandCompletionHandlerusing the passed result object.- Parameters:
future-FutureImplto be notifiedcompletionHandler-CompletionHandlerto be notifiedresult- the result
-
notifyFailure
public static <R> void notifyFailure(FutureImpl<R> future, CompletionHandler completionHandler, Throwable error)
Complete passedFutureImplandCompletionHandlerusing the passed error- Parameters:
future-FutureImplto be notifiedcompletionHandler-CompletionHandlerto be notifiederror- the error.
-
notifyCancel
public static <R> void notifyCancel(FutureImpl<R> future, CompletionHandler completionHandler)
Complete passedFutureImplandCompletionHandlervia the cancellation notification.- Parameters:
future-FutureImplto be notifiedcompletionHandler-CompletionHandlerto 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 returnedCompletionHandlerwill be passed to the passedFutureImpl.- Returns:
CompletionHandler, which may serve as a bridge for passedFutureImpl. All the notifications coming to the returnedCompletionHandlerwill 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 passedFutureImplandCompletionHandlerobjects. All the notifications coming to the returnedCompletionHandlerwill be passed to theFutureImplandCompletionHandlerpassed as parameters.- Returns:
CompletionHandler, which may serve as a bridge for passedFutureImplandCompletionHandlerobjects. All the notifications coming to the returnedCompletionHandlerwill be passed to theFutureImplandCompletionHandlerpassed 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 returnedCompletionHandlerwill be adapted usingGenericAdapterand passed to theFutureImpl.- Returns:
CompletionHandler, which may serve as a bridge for passedFutureImpl. All the notifications coming to the returnedCompletionHandlerwill be adapted usingGenericAdapterand 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 passedFutureImplandCompletionHandler. All the notifications coming to the returnedCompletionHandlerwill be adapted usingGenericAdapterand passed to theFutureImplandCompletionHandler.- Returns:
CompletionHandler, which may serve as a bridge for passedFutureImplandCompletionHandler. All the notifications coming to the returnedCompletionHandlerwill be adapted usingGenericAdapterand passed to theFutureImplandCompletionHandler.
-
-