Package kalix.javasdk.eventsourcedentity
Class EventSourcedEntity<S>
Object
kalix.javasdk.eventsourcedentity.EventSourcedEntity<S>
- Type Parameters:
S
- The type of the state for this entity.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
A return type to allow returning forwards or failures, and attaching effects to messages. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
_internalSetCommandContext
(Optional<CommandContext> context) INTERNAL APIvoid
_internalSetCurrentState
(S state) INTERNAL APIvoid
_internalSetEventContext
(Optional<EventContext> context) INTERNAL APIprotected final CommandContext
Additional context and metadata for a command handler.protected final S
Returns the state as currently stored by Kalix.protected final EventSourcedEntity.Effect.Builder<S>
effects()
Implement by returning the initial empty state object.protected final EventContext
Additional context and metadata for an event handler.
-
Constructor Details
-
EventSourcedEntity
public EventSourcedEntity()
-
-
Method Details
-
emptyState
Implement by returning the initial empty state object. This object will be passed into the command and event handlers, until a new state replaces it.Also known as "zero state" or "neutral state".
The default implementation of this method returns
null
. It can be overridden to return a more sensible initial state. -
commandContext
Additional context and metadata for a command handler.It will throw an exception if accessed from constructor or event handler.
-
_internalSetCommandContext
INTERNAL API -
eventContext
Additional context and metadata for an event handler.It will throw an exception if accessed from constructor or command handler.
-
_internalSetEventContext
INTERNAL API -
_internalSetCurrentState
INTERNAL API -
currentState
Returns the state as currently stored by Kalix.Note that modifying the state directly will not update it in storage. To save the state, one must call {
effects().updateState()
}.This method can only be called when handling a command or an event. Calling it outside a method (eg: in the constructor) will raise a IllegalStateException exception.
- Throws:
IllegalStateException
- if accessed outside a handler method
-
effects
-