Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Self Addressed Message example

Solved!
Go to solution

Hi everybody,

 

I'm new to the Actor Framework and I'm currently developing my first project with it. I've got to the point where I would like an Actor "B" to send a message to another Actor "A" which is not it's caller, nor I want to let A's enqueuer be an attribute of B's class to establish this link between the two actors. It can look a bit weird, but I have reasons to plan the architecture that way, which I don't think to be relevant at least in the beginning of this discussion.

Anyway, for this kind of need, the Self Addressed Msg class seemed to be useful. But I couldn't find any documentation showing examples on how to use the VIs of this class, and I couldn't find a way to send messages with data using the Send Self Addresed Msg.vi.

I understood how to use this VI to configure a message with the Address Message.vi and later use the Send Self Addresed Msg.vi to send this message and running a VI with no inputs. But is it possible to send data along this self addressed message?

 

Thanks!

Message 1 of 7
(4,960 Views)


I understood how to use this VI to configure a message with the Address Message.vi and later use the Send Self Addresed Msg.vi to send this message and running a VI with no inputs. But is it possible to send data along this self addressed message?



You can create a child class of Self-Addressed Msg.lvclass and add the data required to the payload to the new class.

And make sure, the receiving actor can handle this message Smiley Wink

I guess you are aware, you are increasing the coupling between the Actors/ the Message?

0 Kudos
Message 2 of 7
(4,945 Views)

You can create a child class of Self-Addressed Msg.lvclass and add the data required to the payload to the new class.

Oli_Wachno thanks for your reply. Creating the message as a child of Self Addressed Msg.lvclass was also one of my tries, until I've found something I couldn't understand: this class has already an object of Message.lvclass in its attributes, which obviously can only be written inside the parent, Self Addressed Msg.lvclass. Also this class offers no accessor for this Message.lvclass attribute, and my only access to it is in the Address Message.vi. And as I've seen in the Send Self-Addressed Message.vi the message that gets enqueued for the previously addressed actor is actually this Message.lvclass attribute of Self Addressed Msg.lvclass.

So I suppose that creating the message as a child of the Self Addressed Msg.lvclass would only add payload to a message object that already contains a message that wouldn't have been edited on this case. Is that right? If creating my message as a child of the seld addressed message class actually works, how and where should I implement the Address Message.vi and Send Self-Addressed Message.vi?

 

About coupling the actors, that's something I'm already aware... actually these two actors perform different tasks but they depend strongly on each other.

 

Thanks!

0 Kudos
Message 3 of 7
(4,934 Views)
Solution
Accepted by topic author hbaron93

The Self-Addressed Message, as designed, does not permit you to add data to the message before sending it, so it's not really appropriate for your purposes.

 

This is essentially registration for a publish/subscribe scheme, and I've been thinking about this problem a fair amount recently..  I think the answer involves a variant of the abstract message.  In the simplest form, it would look like this:

 

1.  Create an abstract message for the sending actor.  Include in the messages data:

     a.  any data you want to send with the message

     b.  an actor enqueuer - call it Recipient Enqueuer

2.  After the abstract is created, open the Send VI and:

     a.  delete both enqueuer inputs from Send's front panel

     b.  (on the block diagram) get Recipient Enqueuer from the message's class data and wire it to the Enqueue VI

3.  Add a write accessor for Recipient Enqueuer to the message class

4.  Make a child of this message class for your recipient

5.  Before you launch the sending actor, you will give it the child class you created in step 4.  Before you do that, use the write accessor you made in step 3 to set the recipient enqueuer.

 

When the sender sends its message, you won't wire the enqueuer to the send VI, because it will just use the one in its attributes.

 

This scheme does not fully protect the recipient enqueuer, and it is a little fiddley.  I'm thinking of ways to make it better.  (So far, they involve making a variant of the abstract class template).  You're also hand massaging the classes created by the AF project tools, but I don't really see a way around that.

 

I may post a class template soon.

Message 4 of 7
(4,927 Views)

justACS thanks for the idea! I considered creating an abstract message to solve my problem, but I actually didn't think about modifying that template to achieve that.

In the meantime I thought a bit longer about my problem, and realised that the data that I need to send along that supposed self-addressed message was actually constant. In detail: I said in the beginning of the discussion that I had the Actor A and two instances of Actor B launched. The content of the self-addressed message that I needed to send from each B to A was the enqueuer reference from each Actor B.

So the solution that I adopted (since I needed to pass data, but it wouldn't change during the entire execution of the application) was the following:

  1. Create an attribute in the sending actor class of the type Self-Addressed Message.lvclass with a public accessor to write it.
  2. Create a normal message in the receiver actor, containing that desired "constant data" (e.g. the Enqueuer reference)
  3. Create a public Configure <message name>.vi inside that class, that receives as inputs the Recipient Enqueuer, the desired data and the message priority. This VI actually writes the data in the message class and calls the Address Message.vi. The created Self-Addressed Message is the output of this configuration VI. As shown in the snippet below (actually the object where the broken wire comes from is a constant object of the created message class.
  4. Use the public accessor created in step 1 no write this Self-Addressed Message object in the sending actor attributes.
  5. When the sending actor needs to send the message, it calls the Send Self-Addressed Message.vi giving this attribute as the input.

From my little experience with the AF, I can't say if that's an smart solution or not, but it seems to solve my problem without much customization of the templates, taking as advantage the constant behavior of my message data.

 

Best regards

 

Configuration VI.png

0 Kudos
Message 5 of 7
(4,906 Views)

Can I get more details on what "Self-Addressed" means? I'm thinking like "self-addressed" envelope where the recipient knows where to send any response, but I don't see the sending actor's enqueuer being used anywhere in the process of sending this message (as in Send Message and Wait for Response).

0 Kudos
Message 6 of 7
(4,762 Views)

Never mind, the "Send Message and Wait for Response" reply comes back to the sender on an unnamed queue.

0 Kudos
Message 7 of 7
(4,747 Views)