07-15-2016 01:58 AM
Dear community
I have a question about correct implementation of a proxy actor.
The proxy should forward all messages to a target actor without any knowledge about the message. In proxy actor I override Receive Message.vi and store the message object and its priority in member variables of proxy. Because the proxy actor cannot handle the message, do.vi throws bad cast error (1448). In Handle Error.vi I catch this error and forward the stored message to the target actor.
Can I implement proxy in that way or do I overlook some complications?
A LV2014 example is attached.
07-15-2016 02:02 AM
Have you checked this? Those remot launched Actors use proxies as well
07-15-2016 02:40 AM
Thanks for this tip Oli!
AristosQueue uses "get class name.vi" in this example. It was also my first idea, but I don't like it. So I have tried to implement without it. The doubt I have in my example is about synchronity between "receive message.vi" (RM) and "handle error.vi" (HE). If each call of RM implies imidiatly call of HE the ansatz should work. If not, it may by a better idea to create a message queue for messages to be forwarded.
07-19-2016 04:24 AM
Fire suggested this solution:
In order to avoid unnecessary error handling, all messages for proxy shall inherit from a proxy message base class. So it is possible to make a type cast test in Proxy:Receive Message.vi. If typecast fails, proxy forwards message to target actor. If not, proxy handles the message by itself. A example is attached.
Thanks to Fire!
07-27-2016 04:11 PM
To make this work, you'll need to modify Stop Msg to inherit from your Proxy Msg. That was the barrier I ran into with the remote message proxies.
07-28-2016 02:24 AM
Not necessarily. If the relation between Actor and its Proxy is one-to-one, the Stop-Msg can be send to the actor with no special handling. The actor will stop and the Proxy receives the Last Ack-Msg and can stop itself. Holger
07-28-2016 05:40 AM
Thanks to AQ and Holger for this helpfull discussion.
After some tests:
An LV2014 example is attached.
Note that in this implementation, the caller does not have to know to which class the Enqueuer belongs. In the example, the caller is "Launcher.vi". It can send "Send Target Action" directly to target actor or indirectly via proxy.
07-29-2016 02:02 AM
That just moved the problem to having to check for the Last Ack. 🙂