Timer and reminder in the Orleans

Source: Internet
Author: User

Timers and Reminder timers and reminders

The Orleans Runtime allows developers to add periodic behavior to grain through a mechanism called a timer and another called reminder. Next I'll introduce you to the timer and reminder .

Timers Timer

The timer is used to create a timed task for grain, but this timed task is not a recurring task across instances (Statelessworker allows multiple instances), similar to System. Threading.timer, but the difference is that it requires the grain instance it relies on to guarantee a single-threaded execution pattern

How to use

Registertimer will return a IDisposable reference, you can cancel the timer by calling Dispose

protected IDisposable Registertimer (func<objectObject State, TimeSpan duetime, TimeSpan period)

A few things to note

    1. A timer call does not change the state of the current grain instance (grain instance state: Idle idle, using use), and if you delay Grian by a timer because it is idle for too long to be recycled (from idle to the usage state), it is not feasible. In other words, even if there is a timer, if the grain has not been called, the grain may be inactive for too long, and the timer will not continue to run
    2. The cycle of a timer, which refers to a period of time from the last successful call to the start of the next call, not only does the Orleans timer not have overlapping calls similar to System.Theading.Timer, but also extends the call period to "fixed cycle + time of Last Call" 】
    3. The call to the timer will not be executed in parallel with the other calls on the grain. And AsyncCallback doesn't want to do the same thing with other calls.
Reminders Alarm Device

There are several differences between the reminder and the timer :

    1. Reminder will persist the store itself, that is, restart Orleans, will not cause reminder to fail, it will continue to run
    2. Reminder is a specific instance of grain, not grain
    3. If there is no active instance of this grain when reminder expires, it will create a new activation instance
    4. The reminder is invoked by the message, in the calling mode, and the other method calls of the grain are the same
    5. Reminder do not use on high-frequency calls, the call cycle should be minute, hour, or day-level, high-frequency, short-cycle calls, should be given priority to the timer

configuration of the reminder

Reminder is a persistent reminder that requires back-end storage support, this storage support is determined by configuration in the Systemstore configuration node in the Orleans server-side configuration file, and currently supports azuretable and SQL Server. Orleans Official Blog Introduction, will be open source in the early 2015, such as open source, I think all kinds of third-party systemstoreprovider is not a problem, as long as you reason, you can write any provider.

If it is used in the development environment, it only needs to be kept in memory temporarily and can be configured

<reminderservice reminderservicetype="remindertablegrain"/>

How to use

To use reminder, you must let your grain inherit iremindableand implement its Iremindable.recievereminder method

Task Iremindable.receivereminder (string  remindername, tickstatus status) {    Console.WriteLine ( " Thanks for reminding me--I almost forgot! " );     return Taskdone.done;}

Then, in grain, where you need to create a reminder (Reminder), use the method that calls the grain parent class

protected Task<iorleansreminder> Registerorupdatereminder (string remindername, TimeSpan duetime, TimeSpan Period

Parameter description:

Remindername reminder name, within this grain, needs to be unique

Duetime time interval (from establishment to first call) of the first call to the reminder

Period the period of each call

Cancel Reminder Cancel Reminder

You can do this by calling the Unregisterreminder method of the parent class. So how do you get this reminder before you cancel?

①registerorupdatereminder will return reminder references ② through Remindername, through the Getreminder method of the parent class

protected Task Unregisterreminder (Iorleansreminder reminder)
protected Task<iorleansreminder> Getreminder (string remindername)

Ps:reminder is a very nice thing, and later in the post, I'll show you how to use reminder to ensure the reliability of non-persistent messaging distributed systems

Timer and reminder in the Orleans

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.