Package akka.japi.pf
Class ReceiveBuilder
- java.lang.Object
-
- akka.japi.pf.ReceiveBuilder
-
public class ReceiveBuilder extends java.lang.ObjectUsed 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 voidaddStatement(scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> statement)AbstractActor.Receivebuild()Build aPartialFunctionfrom this builder.static ReceiveBuildercreate()Return a newReceiveBuilderwith no case statements.<P> ReceiveBuildermatch(java.lang.Class<P> type, FI.TypedPredicate<P> predicate, FI.UnitApply<P> apply)Add a new case statement to this builder.<P> ReceiveBuildermatch(java.lang.Class<P> type, FI.UnitApply<P> apply)Add a new case statement to this builder.<P> ReceiveBuildermatch(java.lang.Class<P> type, java.util.function.BooleanSupplier externalPredicate, FI.UnitApply<P> apply)Add a new case statement to this builder.ReceiveBuildermatchAny(FI.UnitApply<java.lang.Object> apply)Add a new case statement to this builder, that matches any argument.ReceiveBuildermatchAny(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> ReceiveBuildermatchEquals(P object, FI.TypedPredicate<P> predicate, FI.UnitApply<P> apply)Add a new case statement to this builder.<P> ReceiveBuildermatchEquals(P object, FI.UnitApply<P> apply)Add a new case statement to this builder.<P> ReceiveBuildermatchEquals(P object, java.util.function.BooleanSupplier externalPredicate, FI.UnitApply<P> apply)Add a new case statement to this builder.<P> ReceiveBuildermatchUnchecked(java.lang.Class<?> type, FI.TypedPredicate<?> predicate, FI.UnitApply<P> apply)Add a new case statement to this builder without compile time type check.ReceiveBuildermatchUnchecked(java.lang.Class<?> type, FI.UnitApply<?> apply)Add a new case statement to this builder without compile time type check.<P> ReceiveBuildermatchUnchecked(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 aPartialFunctionfrom this builder. After this call the builder will be reset.- Returns:
- a PartialFunction for this builder.
-
create
public static ReceiveBuilder create()
Return a newReceiveBuilderwith no case statements. They can be added later as the returnedReceiveBuilderis 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.classand(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.classand(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.classand(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
-
-