Class BehaviorInterceptor<Outer,Inner>
- Type Parameters:
Outer- The outer message type – the type of messages the intercepting behavior will acceptInner- The inner message type - the type of message the wrapped behavior accepts
- Direct Known Subclasses:
AbstractSupervisor,BehaviorSignalInterceptor
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAbstraction of passing the on further in the behavior stack inaroundStart(org.apache.pekko.actor.typed.TypedActorContext<Outer>, org.apache.pekko.actor.typed.BehaviorInterceptor.PreStartTarget<Inner>).static interfaceAbstraction of passing the message on further in the behavior stack inaroundReceive(org.apache.pekko.actor.typed.TypedActorContext<Outer>, Outer, org.apache.pekko.actor.typed.BehaviorInterceptor.ReceiveTarget<Inner>).static interfaceAbstraction of passing the signal on further in the behavior stack inaroundReceive(org.apache.pekko.actor.typed.TypedActorContext<Outer>, Outer, org.apache.pekko.actor.typed.BehaviorInterceptor.ReceiveTarget<Inner>). -
Constructor Summary
ConstructorsConstructorDescriptionBehaviorInterceptor(Class<Outer> interceptMessageClass) BehaviorInterceptor(scala.reflect.ClassTag<Outer> interceptMessageClassTag) Scala API: TheClassTagforOuterensures that only messages of this class or a subclass thereof will be intercepted. -
Method Summary
Modifier and TypeMethodDescriptionaroundReceive(TypedActorContext<Outer> ctx, Outer msg, BehaviorInterceptor.ReceiveTarget<Inner> target) Intercept a message sent to the running actor.aroundSignal(TypedActorContext<Outer> ctx, Signal signal, BehaviorInterceptor.SignalTarget<Inner> target) Override to intercept a signal sent to the running actor.aroundStart(TypedActorContext<Outer> ctx, BehaviorInterceptor.PreStartTarget<Inner> target) Override to intercept actor startup.booleanisSame(BehaviorInterceptor<Object, Object> other)
-
Constructor Details
-
BehaviorInterceptor
-
BehaviorInterceptor
Scala API: TheClassTagforOuterensures 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 Details
-
interceptMessageClass
-
aroundStart
public Behavior<Inner> aroundStart(TypedActorContext<Outer> ctx, BehaviorInterceptor.PreStartTarget<Inner> target) Override to intercept actor startup. To trigger startup of the next behavior in the stack, calltarget.start().- Returns:
- The returned behavior will be the "started" behavior of the actor used to accept the next message or signal.
-
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 totarget.apply, returnBehaviors.samewithout invokingtargetto filter out the message.- Returns:
- The behavior for next message or signal
-
aroundSignal
public Behavior<Inner> aroundSignal(TypedActorContext<Outer> ctx, Signal signal, BehaviorInterceptor.SignalTarget<Inner> target) Override to intercept a signal sent to the running actor. Pass the signal on to the next behavior in the stack by passing it totarget.apply.- Returns:
- The behavior for next message or signal
- See Also:
-
isSame
- Returns:
trueif 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.
-