Class Grain<TGrainState>
Base class for a Grain with declared persistent state.
Inherited Members
Namespace: Orleans
Assembly: Orleans.Core.Abstractions.dll
Syntax
public class Grain<TGrainState> : Grain, IAddressable, ILifecycleParticipant<IGrainLifecycle> where TGrainState : new ()
Type Parameters
Name | Description |
---|---|
TGrainState | The class of the persistent state object |
Constructors
| Improve this Doc View SourceGrain()
This constructor should never be invoked. We expose it so that client code (subclasses of this class) do not have to add a constructor. Client code should use the GrainFactory to get a reference to a Grain.
Declaration
protected Grain()
Grain(IGrainIdentity, IGrainRuntime, IStorage<TGrainState>)
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, IGrainRuntime and State with test doubles (mocks/stubs).
Declaration
protected Grain(IGrainIdentity identity, IGrainRuntime runtime, IStorage<TGrainState> storage)
Parameters
Type | Name | Description |
---|---|---|
IGrainIdentity | identity | |
IGrainRuntime | runtime | |
IStorage<TGrainState> | storage |
Properties
| Improve this Doc View SourceState
Strongly typed accessor for the grain state
Declaration
protected TGrainState State { get; set; }
Property Value
Type | Description |
---|---|
TGrainState |
Methods
| Improve this Doc View SourceClearStateAsync()
Clear the current grain state data from backing store.
Declaration
protected virtual Task ClearStateAsync()
Returns
Type | Description |
---|---|
Task |
Participate(IGrainLifecycle)
Declaration
public override void Participate(IGrainLifecycle lifecycle)
Parameters
Type | Name | Description |
---|---|---|
IGrainLifecycle | lifecycle |
Overrides
| Improve this Doc View SourceReadStateAsync()
Read the current grain state data from backing store.
Declaration
protected virtual Task ReadStateAsync()
Returns
Type | Description |
---|---|
Task |
Remarks
Any previous contents of the grain state data will be overwritten.
WriteStateAsync()
Write of the current grain state data into backing store.
Declaration
protected virtual Task WriteStateAsync()
Returns
Type | Description |
---|---|
Task |