public abstract class PersistentEntity.BehaviorBuilder extends Object
build()
to create the immutable PersistentEntity.Behavior
.Constructor and Description |
---|
BehaviorBuilder() |
Modifier and Type | Method and Description |
---|---|
abstract PersistentEntity.Behavior |
build()
Construct the corresponding immutable
Behavior . |
abstract State |
getState() |
abstract void |
removeCommandHandler(Class<? extends Command> commandClass)
Remove a command handler for a given command class.
|
abstract void |
removeEventHandler(Class<? extends Event> eventClass)
Remove an event handler for a given event class.
|
abstract <R,A extends Command> |
setCommandHandler(Class<A> commandClass,
BiFunction<A,PersistentEntity.CommandContext<R>,PersistentEntity.Persist<? extends Event>> handler)
Register a command handler for a given command class.
|
abstract <A extends Event> |
setEventHandler(Class<A> eventClass,
Function<A,State> handler)
Register an event handler for a given event class.
|
abstract <A extends Event> |
setEventHandlerChangingBehavior(Class<A> eventClass,
Function<A,PersistentEntity.Behavior> handler)
Register an event handler that is updating the behavior for a given event class.
|
abstract <R,A extends Command> |
setReadOnlyCommandHandler(Class<A> commandClass,
BiConsumer<A,PersistentEntity.ReadOnlyCommandContext<R>> handler)
Register a read-only command handler for a given command class.
|
abstract void |
setState(State state) |
public abstract PersistentEntity.Behavior build()
Behavior
.public abstract State getState()
public abstract void removeCommandHandler(Class<? extends Command> commandClass)
public abstract void removeEventHandler(Class<? extends Event> eventClass)
public abstract <R,A extends Command> void setCommandHandler(Class<A> commandClass, BiFunction<A,PersistentEntity.CommandContext<R>,PersistentEntity.Persist<? extends Event>> handler)
The handler
function is supposed to return a Persist
directive that defines
what event or events, if any, to persist. Use the thenPersist
, thenPersistAll
or done
methods of the context that is passed to the handler function to create the
Persist
directive.
After persisting an event external side effects can be performed in the afterPersist
function that can be defined when creating the Persist
directive.
A typical side effect is to reply to the request to confirm that it was performed
successfully. Replies are sent with the reply
method of the context that is passed
to the command handler function.
The handler
function may validate the incoming command and reject it by
sending a reply
and returning ctx.done()
.
Invoking this method a second time for the same commandClass
will override the existing handler
.
public abstract <A extends Event> void setEventHandler(Class<A> eventClass, Function<A,State> handler)
handler
function
is supposed to return the new state after applying the event to the current state.
Current state can be accessed with the state
method of the PersistentEntity
.
Invoking this method a second time for the same eventClass
will override the existing handler
.
public abstract <A extends Event> void setEventHandlerChangingBehavior(Class<A> eventClass, Function<A,PersistentEntity.Behavior> handler)
handler
function is supposed to return the new behavior after applying the
event to the current state. Current behavior can be accessed with the behavior
method of the PersistentEntity
.
Invoking this method a second time for the same eventClass
will override the existing handler
.
public abstract <R,A extends Command> void setReadOnlyCommandHandler(Class<A> commandClass, BiConsumer<A,PersistentEntity.ReadOnlyCommandContext<R>> handler)
reply
method of the
context that is passed to the command handler function.
Invoking this method a second time for the same commandClass
will override the existing handler
.
public abstract void setState(State state)