Interface Aggregate<T>
- Type Parameters:
T- The aggregate root type
- All Known Implementing Classes:
AnnotatedAggregate,EventSourcedAggregate,LockAwareAggregate
public interface Aggregate<T>
Interface that describes an aggregate. An aggregate is an isolated tree of entities that is capable of handling
commands. Implementations of this interface defer the actual handling of commands to a wrapped
instance of type T or one of its entities.
When a command is dispatched to an aggregate Axon will load the aggregate instance and invoke the related command
handler method. It is rarely necessary to interact with aggregates directly. Though it is not
recommended it is possible to invoke methods on the wrapped instance using invoke(Function) and execute(Consumer).
-
Method Summary
Modifier and TypeMethodDescriptionvoidExecute a method on the underlying aggregate or one of its instances.Handle the givenmessageon the aggregate root or one of its child entities.Get the unique identifier of this aggregatedefault StringGet the unique identifier of this aggregate, represented as a String.<R> RInvoke a method on the underlying aggregate root or one of its instances.booleanCheck if this aggregate has been deleted.rootType()Get the class type of the wrapped aggregate root that the Aggregate defers to for command handling.type()Get the String representation of the aggregate's type.version()Get the aggregate's version.
-
Method Details
-
type
String type()Get the String representation of the aggregate's type. This defaults to the simple name of therootType()unless configured otherwise.- Returns:
- The aggregate's type
-
identifierAsString
Get the unique identifier of this aggregate, represented as a String.- Returns:
- The aggregate's identifier as a String
-
identifier
Object identifier()Get the unique identifier of this aggregate- Returns:
- The aggregate's identifier
-
version
Long version()Get the aggregate's version. For event sourced aggregates this is identical to the sequence number of the last applied event.- Returns:
- The aggregate's version
-
handle
Handle the givenmessageon the aggregate root or one of its child entities.- Parameters:
message- The message to be handled by the aggregate- Returns:
- The result of message handling. Might returns
nullif for example handling aCommandMessageyields no results - Throws:
Exception- in case one is triggered during message processing
-
invoke
Invoke a method on the underlying aggregate root or one of its instances. Use this overexecute(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.
- 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
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.
- Parameters:
invocation- The function that performs the invocation
-
isDeleted
boolean isDeleted()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 anAggregateDeletedException.- Returns:
truein case the aggregate was deleted,falseotherwise
-
rootType
Get the class type of the wrapped aggregate root that the Aggregate defers to for command handling.- Returns:
- The aggregate root type
-