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 Details

    • updateState

      KeyValueEntity.Effect.OnSuccessBuilder<S> updateState(S newState)
      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

      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

      <T> KeyValueEntity.ReadOnlyEffect<T> reply(T message)
      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

      <T> KeyValueEntity.ReadOnlyEffect<T> reply(T message, Metadata metadata)
      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 message
      metadata - additional metadata to include with the reply
      Returns:
      a read-only effect containing the reply
    • error

      <T> KeyValueEntity.ReadOnlyEffect<T> error(String message)
      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

      <T> KeyValueEntity.ReadOnlyEffect<T> error(CommandException commandException)
      Create an error reply. CommandException will be serialized and sent to the client. It's possible to catch it with try-catch statement or CompletionStage API when using async ComponentClient 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.