Interface EventSourcedEntity.Effect.Builder<S,E>

Type Parameters:
S - The type of the state for this entity.
Enclosing interface:
EventSourcedEntity.Effect<T>

public static interface EventSourcedEntity.Effect.Builder<S,E>
Construct the effect that is returned by the command handler. The effect describes next processing actions, such as persisting events and sending a reply.
  • Method Details

    • persist

      Persist a single event. After this event is persisted, the event handler
      invalid reference
      #applyEvent(E event)
      is called in order to update the entity state.
    • persist

      EventSourcedEntity.Effect.OnSuccessBuilder<S> persist(E event1, E event2, E... events)
      Persist the passed events. After these events are persisted, the event handler EventSourcedEntity.applyEvent(E) is called in order to update the entity state. Note, the event handler is called only once after all events are persisted.
    • persistAll

      EventSourcedEntity.Effect.OnSuccessBuilder<S> persistAll(List<? extends E> events)
      Persist the passed List of events. After these events are persisted, the event handler EventSourcedEntity.applyEvent(E) is called in order to update the entity state. Note, the event handler is called only once after all events are persisted.
    • persistWithMetadata

      EventSourcedEntity.Effect.OnSuccessBuilder<S> persistWithMetadata(E event, Metadata metadata)
      Persist a single event and additional metadata together with the event. After this event is persisted, the event handler
      invalid reference
      #applyEvent(E event)
      is called in order to update the entity state.
    • persistAllWithMetadata

      EventSourcedEntity.Effect.OnSuccessBuilder<S> persistAllWithMetadata(List<EventWithMetadata<? extends E>> events)
      Persist the passed List of events and additional metadata together with the events. After these events are persisted, the event handler EventSourcedEntity.applyEvent(E) is called in order to update the entity state. Note, the event handler is called only once after all events are persisted.
    • updateReplicationFilter

      Change the replication filter for this entity without persisting any events.

      Events are by default replicated to all regions that have been enabled for the service. This method allows you to control which regions participate in the replication for this specific entity instance. This is useful for regulatory reasons or as cost optimization.

      The replication filter can only be updated from the primary region of the entity, or the entity will become the primary if using the request-region primary selection strategy. The filter is durable for the specific entity instance and can be changed without deploying a new version.

      The region where the update is made (the self region) is automatically included in the replication filter. The changes are additive, meaning that if you first update the filter to include one region and then later make another update to include a different region from the same entity, both regions are included.

      Parameters:
      filter - the replication filter defining which regions to include or exclude
      Returns:
      an effect builder for chaining additional operations
    • reply

      <T> EventSourcedEntity.ReadOnlyEffect<T> reply(T message)
      Create a message reply.
      Type Parameters:
      T - The type of the message that must be returned by this call.
      Parameters:
      message - The payload of the reply.
      Returns:
      A message reply.
    • reply

      <T> EventSourcedEntity.ReadOnlyEffect<T> reply(T message, Metadata metadata)
      Create a message reply.
      Type Parameters:
      T - The type of the message that must be returned by this call.
      Parameters:
      message - The payload of the reply.
      metadata - The metadata for the message.
      Returns:
      A message reply.
    • error

      <T> EventSourcedEntity.ReadOnlyEffect<T> error(String message)
      Create an error reply. A short version of {effects().error(new CommandException(message))}.
      Type Parameters:
      T - The type of the message that must be returned by this call.
      Parameters:
      message - The error message.
      Returns:
      An error reply.
    • error

      <T> EventSourcedEntity.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.