Actor reminders

Just like Actor timers, Actor reminders are a triggering mechanism to invoke callbacks at periodic intervals. However, unlike Actor timers, Actor reminder callbacks are always triggered until they are explicitly unregistered. If an Actor has been deactivated, an Actor reminder callback will reactivate the Actor and invoke the registered callback. Actor reminders are generally used to carry out asynchronous processing such as data aggregation by applications. The syntax for registering reminders is very similar to that of timers:

    IActorReminder reminderRegistration = await 
this.RegisterReminderAsync(
reminderName, // Name of reminder

BitConverter.GetBytes(payload), // Parameter

TimeSpan.FromDays(3), // Amount of time to delay
before the callback is invoked

TimeSpan.FromDays(1) // Recurrence period
);

An Actor implementation that uses reminders needs to implement the IRemindable interface. This interface defines a single method named ReceiveReminderAsync. This method will be invoked for all the registered reminders, therefore, your application should be able to differentiate between reminders using either the name or the payload.

    public Task ReceiveReminderAsync(string reminderName, byte[] 
context, TimeSpan dueTime, TimeSpan period)
{
if (reminderName.Equals("Reminder Name"))
{
...
}
}

To unregister a reminder, if you have not persisted the reminder registration, then use the GetReminder method on the Actor base class to get a reference to the reminder registration, and then use the UnregisterReminder method to unregister the reminder:

IActorReminder reminder = GetReminder("Reminder Name"); 
Task reminderUnregistration = UnregisterReminderAsync(reminder);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.201.206