Class ImmutableAggregateRoot<T>

java.lang.Object
io.fluxcapacitor.javaclient.modeling.ImmutableEntity<T>
io.fluxcapacitor.javaclient.modeling.ImmutableAggregateRoot<T>
Type Parameters:
T - the type of the domain object represented by this aggregate root
All Implemented Interfaces:
AggregateRoot<T>, Entity<T>

public class ImmutableAggregateRoot<T> extends ImmutableEntity<T> implements AggregateRoot<T>
Immutable representation of an AggregateRoot, extending ImmutableEntity with additional metadata for event sourcing.

The previous field stores a reference to the prior state, enabling recursive traversal of historical states. When aggregate caching with a caching depth is enabled, older states may be replaced by a LazyAggregateRoot, which holds a reference but defers loading the full state.

This allows memory-efficient checkpointing of long-lived aggregates: once the maximum caching depth is reached, earlier states are no longer retained in memory and must be reloaded via event sourcing when accessed.

See Also:
  • Constructor Details

    • ImmutableAggregateRoot

      public ImmutableAggregateRoot()
  • Method Details

    • from

      public static <T> ImmutableAggregateRoot<T> from(Entity<T> a, EntityHelper entityHelper, Serializer serializer, EventStore eventStore)
    • apply

      public Entity<T> apply(DeserializingMessage message)
      Description copied from interface: Entity
      Applies the given deserializing message to the entity.
      Specified by:
      apply in interface Entity<T>
      Overrides:
      apply in class ImmutableEntity<T>
      Parameters:
      message - the deserializing message to process and convert into an entity
      Returns:
      the entity resulting from applying the given deserializing message
    • update

      public Entity<T> update(UnaryOperator<T> function)
      Description copied from interface: Entity
      Updates the current entity's value using the specified unary operator and returns a new entity containing the updated value.
      Specified by:
      update in interface Entity<T>
      Overrides:
      update in class ImmutableEntity<T>
      Parameters:
      function - the unary operator to apply to the current entity's value
      Returns:
      a new entity containing the updated value after applying the function
    • withEventIndex

      public Entity<T> withEventIndex(Long index, String messageId)
      Description copied from interface: Entity
      Updates the event index and message ID of the entity and returns the updated version of the entity.
      Specified by:
      withEventIndex in interface AggregateRoot<T>
      Specified by:
      withEventIndex in interface Entity<T>
      Parameters:
      index - the event index to set for the root entity
      messageId - the message ID associated with the event
      Returns:
      the updated entity corresponding to the current entity's ID and type, or null if no such entity can be found
    • withSequenceNumber

      public Entity<T> withSequenceNumber(long sequenceNumber)
      Description copied from interface: Entity
      Returns an updated entity based on this with the specified sequence number.
      Specified by:
      withSequenceNumber in interface AggregateRoot<T>
      Specified by:
      withSequenceNumber in interface Entity<T>
      Parameters:
      sequenceNumber - the sequence number to assign to the entity
      Returns:
      the updated entity with the specified sequence number, or null if the entity could not be found in the entity hierarchy