Class BehaviorInterceptor<Outer,​Inner>

  • Type Parameters:
    Outer - The outer message type – the type of messages the intercepting behavior will accept
    Inner - The inner message type - the type of message the wrapped behavior accepts

    Direct Known Subclasses:
    AbstractSupervisor, BehaviorSignalInterceptor

    public abstract class BehaviorInterceptor<Outer,​Inner>
    extends java.lang.Object
    A behavior interceptor allows for intercepting message and signal reception and perform arbitrary logic - transform, filter, send to a side channel etc. It is the core API for decoration of behaviors.

    The BehaviorInterceptor API is considered a low level tool for building other features and shouldn't be used for "normal" application logic. Several built-in intercepting behaviors are provided through factories in the respective Behaviors.

    If the interceptor does keep mutable state care must be taken to create a new instance from the factory function of Behaviors.intercept so that a new instance is created per spawned actor rather than shared among actor instance.

    param: interceptMessageClass Ensures that the interceptor will only receive O message types. If the message is not of this class or a subclass thereof (e.g. a private protocol) will bypass the interceptor and be continue to the inner behavior untouched.

    See Also:
    BehaviorSignalInterceptor
    • Constructor Detail

      • BehaviorInterceptor

        public BehaviorInterceptor​(java.lang.Class<Outer> interceptMessageClass)
      • BehaviorInterceptor

        public BehaviorInterceptor​(scala.reflect.ClassTag<Outer> interceptMessageClassTag)
        Scala API: The ClassTag for Outer ensures that only messages of this class or a subclass thereof will be intercepted. Other message types (e.g. a private protocol) will bypass the interceptor and be continue to the inner behavior untouched.
    • Method Detail

      • interceptMessageClass

        public java.lang.Class<Outer> interceptMessageClass()
      • aroundReceive

        public abstract Behavior<Inner> aroundReceive​(TypedActorContext<Outer> ctx,
                                                      Outer msg,
                                                      BehaviorInterceptor.ReceiveTarget<Inner> target)
        Intercept a message sent to the running actor. Pass the message on to the next behavior in the stack by passing it to target.apply, return Behaviors.same without invoking target to filter out the message.

        Returns:
        The behavior for next message or signal
      • isSame

        public boolean isSame​(BehaviorInterceptor<java.lang.Object,​java.lang.Object> other)
        Returns:
        true if this behavior logically the same as another behavior interceptor and can therefore be eliminated (to avoid building infinitely growing stacks of behaviors)? Default implementation is based on instance equality. Override to provide use case specific logic.