Constructor and Description |
---|
ImmediateCancelled(Caller caller) |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel()
Cancel the current stage.
|
Throwable |
cause()
Get the cause of a failed stage.
|
Stage<T> |
handle(Handle<? super T> handle)
Register a listener that is called on all three types of events for the current stage; completed,
failed, and cancelled.
|
boolean |
isCancelled()
Check if stage is in the cancelled state.
|
boolean |
isCompleted()
Check if stage is completed.
|
boolean |
isDone()
Indicates if the stage is done
|
boolean |
isFailed()
Check if the stage was exceptionally completed.
|
T |
join()
Join the result of the current stage.
|
T |
join(long timeout,
TimeUnit unit)
Join the result of the current stage with a timeout.
|
T |
joinNow()
Join the result of the current stage, or fail if it's state is still running.
|
<U> Stage<U> |
thenApply(Function<? super T,? extends U> fn)
Transform the value of the current stage into another type using an immediate function.
|
Stage<T> |
thenApplyFailed(Function<? super Throwable,? extends T> fn)
Apply a failed stage.
|
<U> Stage<U> |
thenCancel()
Build a stage is cancelled, but waits until the current stage completes.
|
<U> Stage<U> |
thenComplete(U result)
Build a stage is completed, but waits until the current stage completes.
|
<U> Stage<U> |
thenCompose(Function<? super T,? extends Stage<U>> fn)
Compose the current stage with the given function.
|
Stage<T> |
thenComposeCaught(Function<? super Throwable,? extends Stage<T>> fn)
Compose a failed stage.
|
<U> Stage<U> |
thenFail(Throwable cause)
Build a stage is failed, but waits until the current stage completes.
|
String |
toString() |
Stage<T> |
whenCancelled(Runnable runnable)
Register an listener to be called when the current stage is cancelled.
|
Stage<T> |
whenComplete(Consumer<? super T> consumer)
Register a listener to be called when the current stage is completed.
|
Stage<T> |
whenDone(Runnable runnable)
Register a listener to be called when the current stage finishes for any reason.
|
Stage<T> |
whenFailed(Consumer<? super Throwable> consumer)
Register a listener that is called when a stage is failed.
|
Stage<T> |
withCloser(Supplier<? extends Stage<Void>> complete,
Supplier<? extends Stage<Void>> notComplete)
Run one of the provided stages when this stage ends up in a given state.
|
Stage<T> |
withComplete(Supplier<? extends Stage<Void>> supplier)
Run the provided stage when the current stage has completed.
|
Stage<T> |
withNotComplete(Supplier<? extends Stage<Void>> supplier)
Run the provided stage when the current stage ends, but does not complete.
|
protected final Caller caller
public ImmediateCancelled(Caller caller)
public boolean cancel()
Stage
public Stage<T> handle(Handle<? super T> handle)
Stage
public Stage<T> whenDone(Runnable runnable)
Stage
public Stage<T> whenCancelled(Runnable runnable)
Stage
whenCancelled
in interface Stage<T>
runnable
- listener to registerpublic Stage<T> whenComplete(Consumer<? super T> consumer)
Stage
whenComplete
in interface Stage<T>
consumer
- listener to registerpublic Stage<T> whenFailed(Consumer<? super Throwable> consumer)
Stage
whenFailed
in interface Stage<T>
consumer
- listener to registerpublic boolean isDone()
Stage
public boolean isCompleted()
Stage
isCompleted
in interface Stage<T>
true
if the stage is in a completed state, otherwise false
.public boolean isFailed()
Stage
isFailed
in interface Stage<T>
true
if the stage is exceptionally completedCompletable.fail(Throwable)
public boolean isCancelled()
Stage
isCancelled
in interface Stage<T>
true
if the stage is in a cancelled state, otherwise false
.public Throwable cause()
Stage
cause
in interface Stage<T>
Stage.isFailed()
public T join(long timeout, TimeUnit unit)
Stage
join
in interface Stage<T>
timeout
- timeout after which TimeoutException
will be
thrown.unit
- unit of the timeoutpublic T joinNow()
Stage
public <U> Stage<U> thenApply(Function<? super T,? extends U> fn)
Stage
Translates the result of a completed stage as it becomes available:
operation().thenApply(result -> result / 2);
public <U> Stage<U> thenCompose(Function<? super T,? extends Stage<U>> fn)
Stage
When the current stage has completed, calls the given function with the result of the current stage.
Stage<A> a = op1();
Stage<B> a.thenCompose(result -> op2(result));
thenCompose
in interface Stage<T>
U
- type of the composed stagefn
- the function to use when transforming the valuepublic Stage<T> thenApplyFailed(Function<? super Throwable,? extends T> fn)
Stage
This acts like a try-catch, where the provided function is the catch operation.
thenApplyFailed
in interface Stage<T>
fn
- the transformation to usepublic Stage<T> thenComposeCaught(Function<? super Throwable,? extends Stage<T>> fn)
Stage
This acts like a try-catch, where the composed stage is the catch operation.
If the intent is to re-throw after running the catch operation, use
Stage.withNotComplete(java.util.function.Supplier)
thenComposeCaught
in interface Stage<T>
fn
- the transformation to usepublic Stage<T> withCloser(Supplier<? extends Stage<Void>> complete, Supplier<? extends Stage<Void>> notComplete)
Stage
This is typically used to implement catch-then-rethrow style operations, like the following example:
beginTransaction().thenCompose(tx -> {
return oper2(tx).withCloser(tx::commit, tx::rollback);
});
withCloser
in interface Stage<T>
complete
- stage to run when this stage ends in a complete statenotComplete
- stage to run when this stage ends in a non-complete state, if the state is
failed, any exception thrown in this block will suppress the original exceptionpublic Stage<T> withComplete(Supplier<? extends Stage<Void>> supplier)
Stage
withComplete
in interface Stage<T>
supplier
- supplier of the stage to runpublic Stage<T> withNotComplete(Supplier<? extends Stage<Void>> supplier)
Stage
withNotComplete
in interface Stage<T>
supplier
- supplier of the stage to runpublic <U> Stage<U> thenFail(Throwable cause)
Stage
public <U> Stage<U> thenCancel()
Stage
thenCancel
in interface Stage<T>
U
- target typepublic <U> Stage<U> thenComplete(U result)
Stage
thenComplete
in interface Stage<T>
U
- target typeresult
- result to complete withCopyright © 2017. All rights reserved.