Skip to content

GrainBaseExtensions Methods

Helper methods for IGrainBase implementations.

DeactivateOnIdle(IGrainBase)

staticextension
View source
public static void DeactivateOnIdle(this IGrainBase grain)
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.

Parameters

grainIGrainBase

MigrateOnIdle(IGrainBase)

staticextension
View source
public static void MigrateOnIdle(this IGrainBase grain)
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.

Parameters

grainIGrainBase

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

staticextension
View source
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<CancellationToken, Task> callback, GrainTimerCreationOptions options)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<CancellationToken, Task>
The timer callback, which will be invoked whenever the timer becomes due.
optionsGrainTimerCreationOptions
The options for creating the timer.

Returns

The IGrainTimer instance which represents the timer.

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

staticextension
View source
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<CancellationToken, Task> callback, TimeSpan dueTime, TimeSpan period)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<CancellationToken, Task>
The timer callback, which will be invoked whenever the timer becomes due.
dueTimeTimeSpan
A System.TimeSpan representing the amount of time to delay before invoking the callback method specified when the IGrainTimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to prevent the timer from starting. Specify System.TimeSpan.Zero to start the timer immediately.
periodTimeSpan
The time interval between invocations of the callback method specified when the IGrainTimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to disable periodic signaling.

Returns

The IGrainTimer instance which represents the timer.

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

staticextension
View source
public static IGrainTimer RegisterGrainTimer(this IGrainBase grain, Func<Task> callback, TimeSpan dueTime, TimeSpan period)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<Task>
The timer callback, which will be invoked whenever the timer becomes due.
dueTimeTimeSpan
A System.TimeSpan representing the amount of time to delay before invoking the callback method specified when the IGrainTimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to prevent the timer from starting. Specify System.TimeSpan.Zero to start the timer immediately.
periodTimeSpan
The time interval between invocations of the callback method specified when the IGrainTimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to disable periodic signaling.

Returns

The IGrainTimer instance which represents the timer.

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

staticextension
View source
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, CancellationToken, Task> callback, TState state, GrainTimerCreationOptions options)
Creates a grain timer.

Parameters

grainIGrainBase
callbackFunc<TState, CancellationToken, Task>
The timer callback, which will be invoked whenever the timer becomes due.
stateTState
The state passed to the callback.
optionsGrainTimerCreationOptions
The options for creating the timer.

Returns

The IGrainTimer instance which represents the timer.

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

staticextension
View source
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, CancellationToken, Task> callback, TState state, TimeSpan dueTime, TimeSpan period)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<TState, CancellationToken, Task>
The timer callback, which will be invoked whenever the timer becomes due.
stateTState
The state passed to the callback.
dueTimeTimeSpan
The time interval between invocations of the callback method specified when the IGrainTimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to disable periodic signaling.
periodTimeSpan

Returns

The IGrainTimer instance which represents the timer.

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

staticextension
View source
public static IGrainTimer RegisterGrainTimer<TState>(this IGrainBase grain, Func<TState, Task> callback, TState state, TimeSpan dueTime, TimeSpan period)
Creates a grain timer.

Parameters

grainIGrainBase
The grain instance.
callbackFunc<TState, Task>
The timer callback, which will be invoked whenever the timer becomes due.
stateTState
The state passed to the callback.
dueTimeTimeSpan
The time interval between invocations of the callback method specified when the IGrainTimer was constructed. Specify System.Threading.Timeout.InfiniteTimeSpan to disable periodic signaling.
periodTimeSpan

Returns

The IGrainTimer instance which represents the timer.