Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read Last Ack message?

I need to cache an actor's state in memory in between instances, and I'd hoped to get that information by reading the Last Ack message...but I can't figure out how to do it using functions in the palette! Can someone help, maybe with a simple example or a description of how to rewrite this excerpt? Do I just need to cast the message output of the "Dequeue" function to a Last Ack class, then write it into the final VI? If so, is there a better way of doing this that guarantees the message I'm reading is the Last Ack (other than testing all messages left in the queue for type)?

last_ack_attempt.PNG

0 Kudos
Message 1 of 6
(6,672 Views)

David-

I think what you may be missing is that the Callee Actor (the one you want to cache the state of by receiving Last Ack) should be launched by another Actor (the Caller Actor).  You would probably put the Launch Actor.vi in your example into the Actor Core.vi of the Caller Actor.  Then in the Caller Actor class, you simply override Handle Last Ack Core.vi and that VI will run when the Last Ack message is sent by the Callee Actor as it shuts down.  If you don't do it this way, then I don't think there is a way to ever see the Callee's Last Ack message (or if there is, it is probably much more difficult than what I have described).

0 Kudos
Message 2 of 6
(4,458 Views)

The Last Ack message will be posted to the Callee's Caller Queue - the one (optionally) supplied to Launch Actor and returned by Get Queue for Sending To Caller.  That message will have the Caller Actor as part of the message's private data - you already use Read Actor in your snippet but no message is wired.  If your Caller was an Actor, then as Eric stated you would override the Handle Last Ack Core.  If it is not an Actor, then you have no message processing loop and you will have to handle that on your own.  Your start with dequeueing a message is correct.  It would have to be cast (To More Specific) to a Last Ack message, but be aware there may be left over messages pending on the Caller's queue, so casting may fail and you will need to 'handle or ignore' those errors.

Alternately, just prior to the Last Ack being sent, the Stop Core method is called.  This is a Callee method.  It happens when Actor Core completes.  It is the Callee's last chance to do anything.  You could implement the state saving mechanism at this point also.

I hope this helps.

0 Kudos
Message 3 of 6
(4,458 Views)

Thanks to you both. Kurt, that's what I suspected: I'll have to run through all the messages left in the queue after the actor stops, casting each one to a Last Ack and handling the error. When I find the Last Ack, I can pop the Actor from it and hold onto its final state in the caller.

I don't think overridin the Stop Core will work for this, because I need to cache the Actor's state to memory, not to disk. If I store it in a DVR or an FGV, that data will be destroyed when the actor shuts down and closes its panel. It seems I need to pass the state out to the caller via a queue, then hold the state data in the caller.

Here's the code I'm using to get the final state of the actor after it shuts down:

get_last_ack.PNG

NOTE: This is not the proper code. Look farther down the thread for the final implementation.

0 Kudos
Message 4 of 6
(4,458 Views)

Staab: Your solution works as long as you're directly calling Actor.vi. If you try to use Launch Actor.vi, it doesn't quite work... in that case, you'd need to make your loop stop when you get the LastAck otherwise you'll hang. You need an Or on that loop test:

lastack.png

I'm mentioning this mostly for other readers who see your post and are looking for how to do this.

0 Kudos
Message 5 of 6
(4,458 Views)

AQ -

Why are your framework icons so much prettier than mine? It's almost like you had help from someone dedicated to creating nice icons for components built into LabVIEW itself... At any rate, I want them!

As you can see in my screenshot, I am calling Launch Actor, and it worked just fine for my proof-of-concept. My loop stops when I get Last Ack because I'm using the "continue" terminal with the error from the casting attempt, and not the "stop" terminal. However, I do need to fix the error handling to treat errors from the dequeue method differently than errors from the cast prim.

It should also be mentioned that I assume  my actor only talks to its caller, and the only thing of interest it'll ever say is "Last Ack".

Untitled.png

Message was edited by: DavidStaab

0 Kudos
Message 6 of 6
(4,458 Views)