Actions and Action Handlers
Head over to GrainContext API to get a more detailed view of the context API.
pageGrainContext APIWhat are Actions and Action Handlers?
An Action is a message that can be processed by Action Handlers. These messages can be topic events, API calls, or Grain to Grain messages. The entire list of the types of Actions can be found here.
An Action Handler is a method that contains user defined behavior to handle Actions. Action Handlers can contain two types of methods:
Grainite provides the following platform guarantees (and constraints) while processing each Action:
Actions are processed in order, per Key (action source). There is no ordering across keys.
The action handler has single threaded access to the Grain’s state.
The action handler can read/modify the Grain's state.
The action handler can send asynchronous messages to other grains or topics.
The action handler can access external systems, make queries, calls etc. In case of failure, the handler could be re-executed, and any external side effects repeated.
All side effects: changes to self-state, and async messages sent out; are atomic - either all will (eventually) happen, or none will.
Side-effects to external systems are excluded from atomicity guarantee.
Defining a Single Action Handler
Action Handler methods may be per-action, or batch-oriented. Here is the method signature for a per-action handler named handlerMethodName
:
Defining a Batch Action Handler
Here is the method signature for a batch action handler named handlerMethodName
:
Requirements for batch Action Handlers:
ActionResult
s must be returned in the same order as actions order.EITHER full results are returned, with no
ActionResult.defer
s in the results, OR partial results are returned, and only the last entry is aActionResult.defer
.
Accessing Grain value and updating it within the Action Handler
Last updated