ActorBase Class

  • java.lang.Object
    • microsoft.servicefabric.actors.runtime.ActorBase

public class ActorBase

Represents base class for actors. Actor

Remarks:This is a base type for actor, it provides the functionality that is common across actors implemented by actor deriving from Actor The state is preserved across actor garbage collections and fail-overs. The storage and retrieval of the state is provided by the actor state provider ActorStateProvider.

Constructor Summary

Constructor Description
ActorBase(FabricActorService actorService, ActorId actorId)

Method Summary

Modifier and Type Method and Description
FabricActorService getActorService()

Gets the stateful service replica that is hosting the actor.

String getApplicationName()

Gets the name of the application that contains the actor service that is hosting this actor.

DiagnosticsManagerActorContext getDiagnosticsContext()

Returns the diagnostics context for an actor. For internal use only.

<T> T getEvent(Class<T> eventClass)

Gets the event for the specified event interface.

ActorId getId()

Gets the identity of this actor with the actor service.

ActorReminder getReminder(String reminderName)

Gets the actor reminder with specified reminder name.

URI getServiceUri()

Gets the Uri of the actor service that is hosting this actor.

boolean isDirty()

Check if actor state is dirty.

CompletableFuture<?> onActivateAsync()

Override this method to initialize the members, initialize state or register timers. This method is called right after the actor is activated and before any method call or reminders are dispatched on it.

CompletableFuture<?> onDeactivateAsync()

Override this method to release any resources including unregistering the timers. This method is called right before the actor is deactivated.

CompletableFuture<?> onPostActorMethodAsync(ActorMethodContext actorMethodContext)

This method is invoked by actor runtime an actor method has finished execution. Override this method for performing any actions after an actor method has finished execution.

Remarks: This method is invoked by actor runtime prior to:

  • Invoking an actor interface method when a client request comes.

  • Invoking a method on Remindable interface when a reminder fires.

  • Invoking a timer callback when timer fires.

CompletableFuture<?> onPreActorMethodAsync(ActorMethodContext actorMethodContext)

This method is invoked by actor runtime just before invoking an actor method. Override this method for performing any actions prior to an actor method is invoked.

Remarks:This method is invoked by actor runtime prior to:

  • Invoking an actor interface method when a client request comes.

  • Invoking a method on Remindable interface when a reminder fires.

  • Invoking a timer callback when timer fires.

CompletableFuture<?> registerReminderAsync(String reminderName, byte[] state, Duration dueTime, Duration period)

Registers the specified reminder with actor.

ActorTimer registerTimer(Function<Object, CompletableFuture<?>> asyncCallback, Object state, Duration dueTime, Duration period)

Registers a Timer for the actor.

ActorTimer registerTimer(Function<Object, CompletableFuture<?>> asyncCallback, String asyncCallbackFunctionName, Object state, Duration dueTime, Duration period)

Registers a Timer for the actor.

void setDirty(boolean isDirty)

Sets the actor state as dirty.

void setDummy(boolean isDummy)

Set the actor state whether its dummy or not.

CompletableFuture<?> unregisterReminderAsync(ActorReminder reminder)

Unregisters the specified reminder with actor.

void unregisterTimer(ActorTimer timer)

Unregisters a Timer previously set on this actor.

Constructor Details

ActorBase

protected ActorBase(FabricActorService actorService, ActorId actorId)

Parameters:

actorService
actorId

Method Details

getActorService

public FabricActorService getActorService()

Gets the stateful service replica that is hosting the actor.

Returns:

FabricActorService that represents the stateful service replica hosting the actor. actor.

getApplicationName

public String getApplicationName()

Gets the name of the application that contains the actor service that is hosting this actor.

Returns:

Name of application that contains the actor service that is hosting this actor.

getDiagnosticsContext

public DiagnosticsManagerActorContext getDiagnosticsContext()

Returns the diagnostics context for an actor. For internal use only.

Returns:

diagnostics context.

getEvent

protected T getEvent(Class eventClass)

Gets the event for the specified event interface.

Parameters:

eventClass - Event class.

Returns:

Returns Event that represents the specified interface.

getId

public ActorId getId()

Gets the identity of this actor with the actor service.

Returns:

ActorId for the actor.

getReminder

protected ActorReminder getReminder(String reminderName)

Gets the actor reminder with specified reminder name.

Parameters:

reminderName - Name of the reminder to get.

Returns:

An ActorReminder that represents an actor reminder.

getServiceUri

public URI getServiceUri()

Gets the Uri of the actor service that is hosting this actor.

Returns:

java.net.URI of the actor service that is hosting this actor.

isDirty

public boolean isDirty()

Check if actor state is dirty.

Returns:

Boolean value true if actor state is dirty; otherwise false.

onActivateAsync

protected CompletableFuture onActivateAsync()

Override this method to initialize the members, initialize state or register timers. This method is called right after the actor is activated and before any method call or reminders are dispatched on it.

Returns:

A CompletableFuture that represents outstanding OnActivateAsync operation.

onDeactivateAsync

protected CompletableFuture onDeactivateAsync()

Override this method to release any resources including unregistering the timers. This method is called right before the actor is deactivated.

Returns:

A CompletableFuture that represents outstanding OnDeactivateAsync operation.

onPostActorMethodAsync

protected CompletableFuture onPostActorMethodAsync(ActorMethodContext actorMethodContext)

This method is invoked by actor runtime an actor method has finished execution. Override this method for performing any actions after an actor method has finished execution.

Remarks: This method is invoked by actor runtime prior to:

  • Invoking an actor interface method when a client request comes.

  • Invoking a method on Remindable interface when a reminder fires.

  • Invoking a timer callback when timer fires.

Parameters:

actorMethodContext - An ActorMethodContext describing the method that was invoked by actor runtime prior to this method.

Returns:

A CompletableFuture representing post-actor-method operation.

onPreActorMethodAsync

protected CompletableFuture onPreActorMethodAsync(ActorMethodContext actorMethodContext)

This method is invoked by actor runtime just before invoking an actor method. Override this method for performing any actions prior to an actor method is invoked.

Remarks:This method is invoked by actor runtime prior to:

  • Invoking an actor interface method when a client request comes.

  • Invoking a method on Remindable interface when a reminder fires.

  • Invoking a timer callback when timer fires.

Parameters:

actorMethodContext - An ActorMethodContext describing the method that will be invoked by actor runtime after this method finishes.

Returns:

A CompletableFuture representing pre-actor-method operation.

registerReminderAsync

protected CompletableFuture registerReminderAsync(String reminderName, byte[] state, Duration dueTime, Duration period)

Registers the specified reminder with actor.

Parameters:

reminderName - Name of the reminder to register
state - State associated with reminder.
dueTime - A java.time.Duration representing the amount of time to delay before firing the reminder. Specify negative one (-1) milliseconds to prevent reminder from firing. Specify zero (0) to fire the reminder immediately.
period - The time interval between firing of reminders. Specify negative one (-1) milliseconds to disable periodic firing.

Returns:

A task that represents the asynchronous registration operation.

registerTimer

protected ActorTimer registerTimer(Function> asyncCallback, Object state, Duration dueTime, Duration period)

Registers a Timer for the actor.

Parameters:

asyncCallback - Callback to invoke when timer fires.
state - State to pass into timer callback.
dueTime - TimeSpan when actor timer is first due.
period - TimeSpan for subsequent actor timer invocation.

Returns:

Returns ActorTimer object.

registerTimer

protected ActorTimer registerTimer(Function> asyncCallback, String asyncCallbackFunctionName, Object state, Duration dueTime, Duration period)

Registers a Timer for the actor.

Parameters:

asyncCallback - Callback to invoke when timer fires.
asyncCallbackFunctionName - name of AsyncCallBack function. It can be used in onPreActorMethodAsync(ActorMethodContext actorMethodContext) and onPostActorMethodAsync(ActorMethodContext actorMethodContext) to initiate any user task on pre- and post- calling of this function. The property getMethodName() will give the method name.
state - State to pass into timer callback.
dueTime - TimeSpan when actor timer is first due.
period - TimeSpan for subsequent actor timer invocation.

Returns:

Returns ActorTimer object.

setDirty

public void setDirty(boolean isDirty)

Sets the actor state as dirty.

Parameters:

isDirty - takes actor state as boolean value: true or false.

setDummy

protected void setDummy(boolean isDummy)

Set the actor state whether its dummy or not.

Parameters:

isDummy - takes actor state as boolean value : true or false.

unregisterReminderAsync

protected CompletableFuture unregisterReminderAsync(ActorReminder reminder)

Unregisters the specified reminder with actor.

Parameters:

reminder - The actor reminder to unregister.

Returns:

A task that represents the asynchronous unregister operation.

unregisterTimer

protected void unregisterTimer(ActorTimer timer)

Unregisters a Timer previously set on this actor.

Parameters:

timer - ActorTimer representing timer that needs to be unregistered.

Applies to