public abstract class AbstractStatefulReactor<I,S extends com.google.protobuf.Message,B extends io.spine.protobuf.ValidatingBuilder<S>> extends AbstractEventReactor
AbstractEventReactor
s which have state and require
delivering the messages through an
Inbox
.Modifier | Constructor and Description |
---|---|
protected |
AbstractStatefulReactor(io.spine.type.TypeUrl stateType)
Creates a new instance of the reactor and initializes the
Inbox for it. |
Modifier and Type | Method and Description |
---|---|
protected B |
builder()
Returns the current state as a
ValidatingBuilder for the respective message. |
void |
dispatch(EventEnvelope event)
Dispatches the message contained in the passed envelope.
|
protected void |
flushState()
Immediately writes the changes made to the current builder to the
storage.
|
protected abstract java.util.Optional<S> |
load(I id)
Loads the state from the storage by ID.
|
protected abstract B |
newStateBuilderWith(I id)
Creates a new instance of the respective state
ValidatingBuilder and sets the
passed identifier to it. |
protected abstract com.google.common.collect.ImmutableSet<I> |
route(EventEnvelope event)
Selects the target to which the event should be dispatched.
|
protected abstract void |
store(S updatedState)
Stores the passed state in the storage.
|
domesticEventClasses, externalEventClasses, isRegistered, messageClasses, producedEvents, producerId, registerWith, version
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
nothing
dispatchesEvents, dispatchesExternalEvents, eventClasses
canDispatch
protected AbstractStatefulReactor(io.spine.type.TypeUrl stateType)
Inbox
for it.protected B builder()
ValidatingBuilder
for the respective message.@CanIgnoreReturnValue public void dispatch(EventEnvelope event)
MessageDispatcher
dispatch
in interface MessageDispatcher<EventClass,EventEnvelope>
dispatch
in class AbstractEventReactor
event
- the envelope with the messageprotected abstract java.util.Optional<S> load(I id)
Returns Optional.empty()
if there is no such object found.
protected abstract void store(S updatedState)
protected abstract B newStateBuilderWith(I id)
ValidatingBuilder
and sets the
passed identifier to it.protected final void flushState()
The builder state is validated prior to storing. Any validation exceptions are propagated as-is.
protected abstract com.google.common.collect.ImmutableSet<I> route(EventEnvelope event)
event
- the event to dispatch