Package org.drasyl.node.behaviour
Class Behavior.BehaviorBuilder
java.lang.Object
org.drasyl.node.behaviour.Behavior.BehaviorBuilder
- Enclosing class:
- Behavior
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Build a behavior from the current state of the builder.messageAdapter(Class<M> messageType, BiFunction<DrasylAddress, M, Object> adapter) Add a new case to the event handling matching events of typeMessageEventwithMessageEvent.getPayload()matchingmessageType.messageAdapter(Class<M> messageType, Function<M, Object> adapter) Add a new case to the event handling matching events of typeMessageEventwithMessageEvent.getPayload()matchingmessageType.onAnyEvent(Function<Event, Behavior> handler) Adds a new case to the event handling matching any event.onAnyMessage(BiFunction<DrasylAddress, M, Behavior> handler) Add a new case to the event handling matching anyMessageEvent.<M extends Event>
Behavior.BehaviorBuilderAdds a new case to the event handling.<M extends Event>
Behavior.BehaviorBuilderAdds a new predicated case to the event handling.<M extends Event>
Behavior.BehaviorBuilderonEventEquals(M event, Supplier<Behavior> handler) Add a new case to the event handling matching equal events.onMessage(Class<M> messageType, BiFunction<DrasylAddress, M, Behavior> handler) Add a new case to the event handling matching events of typeMessageEventwithMessageEvent.getPayload()matchingmessageType.onMessage(Class<M> messageType, BiPredicate<DrasylAddress, M> test, BiFunction<DrasylAddress, M, Behavior> handler) Add a new predicated case to the event handling matching events of typeMessageEventwithMessageEvent.getPayload()matchingmessageType.onMessageEquals(DrasylAddress sender, M payload, Supplier<Behavior> handler) Add a new case to the event handling matching events of typeMessageEventwith equalMessageEvent.getPayload().
-
Method Details
-
onEvent
public <M extends Event> Behavior.BehaviorBuilder onEvent(Class<M> type, Predicate<M> test, Function<M, Behavior> handler) Adds a new predicated case to the event handling.- Type Parameters:
M- type of event to match- Parameters:
type- type of the event to matchtest- a predicate that will be evaluated on the argument if the type matcheshandler- action to apply if the type matches- Returns:
- a new
Behavior.BehaviorBuilderwith the specified handling appended
-
onEvent
public <M extends Event> Behavior.BehaviorBuilder onEvent(Class<M> type, Function<M, Behavior> handler) Adds a new case to the event handling.- Type Parameters:
M- type of event to match- Parameters:
type- type of the event to matchhandler- action to apply if the type matches- Returns:
- a new
Behavior.BehaviorBuilderwith the specified handling appended
-
onEventEquals
public <M extends Event> Behavior.BehaviorBuilder onEventEquals(M event, Supplier<Behavior> handler) Add a new case to the event handling matching equal events.- Parameters:
event- the event to compare tohandler- action to apply when the event matches- Returns:
- a new
Behavior.BehaviorBuilderwith the specified handling appended
-
onAnyEvent
Adds a new case to the event handling matching any event. SubsequentonEvent(...)andonMessage(...)clauses will never see any events.- Parameters:
handler- action to apply for any event- Returns:
- a new
Behavior.BehaviorBuilderwith the specified handling appended
-
onMessage
public <M> Behavior.BehaviorBuilder onMessage(Class<M> messageType, BiPredicate<DrasylAddress, M> test, BiFunction<DrasylAddress, M, Behavior> handler) Add a new predicated case to the event handling matching events of typeMessageEventwithMessageEvent.getPayload()matchingmessageType.- Type Parameters:
M- type of event to match- Parameters:
messageType- type of the event to matchtest- a predicate that will be evaluated on the argument if the type matcheshandler- action to apply if the type matches- Returns:
- a new
Behavior.BehaviorBuilderwith the specified handling appended
-
onMessage
public <M> Behavior.BehaviorBuilder onMessage(Class<M> messageType, BiFunction<DrasylAddress, M, Behavior> handler) Add a new case to the event handling matching events of typeMessageEventwithMessageEvent.getPayload()matchingmessageType.- Type Parameters:
M- type of event to match- Parameters:
messageType- type of the event to matchhandler- action to apply if the type matches- Returns:
- a new
Behavior.BehaviorBuilderwith the specified handling appended
-
onMessageEquals
public <M> Behavior.BehaviorBuilder onMessageEquals(DrasylAddress sender, M payload, Supplier<Behavior> handler) Add a new case to the event handling matching events of typeMessageEventwith equalMessageEvent.getPayload().- Parameters:
sender- the message sender to compare topayload- the message payload to compare tohandler- action to apply when the event matches- Returns:
- a new
Behavior.BehaviorBuilderwith the specified handling appended
-
onAnyMessage
Add a new case to the event handling matching anyMessageEvent. SubsequentonMessage(...)clauses will never see any messages.- Parameters:
handler- action to apply for any message- Returns:
- a new
Behavior.BehaviorBuilderwith the specified handling appended
-
messageAdapter
public <M> Behavior.BehaviorBuilder messageAdapter(Class<M> messageType, BiFunction<DrasylAddress, M, Object> adapter) Add a new case to the event handling matching events of typeMessageEventwithMessageEvent.getPayload()matchingmessageType. This case will pass the message payload toadapterand then passes theMessageEventwith the wrapped payload to the behavior.- Type Parameters:
M- type of event to match- Parameters:
messageType- type of the event to matchadapter- adapter wrappingMessageEvent.getPayload()- Returns:
- a new
Behavior.BehaviorBuilderwith the specified handling appended
-
messageAdapter
public <M> Behavior.BehaviorBuilder messageAdapter(Class<M> messageType, Function<M, Object> adapter) Add a new case to the event handling matching events of typeMessageEventwithMessageEvent.getPayload()matchingmessageType. This case will pass the message payload toadapterand then passes theMessageEventwith the wrapped payload to the behavior.- Type Parameters:
M- type of event to match- Parameters:
messageType- type of the event to matchadapter- adapter wrappingMessageEvent.getPayload()- Returns:
- a new
Behavior.BehaviorBuilderwith the specified handling appended
-
build
Build a behavior from the current state of the builder.
-