akka.stream.stage

PushPullStage

abstract class PushPullStage[In, Out] extends AbstractStage[In, Out, SyncDirective, SyncDirective, Context[Out], LifecycleContext]

PushPullStage implementations participate in 1-bounded regions. For every external non-completion signal these stages produce *exactly one* push or pull signal.

#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 to emit one element downstreams, 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, one-by-one. onPush is not called again until onPull has requested more elements with Context#pull.

StatefulStage has support for making it easy to emit more than one element from onPush.

#onPull is called when there is demand from downstream, i.e. you are allowed to push one element downstreams with Context#push, or request elements from upstreams with Context#pull. If you always perform transitive pull by calling ctx.pull from onPull you can use PushStage instead of PushPullStage.

Stages are allowed to do early completion of downstream and cancel of upstream. This is done with Context#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 Context#pushAndFinish 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 Context#push as a response to #onUpstreamFinish or #onUpstreamFailure will very likely break boundedness and result in a buffer overflow somewhere. Therefore the only allowed command in this case is Context#absorbTermination which stops the propagation of the termination signal, and puts the stage in a akka.stream.stage.Context#isFinishing state. Depending on whether the stage has a pending pull signal it has not yet "consumed" by a push its #onPull handler might be called immediately or later. From #onPull final elements can be pushed before completing downstream with Context#finish or Context#pushAndFinish.

StatefulStage 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 Context method, and do only call Context commands once per callback.

Source
Stage.scala
See also

PushStage

StatefulStage

DetachedStage

Linear Supertypes
Known Subclasses
Type Hierarchy Learn more about scaladoc diagrams
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. PushPullStage
  2. AbstractStage
  3. Stage
  4. AnyRef
  5. Any
Implicitly
  1. by any2stringadd
  2. by any2stringfmt
  3. by any2ArrowAssoc
  4. by any2Ensuring
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new PushPullStage()

Abstract Value Members

  1. abstract def onPull(ctx: Context[Out]): SyncDirective

    onPull is called when there is demand from downstream, i.

    onPull is called when there is demand from downstream, i.e. you are allowed to push one element downstreams with akka.stream.stage.Context#push, or request elements from upstreams with akka.stream.stage.Context#pull

    Definition Classes
    AbstractStage
  2. abstract def onPush(elem: In, ctx: Context[Out]): SyncDirective

    onPush is called when an element from upstream is available and there is demand from downstream, i.

    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 akka.stream.stage.Context#push to emit one element downstreams, or you can absorb the element by calling akka.stream.stage.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, one-by-one. onPush is not called again until onPull has requested more elements with akka.stream.stage.Context#pull.

    Definition Classes
    AbstractStage

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to StringAdd performed by method any2stringadd in scala.Predef.
    Definition Classes
    StringAdd
  5. def ->[B](y: B): (PushPullStage[In, Out], B)

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to ArrowAssoc[PushPullStage[In, Out]] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  6. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. def decide(t: Throwable): Supervision.Directive

    If an exception is thrown from #onPush this method is invoked to decide how to handle the exception.

    If an exception is thrown from #onPush 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 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.

    Definition Classes
    AbstractStage
  11. def ensuring(cond: (PushPullStage[In, Out]) ⇒ Boolean, msg: ⇒ Any): PushPullStage[In, Out]

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to Ensuring[PushPullStage[In, Out]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. def ensuring(cond: (PushPullStage[In, Out]) ⇒ Boolean): PushPullStage[In, Out]

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to Ensuring[PushPullStage[In, Out]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: Boolean, msg: ⇒ Any): PushPullStage[In, Out]

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to Ensuring[PushPullStage[In, Out]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: Boolean): PushPullStage[In, Out]

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to Ensuring[PushPullStage[In, Out]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  17. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  18. def formatted(fmtstr: String): String

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to StringFormat performed by method any2stringfmt in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  19. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  20. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  21. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  22. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  23. final def notify(): Unit

    Definition Classes
    AnyRef
  24. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  25. def onDownstreamFinish(ctx: Context[Out]): TerminationDirective

    onDownstreamFinish is called when downstream has cancelled.

    onDownstreamFinish is called when downstream has cancelled.

    By default the cancel signal is immediately propagated with akka.stream.stage.Context#finish.

    Definition Classes
    AbstractStage
  26. def onUpstreamFailure(cause: Throwable, ctx: Context[Out]): TerminationDirective

    onUpstreamFailure is called when upstream has signaled that the stream is completed with failure.

    onUpstreamFailure is called when upstream has signaled that the stream is completed with failure. It is not called if #onPull or #onPush 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 akka.stream.stage.Context#push, because there might not be any demand from downstream. To emit additional elements before terminating you can use akka.stream.stage.Context#absorbTermination and push final elements from #onPull. The stage will then be in finishing state, which can be checked with akka.stream.stage.Context#isFinishing.

    Definition Classes
    AbstractStage
  27. def onUpstreamFinish(ctx: Context[Out]): TerminationDirective

    onUpstreamFinish is called when upstream has signaled that the stream is successfully completed.

    onUpstreamFinish is called when upstream has signaled that the stream is successfully completed. Here you cannot call akka.stream.stage.Context#push, because there might not be any demand from downstream. To emit additional elements before terminating you can use akka.stream.stage.Context#absorbTermination and push final elements from #onPull. The stage will then be in finishing state, which can be checked with akka.stream.stage.Context#isFinishing.

    By default the finish signal is immediately propagated with akka.stream.stage.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”.

    Definition Classes
    AbstractStage
  28. def postStop(): Unit

    User overridable callback.

    User overridable callback.

    Is called after the Stages final action is performed. // TODO need better wording here Empty default implementation.

    Definition Classes
    AbstractStage
    Annotations
    @throws( classOf[Exception] )
  29. def preStart(ctx: LifecycleContext): Unit

    User overridable callback.

    User overridable callback.

    It is called before any other method defined on the Stage. Empty default implementation.

    Definition Classes
    AbstractStage
    Annotations
    @throws( classOf[Exception] )
  30. def restart(): Stage[In, Out]

    Used to create a fresh instance of the stage after an error resulting in a Supervision.Restart directive.

    Used to create a fresh instance of the stage after an error resulting in a 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.

    Definition Classes
    AbstractStage
  31. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  32. def toString(): String

    Definition Classes
    AnyRef → Any
  33. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  35. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  36. def [B](y: B): (PushPullStage[In, Out], B)

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to ArrowAssoc[PushPullStage[In, Out]] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Shadowed Implicit Value Members

  1. val self: Any

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to StringAdd performed by method any2stringadd in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (pushPullStage: StringAdd).self
    Definition Classes
    StringAdd
  2. val self: Any

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to StringFormat performed by method any2stringfmt in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (pushPullStage: StringFormat).self
    Definition Classes
    StringFormat

Deprecated Value Members

  1. def x: PushPullStage[In, Out]

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to ArrowAssoc[PushPullStage[In, Out]] performed by method any2ArrowAssoc in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (pushPullStage: ArrowAssoc[PushPullStage[In, Out]]).x
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use leftOfArrow instead

  2. def x: PushPullStage[In, Out]

    Implicit information
    This member is added by an implicit conversion from PushPullStage[In, Out] to Ensuring[PushPullStage[In, Out]] performed by method any2Ensuring in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (pushPullStage: Ensuring[PushPullStage[In, Out]]).x
    Definition Classes
    Ensuring
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use resultOfEnsuring instead

Inherited from Stage[In, Out]

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from PushPullStage[In, Out] to StringAdd

Inherited by implicit conversion any2stringfmt from PushPullStage[In, Out] to StringFormat

Inherited by implicit conversion any2ArrowAssoc from PushPullStage[In, Out] to ArrowAssoc[PushPullStage[In, Out]]

Inherited by implicit conversion any2Ensuring from PushPullStage[In, Out] to Ensuring[PushPullStage[In, Out]]

Ungrouped