public abstract class EventDispatchingRepository<I,E extends AbstractEntity<I,S>,S extends io.spine.base.EntityState> extends DefaultRecordBasedRepository<I,E,S> implements EventDispatcher
Modifier | Constructor and Description |
---|---|
protected |
EventDispatchingRepository() |
Modifier and Type | Method and Description |
---|---|
void |
dispatch(EventEnvelope event)
Dispatches the event to the corresponding entities.
|
protected abstract void |
dispatchTo(I id,
io.spine.core.Event event)
Dispatches the given event to an entity with the given ID.
|
void |
registerWith(BoundedContext context)
Registers itself as an event dispatcher with the parent
BoundedContext . |
protected java.util.Set<I> |
route(EventEnvelope event)
Determines the targets of the given event.
|
protected void |
setupEventRouting(EventRouting<I> routing)
A callback for derived repository classes to customize routing schema for events.
|
entityFactory, storageConverter
applyMigration, applyMigration, create, createStorage, find, find, findActive, findOrCreate, iterator, loadAll, loadAll, recordStorage, store, store, toEntity
checkStorage, close, context, entityClass, entityStateType, eventFilter, hasContext, idClass, index, isOpen, isRegistered, onRegistered, open, storage, storageAssigned
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
dispatchesEvents, dispatchesExternalEvents, domesticEventClasses, eventClasses, externalEventClasses
canDispatch, messageClasses
@OverridingMethodsMustInvokeSuper public void registerWith(BoundedContext context)
BoundedContext
.registerWith
in class DefaultRecordBasedRepository<I,E extends AbstractEntity<I,S>,S extends io.spine.base.EntityState>
context
- the BoundedContext
of this repositoryprotected void setupEventRouting(EventRouting<I> routing)
Default routing returns the ID of the entity which produced the event. This allows to “link” different kinds of entities by having the same class of IDs. More complex scenarios (e.g. one-to-many relationships) may require custom routing schemas.
routing
- the routing schema to customize@CanIgnoreReturnValue public final void dispatch(EventEnvelope event)
If there is no stored entity with such an ID, a new one is created and stored after it handles the passed event.
dispatch
in interface MessageDispatcher<EventClass,EventEnvelope>
event
- the event to dispatchprotected abstract void dispatchTo(I id, io.spine.core.Event event)
id
- the target entity IDevent
- the event to dispatchprotected java.util.Set<I> route(EventEnvelope event)
event
- the event to find targets for