Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Asynchronous Send and Reply msg

Ok I have a question. I have a process that I need to be able to launch an actor, only 1 of it's kind at a time in memory. The process works fine for launching, and I have a method to shut it down as well. However, if I launch 2 of the same actor, when I go to shut it down, it errors and crashes the application.

Here is how I have it set up. I have the "controller actor" which is the root actor, the UI and other actors are launched from the root. The UI sends a message to the controller to spin up the process (Read Error Log). I can launch the same process again a 2nd time, and shut the first one down. Once I try to shut the second one down, it throws an error to the controller which then shuts itself and all of the nested actors down, except the UI.

Not sure whats going on. I guess I could implement this Read Error Log Actor as a singleton? that way only one can be in memory at a time?

What I was thinking of doing would be to have code that before it sends the launch msg to the controller, that it first sends a msg to have the controller check the queue and see if its already running, if so, dont allow the launch, if not, then allow it. This would require a msg to be sent by the UI, and have the UI wait on a reply before it completes the call. Is there a way to do this asynchronously so that the UI doesnt hang?

Sorry its so long, I am trying to be as detailed as possible.

-Steven

0 Kudos
Message 1 of 7
(6,011 Views)

Do you  know what the error message is that the Controller throws when you try to shut the second Read Error Log down?  Regarding the use of "Send Message and Wait for Response", I wouldnt recommend using this for Actor to Actor communication.  The only time I have used this feature was when I wrote an Actor based driver for some hardware and needed a non-Actor API that could communicate with my driver (i.e. read voltage on channel 1).

Message 2 of 7
(4,114 Views)

Jon no I dont...I need to investigate it further. Correct, I dont want to use the Send Msg and Wait for Response, I know that will lock the UI thread until the controller responds back, and that is what I want to avoid.

I am working on a solution now. I created a method that launches and shuts-down the launched actor, but in that process, I embedded another method that looks at the queue of launched actors and if it doesnt see the actor I am wanting to launch then it launches, if not it ignores the msg. On shutdown, another method is called stops the launched actor, but first calls another method to check the queue yet again, if the actor is in the queue, then it proceeds, if not, it ignores the msg.

0 Kudos
Message 3 of 7
(4,114 Views)

Got it, misread your post.  For what its worth the self addressed message sounds like what you were after, although it looks like your current solution no longer needs it.

Playing devils advocate, what if your Read Error Log actor shuts down on its own?  Are you handling the Last Ack in your Controller?  If not, the Controller will still have the Read Error Log actors enqueuer in its queue, and when the View tries to launch a new Read Error Log actor the controller will reject it.

Message 4 of 7
(4,114 Views)

ok so I need to add the Handle Lask Ack Core to my controller or parent actor class override? That way any nested actor that it launched, when that nested actor closes down it informs the parent actor that it did so, so that it can clean up its queue reference, is that correct? i am still fairly new to using this framework so I dont know all of the intricacies yet.

0 Kudos
Message 5 of 7
(4,114 Views)

Thats correct, if you override the Handle Last Ack Core in your Controller then anytime a nested Actor closes the Handle Last Ack Core override will fire.  You can get the nested actors class data and use it to do whatever you want (i.e. clean up queue refs or send a message to self to re-launch). 

RE: being fairly new, I think you are learning this stuff faster than I did when I was new to it.

Message 6 of 7
(4,114 Views)

Thanks Jon, yeah its a neat architecture. I like how it handles messages and all the queues. That way I dont have to worry about it and can focus on the program at hand, and the messaging.

0 Kudos
Message 7 of 7
(4,114 Views)