Düzenle

Aracılığıyla paylaş


JournaledGrain<TGrainState> Class

Definition

A base class for log-consistent grains using standard event-sourcing terminology. All operations are reentrancy-safe.

public abstract class JournaledGrain<TGrainState> : Orleans.EventSourcing.JournaledGrain<TGrainState,object> where TGrainState : class, new()
type JournaledGrain<'GrainState (requires 'GrainState : null and 'GrainState : (new : unit -> 'GrainState))> = class
    inherit JournaledGrain<'GrainState, obj (requires 'GrainState : null and 'GrainState : (new : unit -> 'GrainState))>
Public MustInherit Class JournaledGrain(Of TGrainState)
Inherits JournaledGrain(Of TGrainState, Object)

Type Parameters

TGrainState

The type for the grain state, i.e. the aggregate view of the event log.

Inheritance
JournaledGrain<TGrainState,Object>
JournaledGrain<TGrainState>
Inheritance
LogConsistentGrain<TGrainState>
JournaledGrain<TGrainState,Object>
JournaledGrain<TGrainState>
Inheritance
LogConsistentGrain<TGrainState>
JournaledGrain<TGrainState,Object>
JournaledGrain<TGrainState>

Constructors

JournaledGrain<TGrainState>()

Initializes a new instance of the JournaledGrain<TGrainState> class.

JournaledGrain<TGrainState>(IGrainIdentity, IGrainRuntime)

This constructor is particularly useful for unit testing where test code can create a Grain and replace the IGrainIdentity, IGrainRuntime and State with test doubles (mocks/stubs).

Properties

DefaultAdaptorFactory

If there is no log-consistency provider specified, store versioned state using default storage provider

(Inherited from JournaledGrain<TGrainState,TEventBase>)
GrainContext (Inherited from Grain)
GrainFactory

Gets an object which can be used to access other grains. Null if this grain is not associated with a Runtime, such as when created directly for unit testing.

(Inherited from Grain)
GrainReference (Inherited from Grain)
IdentityString

String representation of grain's SiloIdentity including type and primary key.

(Inherited from Grain)
RuntimeIdentity

A unique identifier for the current silo. There is no semantic content to this string, but it may be useful for logging.

(Inherited from Grain)
ServiceProvider

Gets the IServiceProvider managed by the runtime. Null if this grain is not associated with a Runtime, such as when created directly for unit testing.

(Inherited from Grain)
State

Gets the current confirmed state. Includes only confirmed events.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
TentativeState

Gets the current tentative state. Includes both confirmed and unconfirmed events.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
UnconfirmedEvents

Returns the current queue of unconfirmed events.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
UnresolvedConnectionIssues

Gets a list of all currently unresolved connection issues.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
Version

Gets the version of the current confirmed state. Equals the total number of confirmed events.

(Inherited from JournaledGrain<TGrainState,TEventBase>)

Methods

ConfirmEvents()

Waits 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

(Inherited from JournaledGrain<TGrainState,TEventBase>)
DeactivateOnIdle()

Deactivate this activation of the grain after the current grain method call is completed. This call will mark this activation of the current grain to be deactivated and removed at the end of the current method. The next call to this grain will result in a different activation to be used, which typical means a new activation will be created automatically by the runtime.

(Inherited from Grain)
DelayDeactivation(TimeSpan)

Delay Deactivation of this activation at least for the specified time duration. A positive timeSpan value means “prevent GC of this activation for that time span”. A negative timeSpan value means “cancel the previous setting of the DelayDeactivation call and make this activation behave based on the regular Activation Garbage Collection settings”. DeactivateOnIdle method would undo / override any current “keep alive” setting, making this grain immediately available for deactivation.

(Inherited from Grain)
DisableStatsCollection() (Inherited from JournaledGrain<TGrainState,TEventBase>)
EnableStatsCollection() (Inherited from JournaledGrain<TGrainState,TEventBase>)
GetLogger()

Returns a logger object that this grain's code can use for tracing. The name of the logger will be derived from the grain class name.

(Inherited from Grain)
GetLogger(String)

Returns a logger object that this grain's code can use for tracing.

(Inherited from Grain)
GetReminder(String)

Returns a previously registered reminder.

(Inherited from Grain)
GetReminders()

Returns a list of all reminders registered by the grain.

(Inherited from Grain)
GetStats() (Inherited from JournaledGrain<TGrainState,TEventBase>)
GetStreamProvider(String) (Inherited from Grain)
GetStreamProviders() (Inherited from Grain)
InstallAdaptor(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 grain

(Inherited from JournaledGrain<TGrainState,TEventBase>)
InstallAdaptor(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 grain

(Inherited from JournaledGrain<TGrainState,TEventBase>)
MigrateOnIdle()

Starts an attempt to migrating this instance to another location. Migration captures the current RequestContext, making it available to the activation's placement director so that it can consider it when selecting a new location. Migration will occur asynchronously, when no requests are executing, and will not occur if the activation's placement director does not select an alternative location.

(Inherited from Grain)
OnActivateAsync()

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.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
OnActivateAsync(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.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
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.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
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 ILogConsistencyProvider.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
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 ILogConsistencyProvider.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
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.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
OnDeactivateAsync()

This method is called at the begining of the process of deactivating a grain.

(Inherited from Grain)
OnDeactivateAsync(DeactivationReason, CancellationToken)

This method is called at the beginning of the process of deactivating a grain.

(Inherited from Grain)
OnStateChanged()

Called 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.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
OnTentativeStateChanged()

Called whenever the tentative state may have changed due to local or remote events.

Override this to react to changes of the state.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
Participate(IGrainLifecycle) (Inherited from Grain)
Participate(IGrainLifecycle) (Inherited from LogConsistentGrain<TView>)
Participate(IGrainLifecycle) (Inherited from LogConsistentGrain<TView>)
RaiseConditionalEvent<TEvent>(TEvent)

Raise an event conditionally. Succeeds only if there are no conflicts, that is, no other events were raised in the meantime.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
RaiseConditionalEvents<TEvent>(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.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
RaiseEvent<TEvent>(TEvent)

Raises an event.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
RaiseEvents<TEvent>(IEnumerable<TEvent>)

Raise multiple events, as an atomic sequence.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
RefreshNow()

Retrieves 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

(Inherited from JournaledGrain<TGrainState,TEventBase>)
RegisterOrUpdateReminder(String, TimeSpan, TimeSpan)

Registers a persistent, reliable reminder to send regular notifications (reminders) to the grain. The grain must implement the Orleans.IRemindable interface, and reminders for this grain will be sent to the ReceiveReminder callback method. If the current grain is deactivated when the timer fires, a new activation of this grain will be created to receive this reminder. If an existing reminder with the same name already exists, that reminder will be overwritten with this new reminder. Reminders will always be received by one activation of this grain, even if multiple activations exist for this grain.

(Inherited from Grain)
RegisterTimer(Func<Object,Task>, Object, TimeSpan, TimeSpan)
Obsolete.

Registers a timer to send periodic callbacks to this grain.

(Inherited from Grain)
RetrieveConfirmedEvents(Int32, Int32)

Retrieves a segment of the confirmed event sequence, possibly from storage. Throws NotSupportedException if 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.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
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.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
UnregisterReminder(IGrainReminder)

Unregisters a previously registered reminder.

(Inherited from Grain)

Explicit Interface Implementations

IConnectionIssueListener.OnConnectionIssue(ConnectionIssue)

called by adaptor on connection issues.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
IConnectionIssueListener.OnConnectionIssue(ConnectionIssue)

called by adaptor on connection issues.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
IConnectionIssueListener.OnConnectionIssueResolved(ConnectionIssue)

Called by adaptor when a connection issue is resolved.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
IConnectionIssueListener.OnConnectionIssueResolved(ConnectionIssue)

called by adaptor when a connection issue is resolved.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
IGrainBase.GrainContext (Inherited from Grain)
ILogConsistencyProtocolParticipant.DeactivateProtocolParticipant()

Notify log view adaptor of deactivation

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogConsistencyProtocolParticipant.DeactivateProtocolParticipant()

Notify log view adaptor of deactivation

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogConsistencyProtocolParticipant.OnMultiClusterConfigurationChange(MultiClusterConfiguration)

Receive a configuration change, pass on to log view adaptor.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogConsistencyProtocolParticipant.OnProtocolMessageReceived(ILogConsistencyProtocolMessage)

Receive a protocol message from other clusters, passed on to log view adaptor.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogConsistencyProtocolParticipant.PostActivateProtocolParticipant()

Notify log view adaptor of activation (called after user-level OnActivate)

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogConsistencyProtocolParticipant.PostActivateProtocolParticipant()

Notify log view adaptor of activation (called after user-level OnActivate)

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogConsistencyProtocolParticipant.PreActivateProtocolParticipant()

Notify log view adaptor of activation (called before user-level OnActivate)

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogConsistencyProtocolParticipant.PreActivateProtocolParticipant()

Notify log view adaptor of activation (called before user-level OnActivate)

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogConsistentGrain.DefaultAdaptorFactory

If there is no log-consistency provider specified, store versioned state using default storage provider

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogConsistentGrain.InstallAdaptor(ILogViewAdaptorFactory, Object, String, IStorageProvider, 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 grain

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogViewAdaptorHost<TGrainState,TEventBase>.OnViewChanged(Boolean, Boolean)

Called by adaptor on state change.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogViewAdaptorHost<TGrainState,TEventBase>.OnViewChanged(Boolean, Boolean)

called by adaptor on state change.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogViewAdaptorHost<TGrainState,TEventBase>.UpdateView(TGrainState, TEventBase)

Called by adaptor to update the view when entries are appended.

(Inherited from JournaledGrain<TGrainState,TEventBase>)
ILogViewAdaptorHost<TGrainState,TEventBase>.UpdateView(TGrainState, TEventBase)

called by adaptor to update the view when entries are appended.

(Inherited from JournaledGrain<TGrainState,TEventBase>)

Extension Methods

DeactivateOnIdle(IGrainBase)

Deactivate this grain activation after the current grain method call is completed. This call will mark this activation of the current grain to be deactivated and removed at the end of the current method. The next call to this grain will result in a different activation to be used, which typical means a new activation will be created automatically by the runtime.

MigrateOnIdle(IGrainBase)

Starts an attempt to migrating this instance to another location. Migration captures the current RequestContext, making it available to the activation's placement director so that it can consider it when selecting a new location. Migration will occur asynchronously, when no requests are executing, and will not occur if the activation's placement director does not select an alternative location.

RegisterGrainTimer(IGrainBase, Func<CancellationToken,Task>, GrainTimerCreationOptions)

Creates a grain timer.

RegisterGrainTimer(IGrainBase, Func<CancellationToken,Task>, TimeSpan, TimeSpan)

Creates a grain timer.

RegisterGrainTimer(IGrainBase, Func<Task>, GrainTimerCreationOptions)
RegisterGrainTimer(IGrainBase, Func<Task>, TimeSpan, TimeSpan)

Creates a grain timer.

RegisterGrainTimer<TState>(IGrainBase, Func<TState,CancellationToken,Task>, TState, GrainTimerCreationOptions)

Creates a grain timer.

RegisterGrainTimer<TState>(IGrainBase, Func<TState,CancellationToken,Task>, TState, TimeSpan, TimeSpan)

Creates a grain timer.

RegisterGrainTimer<TState>(IGrainBase, Func<TState,Task>, TState, GrainTimerCreationOptions)
RegisterGrainTimer<TState>(IGrainBase, Func<TState,Task>, TState, TimeSpan, TimeSpan)

Creates a grain timer.

AsReference(IAddressable, Type)

Returns a typed reference to the provided grain.

AsReference<TGrainInterface>(IAddressable)

Returns a typed reference to the provided grain.

BindGrainReference(IAddressable, IGrainFactory)

Binds the grain reference to the provided IGrainFactory.

Cast(IAddressable, Type)

Returns a typed reference to the provided grain.

Cast<TGrainInterface>(IAddressable)

Returns a typed reference to the provided grain.

GetGrainId(IAddressable)

Returns the grain id corresponding to the provided grain.

GetGrainIdentity(IGrain)
GetPrimaryKey(IGrain, String)
GetPrimaryKey(IGrain)
GetPrimaryKey(IAddressable, String)

Returns the Guid representation of a grain primary key.

GetPrimaryKey(IAddressable)

Returns the Guid representation of a grain primary key.

GetPrimaryKeyLong(IGrain, String)
GetPrimaryKeyLong(IGrain)
GetPrimaryKeyLong(IAddressable, String)

Returns the long representation of a grain primary key.

GetPrimaryKeyLong(IAddressable)

Returns the long representation of a grain primary key.

GetPrimaryKeyString(IAddressable)

Returns the string primary key of the grain.

IsPrimaryKeyBasedOnLong(IAddressable)

Returns whether part of the primary key is of type long.

GetReminder(Grain, String)

Returns a previously registered reminder.

GetReminder(IGrainBase, String)

Returns a previously registered reminder.

GetReminders(Grain)

Returns a list of all reminders registered by the grain.

GetReminders(IGrainBase)

Returns a list of all reminders registered by the grain.

RegisterOrUpdateReminder(Grain, String, TimeSpan, TimeSpan)

Registers a persistent, reliable reminder to send regular notifications (reminders) to the grain. The grain must implement the Orleans.IRemindable interface, and reminders for this grain will be sent to the ReceiveReminder callback method. If the current grain is deactivated when the timer fires, a new activation of this grain will be created to receive this reminder. If an existing reminder with the same name already exists, that reminder will be overwritten with this new reminder. Reminders will always be received by one activation of this grain, even if multiple activations exist for this grain.

RegisterOrUpdateReminder(IGrainBase, String, TimeSpan, TimeSpan)

Registers a persistent, reliable reminder to send regular notifications (reminders) to the grain. The grain must implement the Orleans.IRemindable interface, and reminders for this grain will be sent to the ReceiveReminder callback method. If the current grain is deactivated when the timer fires, a new activation of this grain will be created to receive this reminder. If an existing reminder with the same name already exists, that reminder will be overwritten with this new reminder. Reminders will always be received by one activation of this grain, even if multiple activations exist for this grain.

UnregisterReminder(Grain, IGrainReminder)

Unregisters a previously registered reminder.

UnregisterReminder(IGrainBase, IGrainReminder)

Unregisters a previously registered reminder.

GetStreamProvider(Grain, String)

Gets the stream provider with the specified name.

GetStreamProvider(IGrainBase, String)

Gets the stream provider with the specified name.

GetLogger(Grain, String)

Returns a logger object that this grain's code can use for tracing.

GetLogger(Grain)

Returns a logger object that this grain's code can use for tracing. The name of the logger will be derived from the grain class name.

GetGrainStorage(Grain, IServiceProvider)

Acquire the storage provider associated with the grain type.

Applies to