JournaledGrain<TGrainState, TEventBase>
Namespace: Orleans.EventSourcing
public abstract class JournaledGrain<TGrainState, TEventBase> : LogConsistentGrain<TGrainState>, IConnectionIssueListener, ILogConsistencyProtocolParticipant, ILogViewAdaptorHost<TGrainState, TEventBase>, IGrain, IAddressable where TGrainState : class, new() where TEventBase : classConstructors
JournaledGrain<TGrainState, TEventBase>Initializes a new instance of theOrleans.EventSourcing.JournaledGrainclass.
Properties
DefaultAdaptorFactoryIf there is no log-consistency provider specified, store versioned state using default storage providerStateGets the current confirmed state. Includes only confirmed events.TentativeStateGets the current tentative state. Includes both confirmed and unconfirmed events.UnconfirmedEventsReturns the current queue of unconfirmed events.VersionGets the version of the current confirmed state. Equals the total number of confirmed events.
Methods
ClearLogAsync(CancellationToken)Clears the log of all confirmed events. Reset the state to the initial state, and discards all unconfirmed events. ThrowsSystem.NotSupportedExceptionif the log cannot be cleared.ConfirmEventsWaits until all previously raised events have been confirmed.await this after raising one or more events, to ensure events are persisted before proceeding, or to guarantee strong consistency (linearizability) even if there are multiple instances of this grain
DisableStatsCollectionEnableStatsCollectionGetStatsInstallAdaptor(ILogViewAdaptorFactory, object, string, IGrainStorage?, ILogConsistencyProtocolServices)Called right after grain is constructed, to install the adaptor. The log-consistency provider contains a factory method that constructs the adaptor with chosen types for this grainOnActivateAsync(CancellationToken)By default, upon activation, the journaled grain waits until it has loaded the latest view from storage. Subclasses can override this behavior, and skip the wait if desired.OnConnectionIssue(ConnectionIssue)Called when the underlying persistence or replication protocol is running into some sort of connection trouble.Override this to monitor the health of the log-consistency protocol and/or to customize retry delays. Any exceptions thrown are caught and logged by the
ILogViewAdaptorFactory.OnConnectionIssueResolved(ConnectionIssue)Called when a previously reported connection issue has been resolved.Override this to monitor the health of the log-consistency protocol. Any exceptions thrown are caught and logged by the
ILogViewAdaptorFactory.OnStateChangedCalled after the confirmed state may have changed (i.e. the confirmed version number is larger).Override this to react to changes of the confirmed state.
OnTentativeStateChangedCalled whenever the tentative state may have changed due to local or remote events.Override this to react to changes of the state.
RaiseConditionalEvent(TEvent)Raise an event conditionally. Succeeds only if there are no conflicts, that is, no other events were raised in the meantime.RaiseConditionalEvents(IEnumerable<TEvent>)Raise multiple events, as an atomic sequence, conditionally. Succeeds only if there are no conflicts, that is, no other events were raised in the meantime.RaiseEvent(TEvent)Raises an event.RaiseEvents(IEnumerable<TEvent>)Raise multiple events, as an atomic sequence.RefreshNowRetrieves the latest state now, and confirms all previously raised events. Effectively, this enforces synchronization with the global state.Await this before reading the state to ensure strong consistency (linearizability) even if there are multiple instances of this grain
RetrieveConfirmedEvents(int, int)Retrieves a segment of the confirmed event sequence, possibly from storage. ThrowsSystem.NotSupportedExceptionif the events are not available to read. Whether events are available, and for how long, depends on the providers used and how they are configured.TransitionState(TGrainState, TEventBase)Defines how to apply events to the state. Unless it is overridden in the subclass, it calls a dynamic "Apply" function on the state, with the event as a parameter. All exceptions thrown by this method are caught and logged by the log view provider.Override this to customize how to transition the state for a given event.
