Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Batch Messaging

Solved!
Go to solution

I would like to use the Batch Message functionality that accompanies the Actor Framework. I am concerned by the fact that when an array of objects is created, all messages are effectively cast up to generic message objects. Does this imply that any data accompanying the message will be lost? I have not yet gotten to a stage where I can test this with my code, but I thought I'd ask since I haven't seen anything on this Community Discussion about using the Send Batch VI.

M

0 Kudos
Message 1 of 6
(4,284 Views)

When programming in LVOOP, it's important to remember that the data type of the wire (class) is not necessarily the same as the data type of the object that gets put on that wire at run-time. You can put any number of child objects onto a parent class wire. So when you make an array of disparate (i.e. sibling) objects like AF messages, that array has to be cast up to the most generic type that commonly represents all of them: Message.lvclass.

When you want to access a message's data use the "To More Specific Class" primitive to cast it down from the parent type to the child type. This primitive doesn't change the data that will actually be in memory; it just tells the compiler, "This object is actually an instance of SpecificMessage.lvclass, so it's okay to give me access to the methods exposed by that class."

0 Kudos
Message 2 of 6
(3,565 Views)

Thanks for your reply, David.

If I'm understanding what you're saying, the type that LV tells me the wire is while in Edit Mode is the most generic class that the two classes have in common. At run-time, LV must automatically downcast them (or simply retains knowledge of their original classes) for use with the Send Batch VI. Since there's no way to know apriori what messages are going to be in any given batch, there's no way to use the "To More Specific Class" to ensure that each message type that gets written to the array maintains its type (and private data). If this is not the case, the Send Batch VI would only really be useful for messages that don't contain any data, which would be an unfortunate limitation.

Am I understanding correctly?

0 Kudos
Message 3 of 6
(3,565 Views)
Solution
Accepted by topic author munsmat

Casting objects in LV is merely the act of telling the compiler (at edit-time) that you want to treat the object as a specific type. Since objects can be treated as the type of any class in their heirarchy, you can use the casting primitives to tell the compiler which type you want to treat an object as right now. (There's some actual data copying done in certain wiring patterns with the "To More Specific Class"...look inside the AF example project to see how to handle that.) So every element in an array of objects retains its real type and data when it's put into an array. The compiler just needs to tell itself that the object is some more abstract type because of the rules governing what an "array" is.

As for the Send Batch VI, you can give it an array of messages and implement Do.vi (or Do Core.vi...I'm not looking at LV right now) on each one, and each message's implementation will be executed on that message. This is the Command Pattern. If your message each define properties (private data) that you want to use in your Do.vi, write to those properties on each object before putting them in an array.

0 Kudos
Message 4 of 6
(3,565 Views)

David's answer is correct. To answer your direct question: When you batch up messages, don't worry... each message retains its specific data and will dispatch to its specific Do.vi. It would be pretty useless if it didn't. 😉  This works because of the fundamentals of OO programming, not because of anything special that the AF is doing.

Message 5 of 6
(3,565 Views)

Thanks for the quick replies. I'll go back through the OO Fundamentals to refresh myself on the nuances of bundling objects in arrays.

0 Kudos
Message 6 of 6
(3,565 Views)