Class View<S>
- Type Parameters:
S
- The type of the state for this view.
Kalix' Entities represent the command side where you change the state of your model in a strictly consistent and isolated manner. Kalix' Views represent the query side of your application. Views are optimized for reads and allow you to query your model by fields other than the entity identifier.
When implementing a View, you define what will be its internal state (your view model) and how you want to query it. The Query string defines which fields will be indexed and how the query will be executed.
The query is executed by the Kalix when a request is made to the View.
Views are updated in response to Event Sourced Entity events, Value Entity state changes or messages from a Topic.
Each incoming change is handled by a command handler. Command handlers are methods returning an
View.UpdateEffect
. The command handler is responsible for updating the View state.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
An UpdateEffect is a description of what Kalix needs to do after the command is handled. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
_internalSetUpdateContext
(Optional<UpdateContext> context) INTERNAL APIvoid
_internalSetViewState
(S state) INTERNAL APIprotected final View.UpdateEffect.Builder<S>
effects()
The default implementation of this method returnsnull
.protected final UpdateContext
Additional context and metadata for an update handler.protected final S
Returns the view state (row) for this invocation as currently stored in Kalix.
-
Constructor Details
-
View
public View()
-
-
Method Details
-
updateContext
Additional context and metadata for an update handler.It will throw an exception if accessed from constructor.
-
_internalSetUpdateContext
INTERNAL API -
_internalSetViewState
INTERNAL API -
viewState
Returns the view state (row) for this invocation as currently stored in 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. Calling it outside a method (eg: in the constructor) will raise a IllegalStateException exception.
- Throws:
IllegalStateException
- if accessed outside a handler method
-
effects
-
emptyState
The default implementation of this method returnsnull
. It can be overridden to return a more sensible initial state.- Returns:
- an empty state object or `null` to hand to the process method when an event for a previously unknown subject id is seen.
-