Package akka.japi.pf
Class ReceiveBuilder
- java.lang.Object
-
- akka.japi.pf.ReceiveBuilder
-
public class ReceiveBuilder extends java.lang.Object
Used for building a partial function forAbstractActor.createReceive()
.There is both a match on type only, and a match on type and predicate.
Inside an actor you can use it like this:
Example:
@Override public Receive createReceive() { return receiveBuilder() .match(Double.class, d -> { getSender().tell(d.isNaN() ? 0 : d, self()); }) .match(Integer.class, i -> { getSender().tell(i * 10, self()); }) .match(String.class, s -> s.startsWith("foo"), s -> { getSender().tell(s.toUpperCase(), self()); }) .build() ); }
-
-
Constructor Summary
Constructors Constructor Description ReceiveBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addStatement(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> statement)
AbstractActor.Receive
build()
Build aPartialFunction
from this builder.static ReceiveBuilder
create()
Return a newReceiveBuilder
with no case statements.<P> ReceiveBuilder
match(java.lang.Class<P> type, FI.TypedPredicate<P> predicate, FI.UnitApply<P> apply)
Add a new case statement to this builder.<P> ReceiveBuilder
match(java.lang.Class<P> type, FI.UnitApply<P> apply)
Add a new case statement to this builder.<P> ReceiveBuilder
match(java.lang.Class<P> type, java.util.function.BooleanSupplier externalPredicate, FI.UnitApply<P> apply)
Add a new case statement to this builder.ReceiveBuilder
matchAny(FI.UnitApply<java.lang.Object> apply)
Add a new case statement to this builder, that matches any argument.ReceiveBuilder
matchAny(java.util.function.BooleanSupplier externalPredicate, FI.UnitApply<java.lang.Object> apply)
Add a new case statement to this builder, that pass the test of the predicate.<P> ReceiveBuilder
matchEquals(P object, FI.TypedPredicate<P> predicate, FI.UnitApply<P> apply)
Add a new case statement to this builder.<P> ReceiveBuilder
matchEquals(P object, FI.UnitApply<P> apply)
Add a new case statement to this builder.<P> ReceiveBuilder
matchEquals(P object, java.util.function.BooleanSupplier externalPredicate, FI.UnitApply<P> apply)
Add a new case statement to this builder.<P> ReceiveBuilder
matchUnchecked(java.lang.Class<?> type, FI.TypedPredicate<?> predicate, FI.UnitApply<P> apply)
Add a new case statement to this builder without compile time type check.ReceiveBuilder
matchUnchecked(java.lang.Class<?> type, FI.UnitApply<?> apply)
Add a new case statement to this builder without compile time type check.<P> ReceiveBuilder
matchUnchecked(java.lang.Class<?> type, java.util.function.BooleanSupplier externalPredicate, FI.UnitApply<P> apply)
Add a new case statement to this builder without compile time type check.
-
-
-
Method Detail
-
addStatement
protected void addStatement(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> statement)
-
build
public AbstractActor.Receive build()
Build aPartialFunction
from this builder. After this call the builder will be reset.- Returns:
- a PartialFunction for this builder.
-
create
public static ReceiveBuilder create()
Return a newReceiveBuilder
with no case statements. They can be added later as the returnedReceiveBuilder
is a mutable object.- Returns:
- a builder with no case statements
-
match
public <P> ReceiveBuilder match(java.lang.Class<P> type, FI.UnitApply<P> apply)
Add a new case statement to this builder.- Parameters:
type
- a type to match the argument againstapply
- an action to apply to the argument if the type matches- Returns:
- a builder with the case statement added
-
matchUnchecked
public ReceiveBuilder matchUnchecked(java.lang.Class<?> type, FI.UnitApply<?> apply)
Add a new case statement to this builder 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
- a type to match the argument againstapply
- an action to apply to the argument if the type matches- Returns:
- a builder with the case statement added
-
match
public <P> ReceiveBuilder match(java.lang.Class<P> type, FI.TypedPredicate<P> predicate, FI.UnitApply<P> apply)
Add a new case statement to this builder.- Parameters:
type
- a type to match the argument againstpredicate
- a predicate that will be evaluated on the argument if the type matchesapply
- an action to apply to the argument if the type matches and the predicate returns true- Returns:
- a builder with the case statement added
-
match
public <P> ReceiveBuilder match(java.lang.Class<P> type, java.util.function.BooleanSupplier externalPredicate, FI.UnitApply<P> apply)
Add a new case statement to this builder.- Parameters:
type
- a type to match the argument againstexternalPredicate
- a external predicate that will be evaluated if the type matchesapply
- an action to apply to the argument if the type matches and the predicate returns true- Returns:
- a builder with the case statement added
-
matchUnchecked
public <P> ReceiveBuilder matchUnchecked(java.lang.Class<?> type, FI.TypedPredicate<?> predicate, FI.UnitApply<P> apply)
Add a new case statement to this builder 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
- a type to match the argument againstpredicate
- a predicate that will be evaluated on the argument if the type matchesapply
- an action to apply to the argument if the type matches and the predicate returns true- Returns:
- a builder with the case statement added
-
matchUnchecked
public <P> ReceiveBuilder matchUnchecked(java.lang.Class<?> type, java.util.function.BooleanSupplier externalPredicate, FI.UnitApply<P> apply)
Add a new case statement to this builder 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
- a type to match the argument againstexternalPredicate
- an external predicate that will be evaluated if the type matchesapply
- an action to apply to the argument if the type matches and the predicate returns true- Returns:
- a builder with the case statement added
-
matchEquals
public <P> ReceiveBuilder matchEquals(P object, FI.UnitApply<P> apply)
Add a new case statement to this builder.- Parameters:
object
- the object to compare equals withapply
- an action to apply to the argument if the object compares equal- Returns:
- a builder with the case statement added
-
matchEquals
public <P> ReceiveBuilder matchEquals(P object, FI.TypedPredicate<P> predicate, FI.UnitApply<P> apply)
Add a new case statement to this builder.- Parameters:
object
- the object to compare equals withpredicate
- a predicate that will be evaluated on the argument if the object compares equalapply
- an action to apply to the argument if the object compares equal- Returns:
- a builder with the case statement added
-
matchEquals
public <P> ReceiveBuilder matchEquals(P object, java.util.function.BooleanSupplier externalPredicate, FI.UnitApply<P> apply)
Add a new case statement to this builder.- Parameters:
object
- the object to compare equals withexternalPredicate
- an external predicate that will be evaluated if the object compares equalapply
- an action to apply to the argument if the object compares equal- Returns:
- a builder with the case statement added
-
matchAny
public ReceiveBuilder matchAny(FI.UnitApply<java.lang.Object> apply)
Add a new case statement to this builder, that matches any argument.- Parameters:
apply
- an action to apply to the argument- Returns:
- a builder with the case statement added
-
matchAny
public ReceiveBuilder matchAny(java.util.function.BooleanSupplier externalPredicate, FI.UnitApply<java.lang.Object> apply)
Add a new case statement to this builder, that pass the test of the predicate.- Parameters:
externalPredicate
- an external predicate that will always be evaluated.apply
- an action to apply to the argument- Returns:
- a builder with the case statement added
-
-