Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Right way/place for nested actor to tell parent that nested actor is stopping

What is the right way and place to send message from nested actor to parent to tell that the nested actor is stopping? I want the parent to know that nested actor is quitting.

I tried to send message from nested actor's actor core helper loop when Events.stop is executed, but that seems to be too "late" and message is not sent.

If I send the message in nested actor's Stop Core (see pic) it works. But is it ok to send it like that?

Waltteri_0-1622694025299.png

I'm using LabView 2017.

0 Kudos
Message 1 of 8
(1,879 Views)

Usually you get this from the Handle Last Ack override in the caller actor.

 

If you're storing the enqueuer of the nested (quitting) actor, then you can read the enqueuer in Last Ack and compare to a Map or similar of enqueuers/Actor identities and then you know which Actor quit.


GCentral
0 Kudos
Message 2 of 8
(1,855 Views)

Handle Last Ack Core.vi

Actor Framework already implements this. Overwrite this method in your root actor. Use "Read Actor.vi" to read the last state of your actor.

0 Kudos
Message 3 of 8
(1,854 Views)

Thanks, I see that Handle Last Ack Core.vi is called on parent actor when nested actor stops.

If I have two different type of nested actors, how can I tell which one sent the last message?

0 Kudos
Message 4 of 8
(1,835 Views)

As @cbutcher said: compare the enqueur. Or You can make cast to more specific class.

0 Kudos
Message 5 of 8
(1,831 Views)

Got it to work, thanks.

0 Kudos
Message 6 of 8
(1,821 Views)

For the sake of those coming to this post in the future, although neither of these examples specifically cover the OP's question, here are some overrides of Handle Last Ack Core I've used:

 

cbutcher_0-1622711930600.png

Here I use the enqueuer of the stopping Actor to deregister from a Registration Map (LabVIEW 2019 feature) that I use for sending data to various systems in a publish-subscribe type of arrangement. When the actor stops, no point in sending it more data!

If the Actor stops because of an error, I can also log why (usually they stop normally and just choose to disconnect).

 

cbutcher_1-1622712072496.png

Here I have a system that restarts an Actor when it stops (e.g. due to error, this is for a Network Stream handler that can be restarted for reconnection to produce a Server/Client setup).

Displayed below the Handle Last Ack Core is the method used to stop the relaunching (root, in this case) Actor when we want to actually stop, rather than keep relaunching.

 

In the case of this second example, you can see that the root/caller Actor has an enqueuer stored in private data with an easy-to-access unbundle. If your number of callee/nested Actors is small and they have specific purposes, you might also have a similar structure. In such a case, you can compare the enqueuer (seen in the first example, using "Read Caller-to-Actor Enqueuer.vi") with the bundled value to identify what stopped. Hopefully this clarifies what was previously written above (previously posting from a phone).

 


GCentral
Message 7 of 8
(1,817 Views)

@Waltteri wrote:

I tried to send message from nested actor's actor core helper loop when Events.stop is executed, but that seems to be too "late" and message is not sent.


That makes no sense. As long as caller is still running, the message gets sent. Are you seeing an error reported by the Send node? The LastAck is intended to solve this issue, but your earlier solution should have worked... and sometimes is more useful pattern than relying on LastAck, so I don’t want people thinking it doesn’t work. Are you racing shutdown of the caller???

0 Kudos
Message 8 of 8
(1,797 Views)