12-26-2019 08:30 AM
Hi All,
I wanted to have an Actor to be launched when needed and shut down when there are no messages sent/received for the configured time period. On shutdown, the Actor object will be returned to the caller and the caller can relaunch with the same object which will retain the previous state (Private data). Trying to avoid numerous MHL and helper loops running in parallel and launch the actor only when needed but initialize only once.
I could think of a simple helper loop to send a stop message after a set time period by having a message counter. But wanted to know if this could be created as reusable which any actors can use.
I am not very sure about the complexity it might result in and even if this is a valid use case to try for. Let me know your thoughts. (Please note I am new to AF and been exploring for a while)
Thanks,
Mani.
Solved! Go to Solution.
12-26-2019 01:04 PM
Hi Mani,
So depending on your use case, I'd suggest the following options might help you :
0 - you can simply end and relaunch Actors as needed, if you have some information about when you need them. They're pretty lightweight to start and so this can be considered, but doesn't answer your question (hence 0 not 1).
1 - as you suggested, create a helper loop in Actor Core and have it send a stop message on timeout from an Event Structure. Create a user event in Pre Launch Init and send the event each time you want to refresh the timeout. Register for the user event in AC. Be careful not to have other Events in the event structure. This can be reused via inheritance either with a Refresh message sent to self and handled by your parent class (this class) or by making the event reference available via protected accessor. You could perhaps use something akin to composition by launching this as a nested Actor for any other Actor, then having it stop the caller, but you'd have to prevent passing the message upwards.
2 - have a counter in the private data and override Receive Message to reset it to the max timeout if a certain subset of messages (or place a SubVI doing that in each chosen message). Send a time delayed message every however many seconds (E.g. 1 second, to have the counter be in seconds) to decrement the counter. If it reaches zero, have the time delayed message send a stop message.
12-26-2019 01:12 PM
It seems like the easiest answer would be to override Receive Message.vi and keep track of the timestamp of the last received message in the Actors private data that you update there. Then have a time-delayed message that checks to see if the time has elapsed( just make sure that doesn't reset the timestamp)
I attached a demo that does what you want. You could just create a parent class similar to the one in the demo and then have any actor where you want a timeout, just inherit from that. You could make it even more generic by adding some sort of strategy pattern to determine what happens when the timer expires (ie. shutdown, throw an error, perhaps something else?)
As far as the initialization, simply grabbing the actor from the last ack should be enough. You'll have prelaunch init running everytime, but you should only be using that for things that get initialized everytime it launches (for example refnums). For everything else just set it once before you launch it.
Hope that helps.
12-27-2019 06:41 PM
Is this a good idea? Loops just waiting on messages is a low overhead thing. What is the benefit?
12-30-2019 08:11 AM
Thanks, Cbutcher & Taggart, for the suggestions, Overriding the Recieve Message.vi seems to be the way.
Taggart, the code you shared was an empty project and please share it again if possible.
Powell, In my application, there will be >10 actors launched (apart from other actors) to acquire from the camera and it will have a helper loop for the acquisition to stream images at a faster rate. Since not all the cameras are needed to run every time, planning to launch the actor on-demand with a pre-initialized Actor Object. Let me know your thoughts.
Thanks,
Mani.
12-30-2019 10:16 AM
Here it is again.
12-30-2019 10:17 AM
I just realized I attached the wrong thing the first time. Sorry about that.
12-30-2019 02:12 PM
@manig wrote:
Powell, In my application, there will be >10 actors launched (apart from other actors) to acquire from the camera and it will have a helper loop for the acquisition to stream images at a faster rate. Since not all the cameras are needed to run every time, planning to launch the actor on-demand with a pre-initialized Actor Object. Let me know your thoughts.
I'd stand by my previous answers, but I do wonder if (given this topic may become a little longer than simply "how can I do X?") if this is necessary/the best approach.
If you'd like, perhaps you can describe a bit more of your application and forum readers could give some feedback or suggestions?
Of course, if you're happy with what you've already gotten and don't wish further discussion, that's also fine.
12-30-2019 04:20 PM
I agree with Christian and Dr Powell. Just because you can doesn't necessarily mean it is a good idea or in this case necessary.
01-03-2020 07:25 AM
Thanks, Powell, Christian & Taggart for your thoughts.
Bit more details about my application,
1. The application will collect image streams from multiple cameras connected to PXI using different interfaces(GigE, USB3,...) based on the request from other applications (connected through TCP).
2. There will be a scenario where multiple cameras might be streamed at a time - say 3 camera is streamed at a time out of 12 cameras connected.
3. Planning to launch an individual Camera actor for each camera connected and the Camera actor will be responsible for IMAQ initialize, Configure camera and acquisition (which will happen in the helper loop). Another approach is to have acquisition alone delegated to separate actor and this requires sharing of session handles and camera interface classes properly.
4. To optimize the number of the loop running in parallel, thought of shutting down camera actors which are not currently used and relaunch the actor with the same object when there is request. Apart from Camera actors, there will be other actors running in parallel (~10 to 12).
Please let me know if you have any other questions on this.