Package akka.actor.typed.javadsl
Class ReceiveBuilder<T>
- java.lang.Object
-
- akka.actor.typed.javadsl.ReceiveBuilder<T>
-
- Type Parameters:
T
- the common superclass of all supported messages.
public final class ReceiveBuilder<T> extends java.lang.Object
Mutable builder used when implementingAbstractBehavior
.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReceiveBuilder.Case$
-
Constructor Summary
Constructors Constructor Description ReceiveBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Receive<T>
build()
static <T> ReceiveBuilder<T>
create()
Create a new mutable receive builderReceiveBuilder<T>
onAnyMessage(Function<T,Behavior<T>> handler)
Add a new case to the message handling matching any message.<M extends T>
ReceiveBuilder<T>onMessage(java.lang.Class<M> type, Function<M,Behavior<T>> handler)
Add a new case to the message handling.<M extends T>
ReceiveBuilder<T>onMessage(java.lang.Class<M> type, Predicate<M> test, Function<M,Behavior<T>> handler)
Add a new predicated case to the message handling.ReceiveBuilder<T>
onMessageEquals(T msg, Creator<Behavior<T>> handler)
Add a new case to the message handling matching equal messages.<M extends T>
ReceiveBuilder<T>onMessageUnchecked(java.lang.Class<? extends T> type, Function<M,Behavior<T>> handler)
Add a new case to the message handling without compile time type check.<M extends Signal>
ReceiveBuilder<T>onSignal(java.lang.Class<M> type, Function<M,Behavior<T>> handler)
Add a new case to the signal handling.<M extends Signal>
ReceiveBuilder<T>onSignal(java.lang.Class<M> type, Predicate<M> test, Function<M,Behavior<T>> handler)
Add a new predicated case to the signal handling.ReceiveBuilder<T>
onSignalEquals(Signal signal, Creator<Behavior<T>> handler)
Add a new case to the signal handling matching equal signals.
-
-
-
Method Detail
-
create
public static <T> ReceiveBuilder<T> create()
Create a new mutable receive builder
-
onMessage
public <M extends T> ReceiveBuilder<T> onMessage(java.lang.Class<M> type, Function<M,Behavior<T>> handler)
Add a new case to the message handling.- Parameters:
type
- type of message to matchhandler
- action to apply if the type matches- Returns:
- this behavior builder
-
onMessage
public <M extends T> ReceiveBuilder<T> onMessage(java.lang.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:
- this behavior builder
-
onMessageUnchecked
public <M extends T> ReceiveBuilder<T> onMessageUnchecked(java.lang.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.class
and(List<String> list) -> {...}
- Parameters:
type
- type of message to matchhandler
- action to apply when the type matches- Returns:
- this behavior builder
-
onMessageEquals
public ReceiveBuilder<T> onMessageEquals(T msg, Creator<Behavior<T>> handler)
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:
- this behavior builder
-
onAnyMessage
public ReceiveBuilder<T> onAnyMessage(Function<T,Behavior<T>> handler)
Add a new case to the message handling matching any message. SubsequentonMessage
clauses will never see any messages.- Parameters:
handler
- action to apply for any message- Returns:
- this behavior builder
-
onSignal
public <M extends Signal> ReceiveBuilder<T> onSignal(java.lang.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:
- this behavior builder
-
onSignal
public <M extends Signal> ReceiveBuilder<T> onSignal(java.lang.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:
- this behavior builder
-
-