Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Implementation of a proxy actor using Receive Message.vi

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.

0 Kudos
Message 1 of 8
(4,843 Views)

Have you checked this? Those remot launched Actors use proxies as well

0 Kudos
Message 2 of 8
(4,041 Views)

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.

0 Kudos
Message 3 of 8
(4,041 Views)

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!

0 Kudos
Message 4 of 8
(4,041 Views)

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.

Message 5 of 8
(4,041 Views)

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

Message 6 of 8
(4,041 Views)

Thanks to AQ and Holger for this helpfull discussion.

After some tests:

  • If proxy is root and target is nested actor, behavior is like Holger describes. It also possible to start more target actors, the shutdown mechanism works in 1:N configuration still fine.
  • Problem mentioned by AQ arises if target is the root actor and proxy is the nested actor. Assume that target actor wants to shutdown or  to restart the proxy. If target send "Stop Msg" to proxy, proxy forwards it back, and  thus target actor kills himself.
  • To avoid this behavior, I have made a copy of "Stop Msg.lvclass" and let it inherit from "Proxy Msg Base.lvclass". The target actor uses "Proxy Stop Msg" to stop the proxy.

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.

0 Kudos
Message 7 of 8
(4,041 Views)

That just moved the problem to having to check for the Last Ack. 🙂

0 Kudos
Message 8 of 8
(4,041 Views)