Class Aggregate

java.lang.Object
it.polimi.ingsw.server.event_sourcing.Aggregate
Direct Known Subclasses:
GameState

public abstract class Aggregate extends Object
  • Field Details

    • id

      public UUID id
    • created

      public final Date created
    • repository

      public static EventsRepository repository
    • version

      public int version
  • Constructor Details

    • Aggregate

      public Aggregate()
    • Aggregate

      public Aggregate(UUID uuid)
  • Method Details

    • loadFromUuid

      public static Aggregate loadFromUuid(UUID uuid) throws EventSourcingException
      Returns the updated aggregate based on the UUID
      Parameters:
      uuid - of the Aggregate to recover
      Throws:
      EventSourcingException - if there is some problem with the handling of the events
    • getCurrentState

      public Aggregate getCurrentState() throws EventSourcingException, DBQueryException
      Restore the aggregate and return the most updated version of the aggregate For doing so, it reconstructs the aggregate from the snapshot and applies the stack of events
      Returns:
      the updated aggregate
      Throws:
      EventSourcingException - if there is a problem with the events handlers
      DBQueryException - if there is a problem with the DB
    • apply

      public void apply(Event event) throws EventSourcingException
      Applies an event, given the Event to apply This method will call using reflection the appropriate handler that manage the event
      Parameters:
      event - to apply
      Throws:
      EventSourcingException - if there is some problem finding the appropriate handler
    • createSnapshot

      public void createSnapshot()
      Generates the snapshot and saves the Aggregate updated information to the repository
    • rollback

      public Aggregate rollback()
      Recreates the aggregate based on the last snapshot, deletes all the events vit aggregate version > snapshot version
      Returns:
      the Aggregate Snapshot