Class BehaviorInterceptor<O,​I>

  • Type Parameters:
    O - The outer message type – the type of messages the intercepting behavior will accept
    I - The inner message type - the type of message the wrapped behavior accepts
    Direct Known Subclasses:
    AbstractSupervisor, LogMessagesInterceptor, MonitorInterceptor, PoisonPillInterceptor, TimerInterceptor, WidenedInterceptor, WithMdcBehaviorInterceptor

    public abstract class BehaviorInterceptor<O,​I>
    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. Many built-in intercepting behaviors are provided through factories in the respective Behaviors.

    • Constructor Detail

      • BehaviorInterceptor

        public BehaviorInterceptor()
    • Method Detail

      • interceptMessageType

        public java.lang.Class<? extends O> interceptMessageType()
        Allows for applying the interceptor only to certain message types. Useful if the official protocol and the actual protocol of an actor causes problems, for example class cast exceptions for a message not of type O that the actor still knows how to deal with. Note that this is only possible to use when O and I are the same type.

        Returns:
        A subtype of O that should be intercepted or null to intercept all Os. Subtypes of O matching this are passed directly to the inner behavior without interception.
      • aroundStart

        public Behavior<I> aroundStart​(TypedActorContext<O> ctx,
                                       BehaviorInterceptor.PreStartTarget<I> target)
        Override to intercept actor startup. To trigger startup of the next behavior in the stack, call target.start().
        Parameters:
        ctx - (undocumented)
        target - (undocumented)
        Returns:
        The returned behavior will be the "started" behavior of the actor used to accept the next message or signal.
      • aroundReceive

        public abstract Behavior<I> aroundReceive​(TypedActorContext<O> ctx,
                                                  O msg,
                                                  BehaviorInterceptor.ReceiveTarget<I> 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.

        Parameters:
        ctx - (undocumented)
        msg - (undocumented)
        target - (undocumented)
        Returns:
        The behavior for next message or signal
      • aroundSignal

        public abstract Behavior<I> aroundSignal​(TypedActorContext<O> ctx,
                                                 Signal signal,
                                                 BehaviorInterceptor.SignalTarget<I> target)
        Intercept a signal sent to the running actor. Pass the signal on to the next behavior in the stack by passing it to target.apply.

        Parameters:
        ctx - (undocumented)
        signal - (undocumented)
        target - (undocumented)
        Returns:
        The behavior for next message or signal
      • isSame

        public boolean isSame​(BehaviorInterceptor<java.lang.Object,​java.lang.Object> other)
        Parameters:
        other - (undocumented)
        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.