Package akka.javasdk.keyvalueentity
Interface KeyValueEntity.Effect.Builder<S>
- Type Parameters:
S
- The type of the state for this entity
- Enclosing interface:
KeyValueEntity.Effect<T>
public static interface KeyValueEntity.Effect.Builder<S>
Builder for constructing effects that describe the actions to be performed after command
processing. Use this to create effects that update state, reply to callers, or handle errors.
-
Method Summary
Modifier and TypeMethodDescriptionMarks the entity for deletion.error
(CommandException commandException) Create an error reply.Creates an error reply to reject the command and inform the caller of the failure.reply
(T message) Creates a reply message to send back to the caller without updating the entity state.Creates a reply message with additional metadata to send back to the caller without updating the entity state.updateState
(S newState) Updates the entity state with the provided new state.
-
Method Details
-
updateState
Updates the entity state with the provided new state. This is the only way to persist state changes in a Key Value Entity. The new state will replace the current state entirely.- Parameters:
newState
- the new state to persist, replacing the current state- Returns:
- a builder for chaining additional effects like replies
-
deleteEntity
KeyValueEntity.Effect.OnSuccessBuilder<S> deleteEntity()Marks the entity for deletion. After deletion, the entity will still exist with an empty state for some time before being completely removed. No additional state updates are allowed after deletion.- Returns:
- a builder for chaining additional effects like replies
-
reply
Creates a reply message to send back to the caller without updating the entity state. Use this for read-only operations or when the command doesn't require state changes.- Type Parameters:
T
- the type of the reply message- Parameters:
message
- the payload of the reply message- Returns:
- a read-only effect containing the reply
-
reply
Creates a reply message with additional metadata to send back to the caller without updating the entity state.- Type Parameters:
T
- the type of the reply message- Parameters:
message
- the payload of the reply messagemetadata
- additional metadata to include with the reply- Returns:
- a read-only effect containing the reply
-
error
Creates an error reply to reject the command and inform the caller of the failure. The entity state will not be modified when returning an error.- Type Parameters:
T
- the type of the expected reply message- Parameters:
message
- the error message.- Returns:
- a read-only effect containing the error
-
error
Create an error reply.CommandException
will be serialized and sent to the client. It's possible to catch it with try-catch statement orCompletionStage
API when using asyncComponentClient
API.- Type Parameters:
T
- The type of the message that must be returned by this call.- Parameters:
commandException
- The command exception to be returned.- Returns:
- An error reply.
-