Class LockAwareAggregate<AR,A extends Aggregate<AR>>

java.lang.Object
org.axonframework.modelling.command.LockAwareAggregate<AR,A>
Type Parameters:
AR - the aggregate root type
A - the Aggregate implementation type
All Implemented Interfaces:
Aggregate<AR>

public class LockAwareAggregate<AR,A extends Aggregate<AR>> extends Object implements Aggregate<AR>
Aggregate implementation that provides access to the lock held by the aggregate while a command is handled.
Since:
3.0
Author:
Allard Buijze
  • Constructor Details

    • LockAwareAggregate

      public LockAwareAggregate(A wrappedAggregate, Lock lock)
      Initializes a new LockAwareAggregate for given wrappedAggregate and lock.
      Parameters:
      wrappedAggregate - the aggregate instance to which the LockAwareAggregate will delegate
      lock - the lock held by the aggregate
    • LockAwareAggregate

      public LockAwareAggregate(A wrappedAggregate, Supplier<Lock> lock)
      Initializes a new LockAwareAggregate for given wrappedAggregate and a supplier of the lock.
      Parameters:
      wrappedAggregate - the aggregate instance to which the LockAwareAggregate will delegate
      lock - a supplier of the lock held by the aggregate
  • Method Details

    • getWrappedAggregate

      public A getWrappedAggregate()
      Get the delegate aggregate wrapped by this instance.
      Returns:
      the wrapped aggregate
    • isLockHeld

      public boolean isLockHeld()
      Check if the aggregate currently holds a lock.
      Returns:
      true if the lock is held, false otherwise
    • type

      public String type()
      Description copied from interface: Aggregate
      Get the String representation of the aggregate's type. This defaults to the simple name of the Aggregate.rootType() unless configured otherwise.
      Specified by:
      type in interface Aggregate<AR>
      Returns:
      The aggregate's type
    • identifier

      public Object identifier()
      Description copied from interface: Aggregate
      Get the unique identifier of this aggregate
      Specified by:
      identifier in interface Aggregate<AR>
      Returns:
      The aggregate's identifier
    • version

      public Long version()
      Description copied from interface: Aggregate
      Get the aggregate's version. For event sourced aggregates this is identical to the sequence number of the last applied event.
      Specified by:
      version in interface Aggregate<AR>
      Returns:
      The aggregate's version
    • handle

      public Object handle(Message<?> message) throws Exception
      Description copied from interface: Aggregate
      Handle the given message on the aggregate root or one of its child entities.
      Specified by:
      handle in interface Aggregate<AR>
      Parameters:
      message - The message to be handled by the aggregate
      Returns:
      The result of message handling. Might returns null if for example handling a CommandMessage yields no results
      Throws:
      Exception - in case one is triggered during message processing
    • invoke

      public <R> R invoke(Function<AR,R> invocation)
      Description copied from interface: Aggregate
      Invoke a method on the underlying aggregate root or one of its instances. Use this over Aggregate.execute(Consumer) to obtain an invocation result, for instance in order to query the aggregate.

      Note that the use of this method is not recommended as aggregates are not meant to be queried. Relying on this method is commonly a sign of design smell.

      Specified by:
      invoke in interface Aggregate<AR>
      Type Parameters:
      R - The type of the result produced by the given invocation
      Parameters:
      invocation - The function that performs the actual invocation
      Returns:
      The invocation result
    • execute

      public void execute(Consumer<AR> invocation)
      Description copied from interface: Aggregate
      Execute a method on the underlying aggregate or one of its instances.

      Note that the use of this method is not recommended as the wrapped aggregate instance is not meant to be exposed. Relying on this method is commonly a sign of design smell.

      Specified by:
      execute in interface Aggregate<AR>
      Parameters:
      invocation - The function that performs the invocation
    • isDeleted

      public boolean isDeleted()
      Description copied from interface: Aggregate
      Check if this aggregate has been deleted. This is checked by aggregate repositories when an aggregate is loaded. In case the repository is asked to load a deleted aggregate the repository will refuse by throwing an AggregateDeletedException.
      Specified by:
      isDeleted in interface Aggregate<AR>
      Returns:
      true in case the aggregate was deleted, false otherwise
    • rootType

      public Class<? extends AR> rootType()
      Description copied from interface: Aggregate
      Get the class type of the wrapped aggregate root that the Aggregate defers to for command handling.
      Specified by:
      rootType in interface Aggregate<AR>
      Returns:
      The aggregate root type