Interface EntityLifecycleHandler<I,E>

Type Parameters:
I - the type of the entity identifier
E - the type of the entity
All Superinterfaces:
DescribableComponent, SourcingHandler<I,E>
All Known Implementing Classes:
SimpleEntityLifecycleHandler, SnapshottingEntityLifecycleHandler

public interface EntityLifecycleHandler<I,E> extends SourcingHandler<I,E>, DescribableComponent
Defines the lifecycle operations for an event-sourced entity.

An EntityLifecycleHandler is responsible for managing how an entity is:

  • initialized when no prior state exists
  • reconstructed from an underlying event stream
  • kept up to date through live event subscriptions

Implementations encapsulate the full lifecycle semantics of an entity, including how state is derived from events and how runtime updates are applied.

The lifecycle consists of three primary operations:

  • initialize: creates a new entity instance
  • source: reconstructs an entity from its event history
  • subscribe: subscribes a managed entity to be updated with future events

Implementations may apply optimizations such as snapshotting or partial reconstruction strategies, but these concerns remain internal to the handler.

Since:
5.1.0
Author:
John Hendrikx
  • Method Details

    • initialize

      E initialize(I identifier, ProcessingContext context)
      Creates a new instance of the entity for the given identifier.

      This operation is used when no prior state exists for the entity. The resulting instance represents the initial state before any events have been applied.

      Parameters:
      identifier - the entity identifier, cannot be null
      context - the processing context, cannot be null
      Returns:
      a newly initialized entity instance
    • subscribe

      void subscribe(ManagedEntity<I,E> entity, ProcessingContext context)
      Subscribes the given managed entity to the event stream so it receives future state changes.

      After subscription, any newly appended events relevant to the entity are applied to its current state, keeping it synchronized with the event store for the remainder of its lifecycle.

      Parameters:
      entity - the managed entity to subscribe
      context - the processing context