Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Can AF send message or data to another one between different branch?

Solved!
Go to solution

Hi every one,

 

I learned that the AF can only send message through branch way. Like I have two branches, each one have three actors. If there are data between two branch end actor, the data will be send through caller and a long way to the other one. I mean can AF send data to each other directly, or is there a quick way to send data? Like the picture shows.

图片1.png

0 Kudos
Message 1 of 10
(3,422 Views)

You just need to figure out how to get the desired enqueuer to your sender.

 

Be advised that you are potentially making your code harder to debug. You are trading that for writing less messages.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
Message 2 of 10
(3,409 Views)

Thank you for your advise. I can use message to send data. And I also think about how to get the desired enqueuer. But the problem is that I only know two ways to get the desired enqueuer, one is using read caller equeuer and the other is using read self equeuer. So is that the reason why message can only be send through caller and nest actor. 

0 Kudos
Message 3 of 10
(3,404 Views)
Solution
Accepted by topic author champion2019

I was one of my first questions about actor framework. The short answer is that there isn't an easy way to do this on purpose.

 

You could pass actor queues around so that the actor in one branch has access to the actor's queue from the other branch. There are also some AF extensions and libraries that will help you with this (mva framework, primary key's package).

 

But, the AF forces a hierarchical architecture to avoid a class of errors. If you find yourself needing to do this it's a good idea to think if you really actually need it or if there's a better way to structure your actors or message flow to keep branches separate.

Message 4 of 10
(3,396 Views)

As to the mechanics, just send it in a message.

 

As Mark mentioned, think long and hard about why you want to do that.  It's not the worst thing in the world but you are making some tradeoffs.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
0 Kudos
Message 5 of 10
(3,387 Views)

Thank you very much. Your answer really solve my confusion. You are right. I don't have to send message or data like that. But I just wonder why actor can't send message like that.

0 Kudos
Message 6 of 10
(3,382 Views)

You can implement an easy proxy in you root actor by overwriting the receive message.vi
Please read this post:
https://forums.ni.com/t5/Actor-Framework-Discussions/Communicate-Between-Parallel-Nested-Actors/m-p/...

0 Kudos
Message 7 of 10
(3,309 Views)
Solution
Accepted by topic author champion2019

@champion2019 wrote:

But I just wonder why actor can't send message like that.


Actors can send messages to any enqueuer they want to. You can read a current actor's enqueuer, and you can read the caller's enqueuer, or you can just use a variable and pass the actor enquerer down the chain, sending it in messages or loading it in the actor's private data with a method or any number of ways.

 

The reason this isn't really recommended is that it involves coupling a single actor to multiple other actors. For the linked example from the post above, there's a "main" actor that launches a Simulation actor and a Logging actor, and the OP wanted to know how to send a message from Simulation to Logging.

 

IMHO, Simulation shouldn't be sending Logging messages at all. Simulation should do one thing- Simulate. It should provide its data to one location, ideally its calling actor. If you want to display the data only, have the "main actor" forward the data on to a GUI. If you want to log it, have the "main actor" send the data to a logger. If you want to average the data and light up an indicator when the data is too high, have the "main actor" send the data to a "thresholding" actor.

 

In general you want each actor to have one responsibility. If you have a "data producing" actor that's trying to send data to a Logger, what do you do if you just want to display the data only? It gets messed up.

 

Have your "main" actor be more of a message dispatcher. This way, if you want to log, it forwards the data to a logger, if you want to display, it forwards it to a GUI. If you want to do both, it forwards the data to both. If you want to do neither (to, say, debug your simulation actor only), then don't send the data anywhere.

0 Kudos
Message 8 of 10
(3,280 Views)

Thank you for your reply. That is so nice. I will have a try

0 Kudos
Message 9 of 10
(3,272 Views)

Thank you for your answer. That is right. Also, in fact, I am doing a project about data aquisition and data processing. Here is the hierarchy. I have to send some parameter configuration from controller to data aquisition and data process actors. So I have the question about sending message to different actor. And the data acquisition and data process hierarchy must be like the picture. So is there any good solution?

图片1.png

0 Kudos
Message 10 of 10
(3,267 Views)