public abstract class DetachedStage<In,Out> extends AbstractStage<In,Out,UpstreamDirective,DownstreamDirective,DetachedContext<Out>,LifecycleContext>
DetachedStage
can be used to implement operations similar to buffer
,
expand
and conflate
.
DetachedStage
implementations are boundaries between 1-bounded regions. This means that they need to enforce the
"exactly one" property both on their upstream and downstream regions. As a consequence a DetachedStage
can never
answer an AbstractStage.onPull(Ctx)
with a Context.pull()
or answer an AbstractStage.onPush(In, Ctx)
with a Context.push(Out)
since such an action
would "steal" the event from one region (resulting in zero signals) and would inject it to the other region
(resulting in two signals).
However, DetachedStages have the ability to call akka.stream.stage.DetachedContext#hold
as a response to
AbstractStage.onPush(In, Ctx)
and AbstractStage.onPull(Ctx)
which temporarily takes the signal off and
stops execution, at the same time putting the stage in an akka.stream.stage.DetachedContext#isHolding
state.
If the stage is in a holding state it contains one absorbed signal, therefore in this state the only possible
command to call is DetachedContext.pushAndPull(Out)
which results in two events making the
balance right again: 1 hold + 1 external event = 2 external event
This mechanism allows synchronization between the upstream and downstream regions which otherwise can progress independently.
PushPullStage
AbstractStage.PushPullGraphStage<In,Out,Ext>, AbstractStage.PushPullGraphStageWithMaterializedValue<In,Out,Ext,Mat>
Constructor and Description |
---|
DetachedStage()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
Supervision.Directive |
decide(java.lang.Throwable t)
Deprecated.
If an exception is thrown from
AbstractStage.onPush(In, Ctx) this method is invoked to decide how
to handle the exception. |
boolean |
isDetached()
Deprecated.
INTERNAL API
|
onDownstreamFinish, onPull, onPush, onUpstreamFailure, onUpstreamFinish, postStop, preStart, restart
public boolean isDetached()
AbstractStage
isDetached
in class AbstractStage<In,Out,UpstreamDirective,DownstreamDirective,DetachedContext<Out>,LifecycleContext>
public Supervision.Directive decide(java.lang.Throwable t)
AbstractStage.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 AbstractStage.onPull(Ctx)
or if the stage is holding state 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.
decide
in class AbstractStage<In,Out,UpstreamDirective,DownstreamDirective,DetachedContext<Out>,LifecycleContext>
t
- (undocumented)