This site uses cookies to bring you the best experience. Find out more
Skip to main content

blog

Part 2 - Our Learning Quest on Actor Framework

Introduction

The last part of this series covered how the Message class is used in the Actor Framework to send messages to actors. Messages directly invoke an actor method and can provide data for the method’s input terminals.

In this part, we will cover how an actor is launched and see how to get the message enqueuers needed to send messages to actors.

Launching a Root Actor

There are two VIs that can launch actors: Launch Root Actor and Launch Nested Actor.  As the names imply, actors can be categorised as being either ‘root’ or ‘nested’. A nested actor is simply an actor that has been launched by another actor, whereas a root actor has not been launched by another actor.

Launch Root Actor is the first VI that would be used in an Actor Framework program. 

The above figure shows what is required to launch your first actor – the actor object is simply wired into Launch Root Actor, where it will launch your actor and return the message enqueuer for your actor, along with any errors that occurred whilst launching your actor.

Note: this VI is non-blocking, so the enqueuer and error are returned whilst the actor is still running.

The enqueuer that is returned from Launch Root Actor can be used to send messages to this actor. The enqueuer terminal returned here is generally only used by the calling program e.g. if you want to start a root actor and then send it messages.

Launching a Nested Actor

Launch Nested Actor is used by a running actor to start another actor. The VI takes the calling actor’s class wire and a class object of the nested actor to launch. If the actor is launched successfully, it returns the nested actor’s enqueuer.

The enqueuer is normally stored in the private data of the calling actor. This allows the calling actor to send messages to this nested actor as required.

Launch Nested Actor registers the nested actor with the caller and gives the nested actor the calling actor’s enqueuer, which can then be used to pass messages from the nested actor up to its calling actor.

Sending Messages

There are three methods of using actor enqueuers to send messages. We have already demonstrated the first; saving message enqueuers returned from the launch VIs for later use.

There are additionally two VIs that can be used to retrieve message enqueuers from an actor’s class wire.

Read Self Enqueuer returns the enqueuer for the wired in actor; it used by an actor to send messages to itself.

Read Caller Enqueuer only works for nested actors, and it retrieves the enqueuer for the actor that launched this actor. The enqueuer is inserted into the nested actor by Launch Nested Actor.

If you summarise these methods, you’ll see the typical architecture for an Actor Framework program, whereby an actor can only send messages to:

  • It’s caller (if it has one!)
  • Itself
  • It’s direct children

This architecture results in a tree of actors, whereby messages traverse the tree. By keeping in this style, it becomes much easier to keep track of, and debug, actor behaviour.

And that wraps up using Actors in AF! 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

ARGENTA IS A LEADING PROVIDER OF PRODUCT RELIABILITY AND PROCESS IMPROVEMENT SOLUTIONS.

Call 0121 514 2290 to discuss your requirements