I have an application that runs a couple of state machines as independent processes. They communicate each other using User Events.
I’m trying to learn Actor Framework so I read a couple of resources and now I want to get my hands dirty with some code. I want to use my current application as a baseline and try to expand its capabilities by using actors.
I’ve a couple of questions:
Solved! Go to Solution.
- Do you recommend mixing Actor Framework with existing applications that don’t use AF?
Yes. But don't try to mix and match parts.
Start with your main app. Pick one module and convert it to a root actor, breaking out nested actors as needed. Make all the communication with that module go through the root actor. Don't try to cheat and have other lines of communication going to the actor or its nested actors. You'll defeat the whole point of the AF "clean lines" that protects you from a bunch of problems.
As you convert other modules, you make them into root actors with their own trees of nested actors. When two modules share a common root, make a new root class and change the existing actors into nested actors under that new root.
Create a new root actor whose only job is to call your application. Break a module out as a nested actor and change the application to send out messages to that nested actor. Repeat until all parallel activity is moved into a nested actor. Create further nested actors in their respective trees as needed.
This option has less rework involved but is sometimes harder to get started with.
If I launch a root and some nested actors from my main application how can I start sending messages to the root actor?
The output of Launch Root Actor.vi is the enqueuer that you use to send messages into the root actor.
If the root actor needs to communicate out to your calling application, you add whatever communication mechanism you want/need into the private data of the root actor and populate that reference before you launch the actor. This is why Option 1 above is often more work -- you spend time making a good root actor with some custom communication mechanism, then you have to replace it with the caller enqueuer when you refactor it to be a nested actor.
How can the root actor send a message without converting my main application to an actor?
See previous answer. Queues, notifiers, TCP, file refnums, globals... pick your poison for communication out of the root actor.