Notifications
It’s often convenient to react to state changes. All callbacks are subject to Orleans’ turn-based guarantees; see also the section on Concurrency Guarantees.
Track confirmed state
Section titled “Track confirmed state”To be notified of any changes to the confirmed state, JournaledGrain subclasses can override this method:
protected override void OnStateChanged(){ // read state and/or event log and take appropriate action}OnStateChanged is called whenever the confirmed state updates, i.e., the version number increases. This can happen when:
- A newer version of the state was loaded from storage.
- An event raised by this instance has been successfully written to storage.
- A notification message was received from some other instance.
Note that since all grains initially have version zero, OnStateChanged is called whenever the initial load from storage completes with a version larger than zero.
Track tentative state
Section titled “Track tentative state”To be notified of any changes to the tentative state, JournaledGrain subclasses can override this method:
protected override void OnTentativeStateChanged(){ // read state and/or events and take appropriate action}OnTentativeStateChanged is called whenever the tentative state changes, i.e., if the combined sequence (ConfirmedEvents + UnconfirmedEvents) changes. In particular, a callback to OnTentativeStateChanged() always happens during RaiseEvent.
