PushPullStageTIn, TOut Class |
Note: This API is now obsolete.
PushPullStageTIn, TOut implementations participate in 1-bounded regions. For every external non-completion signal these stages produce *exactly one* push or pull signal.
OnPush(TIn, IContext) is called when an element from upstream is available and there is demand from downstream, i.e. in OnPush(TIn, IContext) you are allowed to call Push(Object) to emit one element downstream, or you can absorb the element by calling Pull. Note that you can only emit zero or one element downstream from OnPull(IContext). To emit more than one element you have to push the remaining elements from OnPush(TIn, IContext), one-by-one. OnPush(TIn, IContext) is not called again until OnPull(IContext) has requested more elements with Pull.
StatefulStageTIn, TOut has support for making it easy to emit more than one element from OnPush(TIn, IContext).
OnPull(IContext)> is called when there is demand from downstream, i.e. you are allowed to push one element downstream with Push(Object), or request elements from upstreams with Pull. If you always perform transitive pull by calling Pull from OnPull(IContext) you can use PushStageTIn, TOut instead of PushPullStageTIn, TOut.
Stages are allowed to do early completion of downstream and cancel of upstream. This is done with Finish, which is a combination of cancel/complete.
Since OnComplete is not a backpressured signal it is sometimes preferable to push a final element and then immediately finish. This combination is exposed as PushAndFinish(Object) which enables stages to propagate completion events without waiting for an extra round of pull.
Another peculiarity is how to convert termination events (complete/failure) into elements. The problem here is that the termination events are not backpressured while elements are. This means that simply calling Push(Object) as a response to OnUpstreamFinish(IContext) or OnUpstreamFailure(Exception, IContext) will very likely break boundedness and result in a buffer overflow somewhere. Therefore the only allowed command in this case is AbsorbTermination which stops the propagation of the termination signal, and puts the stage in a IsFinishing state. Depending on whether the stage has a pending pull signal it has not yet "consumed" by a push its OnPull(IContext) handler might be called immediately or later. From OnPull(IContext) final elements can be pushed before completing downstream with Finish or PushAndFinish(Object).
StatefulStageTIn, TOut has support for making it easy to emit final elements.
All these rules are enforced by types and runtime checks where needed. Always return the Directive from the call to the IContext method, and do only call IContext commands once per callback.
Namespace: Akka.Streams.Stage
[ObsoleteAttribute("Please use GraphStage instead. [1.1.0]")] public abstract class PushPullStage<TIn, TOut> : AbstractStage<TIn, TOut, ISyncDirective, ISyncDirective, IContext<TOut>>
The PushPullStageTIn, TOut type exposes the following members.
Name | Description | |
---|---|---|
PushPullStageTIn, TOut | Initializes a new instance of the PushPullStageTIn, TOut class |
Name | Description | |
---|---|---|
IsDetached |
TBD
(Inherited from AbstractStageTIn, TOut.) |
Name | Description | |
---|---|---|
Decide |
If an exception is thrown from OnPush(TIn, IContext) this method is invoked to decide how
to handle the exception. By default this method returns Stop.
(Inherited from AbstractStageTIn, TOut.)If an exception is thrown from OnPull(IContext) 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(IContext) when it is know how to recover from such exceptions. | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OnDownstreamFinish(TContext) |
This method is called when downstream has cancelled.
By default the cancel signal is immediately propagated with Finish.
(Inherited from AbstractStageTIn, TOut, TPushDirective, TPullDirective, TContext.) | |
OnDownstreamFinish(IContext) |
This method is called when downstream has cancelled.
By default the cancel signal is immediately propagated with Finish.
(Inherited from AbstractStageTIn, TOut, TPushDirective, TPullDirective, TContext.) | |
OnPull(TContext) |
This method is called when there is demand from downstream, i.e. you are allowed to push one element
downstreams with Push(Object), or request elements from upstreams with Pull (Inherited from AbstractStageTIn, TOut, TPushDirective, TPullDirective, TContext.) | |
OnPull(IContext) |
This method is called when there is demand from downstream, i.e. you are allowed to push one element
downstreams with Push(Object), or request elements from upstreams with Pull (Inherited from AbstractStageTIn, TOut, TPushDirective, TPullDirective, TContext.) | |
OnPush(TIn, TContext) | This method is called when an element from upstream is available and there is demand from downstream, i.e. in OnPush(TIn, TContext) you are allowed to call Push(Object) to emit one element downstreams, or you can absorb the element by calling Pull. Note that you can only emit zero or one element downstream from OnPull(TContext). To emit more than one element you have to push the remaining elements from OnPull(TContext), one-by-one. OnPush(TIn, TContext) is not called again until OnPull(TContext) has requested more elements with Pull. | |
OnUpstreamFailure(Exception, IContext) | OnUpstreamFailure(Exception, IContext) is called when upstream has signaled that the stream is completed with failure. It is not called if OnPull(TContext) or OnPush(TIn, TContext) 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(Exception, IContext) is called, i.e. failures are not backpressured and might be propagated as soon as possible. Here you cannot call Push(Object), because there might not be any demand from downstream. To emit additional elements before terminating you can use AbsorbTermination and push final elements from OnPull(TContext). The stage will then be in finishing state, which can be checked with IsFinishing. | |
OnUpstreamFailure(Exception, TContext) | OnUpstreamFailure(Exception, IContext) is called when upstream has signaled that the stream is completed with failure. It is not called if OnPull(TContext) or OnPush(TIn, TContext) 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(Exception, IContext) is called, i.e. failures are not backpressured and might be propagated as soon as possible. Here you cannot call Push(Object), because there might not be any demand from downstream. To emit additional elements before terminating you can use AbsorbTermination and push final elements from OnPull(TContext). The stage will then be in finishing state, which can be checked with IsFinishing. | |
OnUpstreamFinish(TContext) | This method is called when upstream has signaled that the stream is successfully completed. Here you cannot call Push(Object), because there might not be any demand from downstream. To emit additional elements before terminating you can use AbsorbTermination and push final elements from OnPull(TContext). The stage will then be in finishing state, which can be checked with IsFinishing. By default the finish signal is immediately propagated with 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". | |
OnUpstreamFinish(IContext) | This method is called when upstream has signaled that the stream is successfully completed. Here you cannot call Push(Object), because there might not be any demand from downstream. To emit additional elements before terminating you can use AbsorbTermination and push final elements from OnPull(TContext). The stage will then be in finishing state, which can be checked with IsFinishing. By default the finish signal is immediately propagated with 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". | |
PostStop |
User overridable callback.
Is called after the Stages final action is performed.
Empty default implementation.
(Inherited from AbstractStageTIn, TOut.) | |
PreStart |
User overridable callback.
(Inherited from AbstractStageTIn, TOut.)It is called before any other method defined on the IStageTIn, TOut. Empty default implementation. | |
Restart |
Used to create a fresh instance of the stage after an error resulting in a 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.
(Inherited from AbstractStageTIn, TOut.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
Context |
TBD
(Inherited from AbstractStageTIn, TOut, TPushDirective, TPullDirective, TContext.) |
Name | Description | |
---|---|---|
AsInstanceOfT |
TBD
(Defined by Extensions.) | |
Match | Overloaded.
Matches the specified target.
(Defined by PatternMatch.) | |
MatchT | Overloaded.
Matches the specified target and return a result of target processing.
(Defined by PatternMatch.) |