Actor lifetime

Unlike Actor implementation on other platforms, such as Akka.net (https://petabridge.com/bootcamp/), Service Fabric Actors are virtual. What this means is that the Service Fabric Reliable Actors runtime manages the location and activation of Actor instances. The Reliable Actors runtime automatically activates an Actor the first time it receives a request for that Actor ID. If an Actor instance remains unused for a period of time, the Reliable Actors runtime garbage-collects the in-memory object. The Reliable Actors runtime also maintains knowledge of the Actor's existence in the state manager for any future Actor reactivations. Actor instances are activated only when the runtime receives a message that is intended to be served by the Actor. If a message is sent to the Actor instance and there is no activation of that Actor on any cluster node, then the runtime will pick a node and create a new activation there.

Every Actor has a unique identifier and calling any Actor method for an Actor ID makes the runtime activates that Actor. For this reason, the Actor constructors are not called by the client but are called implicitly by the runtime. Therefore, an Actor type's constructor can not accept parameters from the client code, although parameters may be passed to the Actor's constructor by the service itself. There is no single entry point for the activation of an Actor from the client.

Even though the client of an Actor does not have the capability to activate the Actor's constructor, the client does have the ability to explicitly delete an Actor and its state. The following diagram shows the lifecycle of an actor:

Reliable Actors lifetime

Every Actor derives from the Actor class. The runtime is responsible for invoking the Actor constructor. Every time an Actor instance is activated the OnActivateAsync method is invoked. You can override this method to initialize your Actor instance. Next, for every request sent to the Actor a pre-handle and a post-handle is available. If you want to log all operations that your Actor performs, then you can override these methods to add logging statements. Finally, the OnDeactivateAsyc method can be used to perform cleanup activities in Actor.

..................Content has been hidden....................

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