AggregateRepository

public abstract class AggregateRepository<I, A extends Aggregate<I, ? extends Object, ? extends Object>> extends Repository<I, E> implements CommandDispatcher, EventProducingRepository, EventDispatcherDelegate

The repository which manages instances of Aggregates.

Parameters

<I>

the type of the aggregate IDs

<A>

the type of the aggregates managed by this repository

See also

Inheritors

Constructors

Link copied to clipboard
protected void AggregateRepository()
Creates a new instance.

Functions

Link copied to clipboard
protected final AggregateClass<A> aggregateClass()
Obtains class information of aggregates managed by this repository.
Link copied to clipboard
Returns the storage assigned to this aggregate.
Link copied to clipboard
public void close()
Closes the repository by closing the underlying storage.
Link copied to clipboard
public A create(I id)
Create a new entity instance with its default state.
Link copied to clipboard
Creates aggregate storage for the repository.
Link copied to clipboard
public final DispatchOutcome dispatch(CommandEnvelope cmd)
Dispatches the passed command to an aggregate.
Link copied to clipboard
public DispatchOutcome dispatchEvent(EventEnvelope event)
Dispatches event to one or more aggregates reacting on the event.
Link copied to clipboard
protected A doLoadOrCreate(I id)
Link copied to clipboard
public ImmutableSet<EventClass> domesticEvents()
Obtains domestic event classes dispatched by this delegate.
Link copied to clipboard
protected void doStore(A aggregate)
Link copied to clipboard
public final EventBus eventBus()
Obtains the EventBus to which the repository posts.
Link copied to clipboard
public ImmutableSet<EventClass> events()
Obtains all event classes dispatched by this delegate.
Link copied to clipboard
public ImmutableSet<EventClass> externalEvents()
Obtains external event classes dispatched by this delegate.
Link copied to clipboard
public Optional<A> find(I id)
Loads an aggregate by the passed ID.
Link copied to clipboard
public ImmutableSet<EventClass> importableEvents()
Obtains classes of events that can be imported by aggregates of this repository.
Link copied to clipboard
public final ImmutableSet<CommandClass> messageClasses()
Obtains a set of message classes that can be processed by this dispatcher.
Link copied to clipboard
protected final void onRoutingFailed(SignalEnvelope<? extends Object, ? extends Object, ? extends Object> envelope, Throwable cause)
A callback invoked when an exception is thrown from message routing.
Link copied to clipboard
public ImmutableSet<EventClass> outgoingEvents()
Obtains classes of the events produced by entities of this repository.
Link copied to clipboard
protected A play(I id, AggregateHistory history)
Plays the given Aggregate history for an instance of Aggregate with the given ID.
Link copied to clipboard
public void registerWith(BoundedContext context)
Initializes the repository during its registration with its context.
Link copied to clipboard
protected void setSnapshotTrigger(int snapshotTrigger)
Changes the number of events between making aggregate snapshots to the passed value.
Link copied to clipboard
protected void setupCommandRouting(CommandRouting<I> routing)
A callback for derived classes to customize routing schema for commands.
Link copied to clipboard
protected void setupEventRouting(EventRouting<I> routing)
A callback for derived classes to customize routing schema for events.
Link copied to clipboard
protected void setupImportRouting(EventRouting<I> routing)
A callback for derived classes to customize routing schema for importable events.
Link copied to clipboard
protected int snapshotTrigger()
Returns the number of events until a next Snapshot is made.
Link copied to clipboard
protected final void store(A aggregate)
Stores the passed aggregate and commits its uncommitted events.
Link copied to clipboard
protected AggregateClass<A> toModelClass(Class<A> cls)
Obtains a model class for the passed entity class value.

Inherited functions

Link copied to clipboard
public boolean canDispatch(E envelope)
Checks if this dispatcher can dispatch the given message.
Link copied to clipboard
public void checkNotRegistered()
Verifies that this instance is NOT registered yet.
Link copied to clipboard
public void checkOpen()
Ensures that the object is open.
Link copied to clipboard
public void checkRegistered()
Verifies that this instance is already registered.
Link copied to clipboard
protected static S checkStorage<S extends AutoCloseable>(S storage)
Ensures that the storage is not null.
Link copied to clipboard
public abstract void close()
Link copied to clipboard
protected final BoundedContext context()
Obtains the BoundedContext to which this repository belongs.
Link copied to clipboard
Obtains StorageFactory associated with the ServerEnvironment for creating standard storages.
Link copied to clipboard
public boolean dispatchesCommands()
Verifies if this instance dispatches at least one command.
Link copied to clipboard
public boolean dispatchesEvents()
Verifies if this instance dispatches at least one event.
Link copied to clipboard
public boolean dispatchesExternalEvents()
Verifies if this instance dispatches at least one external event.
Link copied to clipboard
public final Class<E> entityClass()
Returns the class of entities managed by this repository.
Link copied to clipboard
Obtains model class for the entities managed by this repository.
Link copied to clipboard
public final TypeUrl entityStateType()
Obtains the TypeUrl for the state objects wrapped by entities managed by this repository.
Link copied to clipboard
Creates an EventFilter for this repository.
Link copied to clipboard
public Iterable<Event> filter(Collection<Event> events)
Filters passed events using the eventFilter filter} of this repository.
Link copied to clipboard
protected final boolean hasContext()
Verifies whether the repository is registered with a BoundedContext.
Link copied to clipboard
public final Class<I> idClass()
Returns the class of IDs used by this repository.
Link copied to clipboard
public ImmutableSet<String> identity()
Returns immutable set with one element with the identity of the multicast dispatcher that dispatches messages to itself.
Link copied to clipboard
public Iterator<I> index()
Returns an iterator over the identifiers of all the entities managed by this repository.
Link copied to clipboard
public final boolean isOpen()
Verifies if the repository is open.
Link copied to clipboard
public boolean isRegistered()
Tells if the repository is registered in a BoundedContext.
Link copied to clipboard
protected boolean isTypeSupplier()
Tells if this repository should be registered as a type supplier with a Stand of the BoundedContext to which this repository belongs.
Link copied to clipboard
public Iterator<E> iterator(Predicate<E> filter)
Returns an iterator over the entities managed by the repository that match the passed filter.
Link copied to clipboard
Obtains an instance of EntityLifecycle for the entity with the given ID.
Link copied to clipboard
public void onRegistered()
The callback is invoked by a BoundedContext when adding the repository.
Link copied to clipboard
protected final void open()
Initializes the storage of the repository.
Link copied to clipboard
public void postEvents(Collection<Event> events)
Filters the passed events and posts the result to the EventBus.
Link copied to clipboard
public void postIfCommandRejected(SignalEnvelope<? extends Object, ? extends Object, ? extends Object> signal, Throwable cause)
If the passed signal is a command and the thrown cause is a rejection, posts the rejection to the associated EventBus.
Link copied to clipboard
protected final Optional<R> route<M extends Message, C extends MessageContext, R>(Route<M, C, R> routing, SignalEnvelope<? extends Object, ? extends Object, C> envelope)
Link copied to clipboard
protected final Storage<I, ? extends Object, ? extends Object> storage()
Returns the storage assigned to this repository.
Link copied to clipboard
public final boolean storageAssigned()
Returns true if the storage is assigned, false otherwise.