Edit

Share via


Grain Class

Definition

The abstract base class for all grain classes.

public abstract class Grain : Orleans.Runtime.IAddressable
public abstract class Grain : Orleans.ILifecycleParticipant<Orleans.Runtime.IGrainLifecycle>, Orleans.Runtime.IAddressable
public abstract class Grain : Orleans.IGrainBase, Orleans.Runtime.IAddressable
type Grain = class
    interface IAddressable
type Grain = class
    interface IAddressable
    interface ILifecycleParticipant<IGrainLifecycle>
type Grain = class
    interface IGrainBase
    interface IAddressable
Public MustInherit Class Grain
Implements IAddressable
Public MustInherit Class Grain
Implements IAddressable, ILifecycleParticipant(Of IGrainLifecycle)
Public MustInherit Class Grain
Implements IAddressable, IGrainBase
Inheritance
Grain
Derived
Implements

Constructors

Grain()

This constructor should never be invoked. We expose it so that client code (subclasses of Grain) do not have to add a constructor. Client code should use the GrainFactory property to get a reference to a Grain.

Grain(IGrainContext, IGrainRuntime)

Grain implementers do NOT have to expose this constructor but can choose to do so. This constructor is particularly useful for unit testing where test code can create a Grain and replace the IGrainIdentity and IGrainRuntime with test doubles (mocks/stubs).

Grain(IGrainIdentity, IGrainRuntime)

Grain implementers do NOT have to expose this constructor but can choose to do so. This constructor is particularly useful for unit testing where test code can create a Grain and replace the IGrainIdentity and IGrainRuntime with test doubles (mocks/stubs).

Properties

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

GrainReference
IdentityString

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

RuntimeIdentity

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

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.

Methods

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.

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.

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.

GetLogger(String)

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

GetReminder(String)

Returns a previously registered reminder.

GetReminders()

Returns a list of all reminders registered by the grain.

GetStreamProvider(String)
GetStreamProviders()
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.

OnActivateAsync()

This method is called at the end of the process of activating a grain. It is called before any messages have been dispatched to the grain. For grains with declared persistent state, this method is called after the State property has been populated.

OnActivateAsync(CancellationToken)

This method is called at the end of the process of activating a grain. It is called before any messages have been dispatched to the grain. For grains with declared persistent state, this method is called after the State property has been populated.

OnDeactivateAsync()

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

OnDeactivateAsync(DeactivationReason, CancellationToken)

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

Participate(IGrainLifecycle)
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.

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

Registers a timer to send periodic callbacks to this grain.

UnregisterReminder(IGrainReminder)

Unregisters a previously registered reminder.

Explicit Interface Implementations

IGrainBase.GrainContext

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.

GetPrimaryKey(IAddressable, String)

Returns the Guid representation of a grain primary key.

GetPrimaryKey(IAddressable)

Returns the Guid representation of a grain primary key.

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