Part 1 - Our Learning Quest on Actor Framework
06 May 2024
Introduction
We have been using Actor Framework (AF) consistently for about a year, and as with every learning experience there have been some ups and downs! We wanted to share what we saw to be some of the key areas of learning and give you some hints and tips along with some holes we fell down! If you are completely unfamiliar with AF, check out this post where we do a quick introduction and link to some useful resources to pick up the basics.
Before getting into the details of how actors can be used in a project, this article will cover how messaging works in the AF. One key thing to remember with AF messages is that they are classes which inherit from the Actor Framework class, Message.
![](/_userfiles/pages/images/af_messaging_pic_1.png)
Creating a Message
Imagine you have an actor that has a method Some Function. In this example, Some Function has two inputs, foo and bar. This method simply updates our actor’s private data with the latest values for foo and bar.
![](/_userfiles/pages/images/af_messaging_pic_2.png)
Now, we can call some Some Function as normal on the block diagram of our actor – maybe we want to update foo and bar after completing some other task. But what if we want to update foo and bar in some process that is external to our actor e.g. another actor?
To do this, we can create an Actor Framework message which can then be used in other areas of our code. Thankfully, the Actor Framework provides a scripting method to create a message through the right click menu.
![](/_userfiles/pages/images/af_messaging_pic_3.png)
This script then creates our message – a class with two methods, Send Some Function and Do.
![](/_userfiles/pages/images/af_messaging_pic_4.png)
The send method, Send Some Function, can then be used to send foo and bar from outside the actor.
![](/_userfiles/pages/images/af_messaging_pic_5.png)
Note that this send method does not expose the actor’s class wires, meaning that we do not need access to the actor’s class object in order to send it a message - all we need is the actor’s enqueuer. (Actor enqueuers will be covered in the next part of the series!)
What is in a Message?
If we look inside the send method, we can see what’s happening to foo and bar.
![](/_userfiles/pages/images/af_messaging_pic_6.png)
The send method has been created, where foo and bar are being inserted into the message’s private data. If we look in the class private data for the message, we can indeed see that this message class has been configured with the data we want to send.
![](/_userfiles/pages/images/af_messaging_pic_7.png)
This then means arbitrary data can be sent through the Actor Framework messaging system by sending configured class objects to an actor’s queue, which is addressed by the Message Enqueuer passed to Send Some Function.
When the message is dequeued at the actor, it is sent to the Actor Framework’s Message class method Do and this is where the magic happens!
Do.vi
The Do method is a dynamically dispatched method that is designed to be overridden by the Do method in your message class. The base implementation doesn’t actually do anything:
![](/_userfiles/pages/images/af_messaging_pic_8.png)
![](/_userfiles/pages/images/af_messaging_pic_9.png)
Notice that Do has an input terminal for the incoming message object; this is a dynamic input, meaning that your message will override this method and performs its own Do method. It also has terminals for the actor’s class wire; this allows the message to interact with the actor’s private data.
![](/_userfiles/pages/images/af_messaging_pic_10.png)
The above image is the block diagram for the Do method in our Some Function Msg class. This was automatically generated with the rest of the message. Notice here that the data we stored in the Send Some Function method is now unbundled and wired into Some Function.
This behaviour turns Do into a dynamic wrapper for any of the functions contained within the actor, which allows methods to be directly called with messages.
And that's messages folks! If you have any questions about this or want to discuss this in a bit more detail, we are always keen to chat, so get in touch!
Back to Blog listings