I
- the type of IDs of process managersP
- the type of process managersS
- the type of process manager state messagespublic abstract class ProcessManagerRepository<I,P extends ProcessManager<I,S,?>,S extends io.spine.base.EntityState> extends EventDispatchingRepository<I,P,S> implements EventProducingRepository
ProcessManager
Modifier | Constructor and Description |
---|---|
protected |
ProcessManagerRepository() |
Modifier and Type | Method and Description |
---|---|
protected PmTransaction<?,?,?> |
beginTransactionFor(P manager) |
void |
close()
Closes the repository by closing the underlying storage.
|
com.google.common.collect.ImmutableSet<CommandClass> |
commandClasses()
Obtains a set of classes of commands handled by process managers of this repository.
|
protected void |
configure(P processManager)
A callback method for configuring a recently created
ProcessManager instance
before it is returned by the repository as the result of creating a new process manager
instance or finding existing one. |
P |
create(I id)
Create a new entity instance with its default state.
|
void |
dispatchCommand(CommandEnvelope command)
Dispatches the command to a corresponding process manager.
|
protected void |
dispatchTo(I id,
io.spine.core.Event event)
Dispatches the given event to an entity with the given ID.
|
com.google.common.collect.ImmutableSet<EventClass> |
domesticEventClasses()
Obtains classes of domestic events to which the process managers managed by this repository
react.
|
EventBus |
eventBus()
Obtains the
EventBus to which the repository posts. |
com.google.common.collect.ImmutableSet<EventClass> |
externalEventClasses()
Obtains classes of external events to which the process managers managed by this repository
react.
|
protected P |
findOrCreate(I id)
Loads an entity by the passed ID or creates a new one, if the entity was not found.
|
com.google.common.collect.ImmutableSet<EventClass> |
messageClasses()
Obtains a set of event classes to which process managers of this repository react.
|
com.google.common.collect.ImmutableSet<EventClass> |
outgoingEvents()
Obtains classes of the events produced by entities of this repository.
|
void |
registerWith(BoundedContext context)
Registers itself as an event dispatcher with the parent
BoundedContext . |
protected void |
setupCommandRouting(CommandRouting<I> routing)
A callback for derived classes to customize routing schema for commands.
|
protected void |
setupEventRouting(EventRouting<I> routing)
Replaces default routing with the one which takes the target ID from the first field
of an event message.
|
void |
store(P entity)
Stores the passed object.
|
protected P |
toEntity(io.spine.server.entity.EntityRecord record)
Creates and configures an instance of
the process manager by the passed record.
|
dispatch, route
entityFactory, storageConverter
applyMigration, applyMigration, createStorage, find, find, findActive, iterator, loadAll, loadAll, recordStorage, store
checkStorage, context, entityClass, entityStateType, eventFilter, hasContext, idClass, index, isOpen, isRegistered, onRegistered, open, storage, storageAssigned
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
eventFilter, filter, postEvents, postIfCommandRejected
dispatchesEvents, dispatchesExternalEvents, eventClasses
canDispatch
@OverridingMethodsMustInvokeSuper public void registerWith(BoundedContext context)
BoundedContext
.
Customizes event routing to use first message field.
Registers with the CommandBus
for dispatching commands
(via delegating dispatcher).
Registers with the IntegrationBroker
for dispatching external events and
rejections.
Ensures there is at least one handler method declared by the class of the managed process manager:
Throws an IllegalStateException
otherwise.
registerWith
in class EventDispatchingRepository<I,P extends ProcessManager<I,S,?>,S extends io.spine.base.EntityState>
context
- the Bounded Context of this repositoryjava.lang.IllegalStateException
- if the Process Manager class of this repository does not declare message
handling methodspublic final EventBus eventBus()
EventProducingRepository
EventBus
to which the repository posts.eventBus
in interface EventProducingRepository
@OverridingMethodsMustInvokeSuper protected void setupEventRouting(EventRouting<I> routing)
setupEventRouting
in class EventDispatchingRepository<I,P extends ProcessManager<I,S,?>,S extends io.spine.base.EntityState>
routing
- the routing to customizeprotected void setupCommandRouting(CommandRouting<I> routing)
Default routing returns the value of the first field of a command message.
routing
- the routing schema to customizepublic final com.google.common.collect.ImmutableSet<EventClass> messageClasses()
messageClasses
in interface MessageDispatcher<EventClass,EventEnvelope>
public final com.google.common.collect.ImmutableSet<EventClass> domesticEventClasses()
domesticEventClasses
in interface EventDispatcher
public final com.google.common.collect.ImmutableSet<EventClass> externalEventClasses()
externalEventClasses
in interface EventDispatcher
public final com.google.common.collect.ImmutableSet<CommandClass> commandClasses()
public com.google.common.collect.ImmutableSet<EventClass> outgoingEvents()
EventProducingRepository
outgoingEvents
in interface EventProducingRepository
public final void dispatchCommand(CommandEnvelope command)
If there is no stored process manager with such an ID, a new process manager is created and stored after it handles the passed command.
command
- a request to dispatchprotected final void dispatchTo(I id, io.spine.core.Event event)
Sends the given event to the Inbox
of this repository.
dispatchTo
in class EventDispatchingRepository<I,P extends ProcessManager<I,S,?>,S extends io.spine.base.EntityState>
id
- the target entity IDevent
- the event to dispatchprotected PmTransaction<?,?,?> beginTransactionFor(P manager)
protected final P toEntity(io.spine.server.entity.EntityRecord record)
toEntity
in class RecordBasedRepository<I,P extends ProcessManager<I,S,?>,S extends io.spine.base.EntityState>
@OverridingMethodsMustInvokeSuper public P create(I id)
Repository
create
in class RecordBasedRepository<I,P extends ProcessManager<I,S,?>,S extends io.spine.base.EntityState>
id
- the id of the entityprotected void configure(P processManager)
ProcessManager
instance
before it is returned by the repository as the result of creating a new process manager
instance or finding existing one.
Default implementation does nothing. Overriding repositories may use this method for injecting dependencies that process managers need to have.
processManager
- the process manager to configureprotected final P findOrCreate(I id)
An entity will be loaded whether its active or not.
The new entity is created if and only if there is no record with the corresponding ID.
Overrides to expose the method to the package.
findOrCreate
in class RecordBasedRepository<I,P extends ProcessManager<I,S,?>,S extends io.spine.base.EntityState>
id
- the ID of the entity to loadpublic final void store(P entity)
Repository
Note: The storage must be assigned before calling this method.
store
in class RecordBasedRepository<I,P extends ProcessManager<I,S,?>,S extends io.spine.base.EntityState>
entity
- an instance to store@OverridingMethodsMustInvokeSuper public void close()
Repository
The reference to the storage becomes null after this call.
close
in interface java.lang.AutoCloseable
close
in class Repository<I,P extends ProcessManager<I,S,?>>