Class BehaviorBuilder<T>
java.lang.Object
org.apache.pekko.actor.typed.javadsl.BehaviorBuilder<T>
- Type Parameters:
T- the common superclass of all supported messages.
Immutable builder used for creating a
Behavior by 'chaining' message and signal handlers.
When handling a message or signal, this Behavior will consider all handlers in the order they were added,
looking for the first handler for which both the type and the (optional) predicate match.
Akka org.apache.pekko.japi.function lambda types are used throughout to allow handlers to throw checked exceptions
(which will fail the actor).
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build a Behavior from the current state of the builderstatic <T> BehaviorBuilder<T>create()onAnyMessage(Function<T, Behavior<T>> handler) Add a new case to the message handling matching any message.<M extends T>
BehaviorBuilder<T>Add a new case to the message handling.<M extends T>
BehaviorBuilder<T>Add a new predicated case to the message handling.onMessageEquals(T msg, Creator<Behavior<T>> handler) Add a new case to the message handling matching equal messages.<M extends T>
BehaviorBuilder<T>Add a new case to the message handling without compile time type check.<M extends Signal>
BehaviorBuilder<T>Add a new case to the signal handling.<M extends Signal>
BehaviorBuilder<T>Add a new predicated case to the signal handling.onSignalEquals(Signal signal, Creator<Behavior<T>> handler) Add a new case to the signal handling matching equal signals.
-
Constructor Details
-
BehaviorBuilder
public BehaviorBuilder()
-
-
Method Details
-
create
- Returns:
- new empty immutable behavior builder.
-
build
Build a Behavior from the current state of the builder -
onMessage
Add a new case to the message handling.- Parameters:
type- type of message to matchhandler- action to apply if the type matches- Returns:
- a new behavior builder with the specified handling appended
-
onMessage
public <M extends T> BehaviorBuilder<T> onMessage(Class<M> type, Predicate<M> test, Function<M, Behavior<T>> handler) Add a new predicated case to the message handling.- Parameters:
type- type of message to matchtest- a predicate that will be evaluated on the argument if the type matcheshandler- action to apply if the type matches and the predicate returns true- Returns:
- a new behavior builder with the specified handling appended
-
onMessageUnchecked
public <M extends T> BehaviorBuilder<T> onMessageUnchecked(Class<? extends T> type, Function<M, Behavior<T>> handler) Add a new case to the message handling without compile time type check.Should normally not be used, but when matching on class with generic type argument it can be useful, e.g.
List.classand(List<String> list) -> {...}- Parameters:
type- type of message to matchhandler- action to apply when the type matches- Returns:
- a new behavior builder with the specified handling appended
-
onMessageEquals
Add a new case to the message handling matching equal messages.- Parameters:
msg- the message to compare tohandler- action to apply when the message matches- Returns:
- a new behavior builder with the specified handling appended
-
onAnyMessage
Add a new case to the message handling matching any message. SubsequentonMessageclauses will never see any messages.- Parameters:
handler- action to apply for any message- Returns:
- a new behavior builder with the specified handling appended
-
onSignal
public <M extends Signal> BehaviorBuilder<T> onSignal(Class<M> type, Function<M, Behavior<T>> handler) Add a new case to the signal handling.- Parameters:
type- type of signal to matchhandler- action to apply if the type matches- Returns:
- a new behavior builder with the specified handling appended
-
onSignal
public <M extends Signal> BehaviorBuilder<T> onSignal(Class<M> type, Predicate<M> test, Function<M, Behavior<T>> handler) Add a new predicated case to the signal handling.- Parameters:
type- type of signals to matchtest- a predicate that will be evaluated on the argument if the type matcheshandler- action to apply if the type matches and the predicate returns true- Returns:
- a new behavior builder with the specified handling appended
-
onSignalEquals
Add a new case to the signal handling matching equal signals.- Parameters:
signal- the signal to compare tohandler- action to apply when the message matches- Returns:
- a new behavior builder with the specified handling appended
-