Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Can someone provide a simple demo how to use Last Ack Messages?

Solved!
Go to solution

Hi all,

maybe I have read too much stuff or whatever is wrong. I need a little help to get me back on track again.

I can't figure out how to utilize the Last Ack Message. I want to get the final state of a nested actor that has been stopped or stopped by itself.

In order to figure this out I created a new project from AF and modified the Stop Core.vi of one of the nested tactors to create a message a la "<Stop> received at 03.06.2014 - 17:27:40". In the Stop Core.vi of the main actor I want to retrieve this message, send it to the Event Log display and wait some seconds to be able to see the Last Ack Message from the nested actor. But it did not work out. Any of my attempts either did not show the message or raised a runtime error I could see in Desktop Trace Execution Toolkit. I am out of ideas now

The post 'How to read Last Ack message?' by Dave Staab here in the group seemed to show that, but at first its quite old and at second it uses 'Obtain message queue' which is not related to the actors as described above. I 'feel' this is not the proper way.

Can someone provide such an example of code with LabVIEW 2013 SP1 (version 13.0.1f2 (32 bit)?

I would be very gratefull, as I try to solve that problem for more than 3 days now.

TIA

--

Uwe

0 Kudos
Message 1 of 14
(8,658 Views)
Solution
Accepted by topic author LuI

Hello,

You can give this coffee shop example a look.  In the top-level coffee shop actor (Starbuzz.lvclass), you can see an example of an override of Handle Last Ack, which is how the top-level actor is notified that a dynamically launched nested actor (such as a customer, cashier, or barista) has shut down, along with the ability to get its last state.  The code in that area needs some love, but is certainly functional.

Note that Handle Last Ack, which is the method called when an actor receives a last ack message from a nested actor, is separate and distinct from Stop Core, which is called when the actor itself is closing down.  The framework itself will guarantee that a Last Ack message is sent from a nested actor to its  caller when the nested actor stops - you do not need to manually send such a message.  If you want to see where this happens, take a look at the block diagram of Actor.vi in the root Actor.lvclass that ships in vi.lib.

Is your use case that you are shutting down the whole system and need to make sure the top level doesn't stop until its nested actors stop, or are you shutting down only some of your nested actors while the top level remains running?

Cheers,

Matt Pollock
National Instruments
0 Kudos
Message 2 of 14
(4,740 Views)

Lul:

Part of your post doesn't make sense.

"In the Stop Core.vi of the main actor I want to retrieve this message"

An actor cannot retrieve messages in Stop Core.vi. In Stop Core.vi, an actor does its own shutdown work, whatever that is. It can send messages but it cannot receive them there.

Can you clarify what you mean by "retrieve"?

"I want to get the final state of a nested actor that has been stopped or stopped by itself."

That will happen for free when your nested actor stops -- when any actor stops, the last action it does -- built into the framework -- is send the Last Ack message back to its caller. That message contains the actor's final state, and the caller can override Handle Last Ack.vi in order to obtain that value.

Message 3 of 14
(4,740 Views)

MattP, thx for your example. This is exactly what I wanted to see and could not find.

The idea I sketched above was to modify the template project in a way so that when I press the <Stop All>-button, one of the nested actors creates a notifying text in its privat data, which is retrieved by the main actor and displayed before itself shuts down. Just a simple experiment to explore the idea.

My real project needs to start some actors to be started in a given sequence and to get their final state when they had finished. This seems to be possible with the new information. Thank you again!

Greetimgs from Germany!

--

Uwe

0 Kudos
Message 4 of 14
(4,740 Views)

Steven,

thx for your clarifying answer. I was locked somehow, but the starbuzz example has helped me out.

The idea I sketched above was to modify the project (as created freshly from AF template) in a way so that when I press the <Stop All>-button, one of the nested actors stores a notifying text in its privat data, which is retrieved by the main actor in a 'Handle Last Ack' and displayed before itself shuts down. Just a simple experiment to explore the idea.

So if that cannot be done in main actors Stop Core.vi, I'll try to modify the event handler for that button as the base for that action. So to sent the stop message to both nested actors, wait for a Last Ack message, show that notifying text and tahn send Stop to itself.

Thank you again for that clarifying.

Greetimgs from Germany!

--

Uwe

0 Kudos
Message 5 of 14
(4,740 Views)

Glad we were able to help.

0 Kudos
Message 6 of 14
(4,740 Views)

That worked out quite well, but I had to find my way to Handle Last Ack Messages. The example it StarBuzz is not that impressing.

At this time I do get the name of the returned class, convert it to a string that is unique in the library and use that as a case selector to cast to the best actor:

AFW_4.png

0 Kudos
Message 7 of 14
(4,740 Views)

Agreed, that area of Starbuzz is, shall we say, lacking.  The next time that example comes up for modification, cleaning up that area is at the top of the list.

Cheers,

Matt Pollock
National Instruments
0 Kudos
Message 8 of 14
(4,740 Views)

MattP wrote:

Note that Handle Last Ack, which is the method called when an actor receives a last ack message from a nested actor, is separate and distinct from Stop Core, which is called when the actor itself is closing down.  The framework itself will guarantee that a Last Ack message is sent from a nested actor to its  caller when the nested actor stops - you do not need to manually send such a message. 

So, maybe just a minor point to what Matt has written here - if your system throws an error in the Pre-Launch Init.vi and you pass that error to the error terminal, the Last Ack message will not be sent.  This caused a little bit of a headache for me as I could not figure out why my main Actor was not getting the last ack (and this in turn was causing that actor to shut the rest of the actors it was responsible for to shut down).  This is probably fairly obvious to others, but it caused some head scratching here.

Matt

0 Kudos
Message 9 of 14
(4,740 Views)

It never sent a last ack because it never even launched... shouldn't have caused any problem for your caller because your caller got the error directly out of Launch Actor. If you didn't get the error out of Launch Actor, we have a bug that needs addressing.

0 Kudos
Message 10 of 14
(4,740 Views)