Class BehaviorInterceptor<Outer,Inner>
- java.lang.Object
-
- akka.actor.typed.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
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 respectiveBehaviors
.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
BehaviorInterceptor.PreStartTarget<T>
Abstraction of passing the on further in the behavior stack inaroundStart(akka.actor.typed.TypedActorContext<Outer>, akka.actor.typed.BehaviorInterceptor.PreStartTarget<Inner>)
.static interface
BehaviorInterceptor.ReceiveTarget<T>
Abstraction of passing the message on further in the behavior stack inaroundReceive(akka.actor.typed.TypedActorContext<Outer>, Outer, akka.actor.typed.BehaviorInterceptor.ReceiveTarget<Inner>)
.static interface
BehaviorInterceptor.SignalTarget<T>
Abstraction of passing the signal on further in the behavior stack inaroundReceive(akka.actor.typed.TypedActorContext<Outer>, Outer, akka.actor.typed.BehaviorInterceptor.ReceiveTarget<Inner>)
.
-
Constructor Summary
Constructors Constructor Description BehaviorInterceptor(java.lang.Class<Outer> interceptMessageClass)
BehaviorInterceptor(scala.reflect.ClassTag<Outer> interceptMessageClassTag)
Scala API: TheClassTag
forOuter
ensures that only messages of this class or a subclass thereof will be intercepted.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Behavior<Inner>
aroundReceive(TypedActorContext<Outer> ctx, Outer msg, BehaviorInterceptor.ReceiveTarget<Inner> target)
Intercept a message sent to the running actor.Behavior<Inner>
aroundSignal(TypedActorContext<Outer> ctx, Signal signal, BehaviorInterceptor.SignalTarget<Inner> target)
Override to intercept a signal sent to the running actor.Behavior<Inner>
aroundStart(TypedActorContext<Outer> ctx, BehaviorInterceptor.PreStartTarget<Inner> target)
Override to intercept actor startup.java.lang.Class<Outer>
interceptMessageClass()
boolean
isSame(BehaviorInterceptor<java.lang.Object,java.lang.Object> other)
-
-
-
Constructor Detail
-
BehaviorInterceptor
public BehaviorInterceptor(java.lang.Class<Outer> interceptMessageClass)
-
BehaviorInterceptor
public BehaviorInterceptor(scala.reflect.ClassTag<Outer> interceptMessageClassTag)
Scala API: TheClassTag
forOuter
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()
-
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.same
without invokingtarget
to 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:
BehaviorSignalInterceptor
-
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.
-
-