public abstract class AbstractStage<In,Out,PushD extends Directive,PullD extends Directive,Ctx extends Context<Out>,LifeCtx extends LifecycleContext> extends java.lang.Object implements Stage<In,Out>
Modifier and Type | Class and Description |
---|---|
static class |
AbstractStage.PushPullGraphStage<In,Out,Ext>
Deprecated.
|
static class |
AbstractStage.PushPullGraphStageWithMaterializedValue<In,Out,Ext,Mat>
Deprecated.
|
Constructor and Description |
---|
AbstractStage()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
Supervision.Directive |
decide(java.lang.Throwable t)
Deprecated.
If an exception is thrown from
onPush(In, Ctx) this method is invoked to decide how
to handle the exception. |
boolean |
isDetached()
Deprecated.
INTERNAL API
|
TerminationDirective |
onDownstreamFinish(Ctx ctx)
Deprecated.
onDownstreamFinish is called when downstream has canceled. |
abstract PullD |
onPull(Ctx ctx)
Deprecated.
onPull is called when there is demand from downstream, i.e. |
abstract PushD |
onPush(In elem,
Ctx ctx)
Deprecated.
onPush is called when an element from upstream is available and there is demand from downstream, i.e. |
TerminationDirective |
onUpstreamFailure(java.lang.Throwable cause,
Ctx ctx)
Deprecated.
onUpstreamFailure is called when upstream has signaled that the stream is completed
with failure. |
TerminationDirective |
onUpstreamFinish(Ctx ctx)
Deprecated.
onUpstreamFinish is called when upstream has signaled that the stream is
successfully completed. |
void |
postStop()
Deprecated.
User overridable callback.
|
void |
preStart(LifeCtx ctx)
Deprecated.
User overridable callback.
|
Stage<In,Out> |
restart()
Deprecated.
Used to create a fresh instance of the stage after an error resulting in a
Supervision.Restart
directive. |
public boolean isDetached()
public void preStart(LifeCtx ctx) throws java.lang.Exception
Stage
.
Empty default implementation.ctx
- (undocumented)java.lang.Exception
public abstract PushD onPush(In elem, Ctx ctx)
onPush
is called when an element from upstream is available and there is demand from downstream, i.e.
in onPush
you are allowed to call Context.push(Out)
to emit one element downstream,
or you can absorb the element by calling Context.pull()
. Note that you can only
emit zero or one element downstream from onPull
.
To emit more than one element you have to push the remaining elements from onPull(Ctx)
, one-by-one.
onPush
is not called again until onPull
has requested more elements with
Context.pull()
.
elem
- (undocumented)ctx
- (undocumented)public abstract PullD onPull(Ctx ctx)
onPull
is called when there is demand from downstream, i.e. you are allowed to push one element
downstream with Context.push(Out)
, or request elements from upstreams with
Context.pull()
ctx
- (undocumented)public TerminationDirective onUpstreamFinish(Ctx ctx)
onUpstreamFinish
is called when upstream has signaled that the stream is
successfully completed. Here you cannot call Context.push(Out)
,
because there might not be any demand from downstream. To emit additional elements before
terminating you can use Context.absorbTermination()
and push final elements
from onPull(Ctx)
. The stage will then be in finishing state, which can be checked
with Context.isFinishing()
.
By default the finish signal is immediately propagated with Context.finish()
.
*IMPORTANT NOTICE:* this signal is not back-pressured, it might arrive from upstream even though the last action by this stage was a “push”.
ctx
- (undocumented)public TerminationDirective onDownstreamFinish(Ctx ctx)
onDownstreamFinish
is called when downstream has canceled.
By default the cancel signal is immediately propagated with Context.finish()
.
ctx
- (undocumented)public TerminationDirective onUpstreamFailure(java.lang.Throwable cause, Ctx ctx)
onUpstreamFailure
is called when upstream has signaled that the stream is completed
with failure. It is not called if onPull(Ctx)
or onPush(In, Ctx)
of the stage itself
throws an exception.
Note that elements that were emitted by upstream before the failure happened might
not have been received by this stage when onUpstreamFailure
is called, i.e.
failures are not backpressured and might be propagated as soon as possible.
Here you cannot call Context.push(Out)
, because there might not
be any demand from downstream. To emit additional elements before terminating you
can use Context.absorbTermination()
and push final elements
from onPull(Ctx)
. The stage will then be in finishing state, which can be checked
with Context.isFinishing()
.
cause
- (undocumented)ctx
- (undocumented)public void postStop() throws java.lang.Exception
java.lang.Exception
public Supervision.Directive decide(java.lang.Throwable t)
onPush(In, Ctx)
this method is invoked to decide how
to handle the exception. By default this method returns Supervision.Stop
.
If an exception is thrown from onPull(Ctx)
the stream will always be completed with
failure, because it is not always possible to recover from that state.
In concrete stages it is of course possible to use ordinary try-catch-recover inside
onPull
when it is know how to recover from such exceptions.
t
- (undocumented)public Stage<In,Out> restart()
Supervision.Restart
directive. By default it will return the same instance untouched, so you must override it
if there are any state that should be cleared before restarting, e.g. by returning a new instance.