Classes - reyou/Ggg.AkkaNET GitHub Wiki


https://getakka.net/api/index.html


Class Receive​Timeout

https://getakka.net/articles/actors/receive-actor-api.html#receive-timeout

This message is sent to an actor that has set a receive timeout, either by calling Set​Receive​Timeout(Nullable<Time​Span>) or Set​Receive​Timeout(Nullable<Time​Span>) and no message has been sent to the actor during the specified amount of time.

public MyActor()
        {
            Receive<string>(s => s.Equals("Hello"), msg =>
            {
                Context.SetReceiveTimeout(TimeSpan.FromMilliseconds(100));
            });

            Receive<ReceiveTimeout>(msg =>
            {
                Context.SetReceiveTimeout(null);
                throw new Exception("Receive timed out");
            });
        }

Context.Watch

https://getakka.net/articles/actors/receive-actor-api.html#lifecycle-monitoring-aka-deathwatch

In order to be notified when another actor terminates (i.e. stops permanently, not temporary failure and restart), an actor may register itself for reception of the Terminated message dispatched by the other actor upon termination (see Stopping Actors). This service is provided by the DeathWatch component of the actor system.


Class Actor​Selection

This class represents a logical view of a section of an Actor​System tree of actors that allows for broadcasting of messages to that section.


Interface IActor​Ref

An actor reference. Acts as a handle to an actor. Used to send messages to an actor, whether an actor is local or remote. If you receive a reference to an actor, that actor is guaranteed to have existed at some point in the past. However, an actor can always be terminated in the future.

If you want to be notified about an actor terminating, call on this actor and you'll receive a Terminated message when the actor dies or if it is already dead.

Forward(IActorRef, Object)

Forwards the message using the current Sender.

TestUtilities.WriteLine("DeviceGroup.OnReceive() deviceNotFound: " + message);
Props props = Device.Props(trackMsg.GroupId, trackMsg.DeviceId);
IActorRef deviceActor = Context.ActorOf(props, $"device-{trackMsg.DeviceId}");
_deviceIdToActor.Add(trackMsg.DeviceId, deviceActor);
TestUtilities.WriteLine("DeviceGroup.OnReceive() deviceCreated: " + deviceActor);
deviceActor.Forward(trackMsg);

Class Actor​System

An actor system is a hierarchical group of actors which share common configuration, e.g. dispatchers, deployments, remote capabilities and addresses. It is also the entry point for creating or looking up actors. There are several possibilities for creating actors (see Props for details on props):

system.ActorOf(props, "name");
system.ActorOf(props);
system.ActorOf(Props.Create(typeof(MyActor)), "name");
system.ActorOf(Props.Create(() => new MyActor(arg1, arg2), "name");
using (ActorSystem system = ActorSystem.Create("iot-system")){
      IActorRef supervisor = system.ActorOf(Props.Create<IotSupervisor>(), "iot-supervisor");
      TestUtilities.WriteLine("IotApp Init supervisor: " + supervisor);
 }

Where no name is given explicitly, one will be automatically generated. Important Notice: This class is not meant to be extended by user code.


Class Backoff​Options

WithSupervisorStrategy(OneForOneStrategy)

The Supervisor​Strategy that the back-off supervisor will use. The default supervisor strategy is used as fallback if the specified SupervisorStrategy (its decider) does not explicitly handle an exception.

The below code sets up a back-off supervisor that restarts the child after back-off if HttpRequestException is thrown, any other exception will be escalated. The back-off is automatically reset if the child does not throw any errors within 10 seconds.

  public void OnStopWithSupervisorStrategyExample()
        {
            Props childProps = Props.Create<EchoActor>();
            BackoffOptions backoffOptions = Backoff.OnStop(
                    childProps,
                    childName: "myEcho",
                    minBackoff: TimeSpan.FromSeconds(3),
                    maxBackoff: TimeSpan.FromSeconds(30),
                    randomFactor: 0.2)
                .WithAutoReset(TimeSpan.FromSeconds(10))
                .WithSupervisorStrategy(new OneForOneStrategy(exception =>
                {
                    if (exception is HttpRequestException)
                        return Directive.Restart;
                    return Directive.Escalate;
                }));
            Props supervisor = BackoffSupervisor.Props(backoffOptions);
            IActorRef actorRef = Sys.ActorOf(supervisor, "echoSupervisor");
        }

WithDefaultStoppingStrategy()

Returns a new Backoff​Options with a default Stopping​Strategy. The default supervisor strategy is used as fallback for throwables not handled by Stopping​Strategy.

The below code sets up a back-off supervisor that requires the child actor to send a Akka.Pattern.BackoffSupervisor.Reset message to its parent when a message is successfully processed, resetting the back-off. It also uses a default stopping strategy, any exception will cause the child to stop.

 BackoffOptions backoffOptions = Backoff.OnStop(
                    childProps: childProps,
                    childName: "myEcho",
                    minBackoff: TimeSpan.FromSeconds(3),
                    maxBackoff: TimeSpan.FromSeconds(30),
                    randomFactor: 0.2)
                .WithManualReset() // the child must send BackoffSupervisor.Reset to its parent
                .WithDefaultStoppingStrategy();

Class Backoff​Supervisor

Actor used to supervise actors with ability to restart them after back-off timeout occurred. It's designed for cases when i.e. persistent actor stops due to journal unavailability or failure. In this case it is better to wait before restart.

Props supervisor = BackoffSupervisor.Props(backoffOptions);
IActorRef actorRef = Sys.ActorOf(supervisor, "echoSupervisor");

Class Echo​Actor

An Echo​Actor is an actor that echoes whatever is sent to it, to the TestKit's Test​Actor. By default it also echoes back to the sender, unless the sender is the Test​Actor (in this case the Test​Actor will only receive one message).


Class Props

This class represents a configuration object used in creating an Actor​Base. It is immutable and thus thread-safe.

Props childProps = Props.Create<EchoActor>();

Class Backoff

Builds back-off options for creating a back-off supervisor. You can pass Backoff​Options to Props(Backoff​Options).

 BackoffOptions backoffOptions = Backoff.OnStop(childProps, "myEcho",
                TimeSpan.FromSeconds(3),
                TimeSpan.FromSeconds(30),
                randomFactor: 0.2);

⚠️ **GitHub.com Fallback** ⚠️