Studio:AutoScript Messages

From STRIDE Wiki
Revision as of 21:57, 10 July 2008 by Chrisj (talk | contribs)
Jump to navigation Jump to search

STRIDE offers many types of messaging as well as many options on messaging. For ease of understanding, this section describes overall concepts and then describes the precise functionality that STRIDE provides.

Concepts

This section describes overall basic STRIDE concepts related to messaging. Later sections describe how to specifically use STRIDE to facilitate messaging.

Ownership vs. Usage

STRIDE has the concept of a message owner and a message user. In general STRIDE usage the Owner and User imply target and host, but for messaging this meaning is transparent. A message owner may be on the host or the target. A message user may be on the host or target.

User

A message user may be any script that is not registered as the message owner or message override owner.

Owner

The message owner is the script that has successfully registered itself as the owner of the message (by calling the Register method). A message will only have one registered owner. Calls to register a second owner will result in an exception will be thrown. Ownership can be surrendered by calling the Unregister method (or by exiting the script that registered ownership).

Override Owner

The message override owner of a message is the script that successfully registered as the override owner (using the RegisterOverride method). An override owner is used to bypass the registered owner. If a message has an override owner registered, message transfers are sent to the registered override owner and not the registered owner. This allows the ability to code scripting with the registered owner, but to bypass the registered owner for certain processing for a variety of reasons (i.e. some code not implemented for the registered owner, some exception cases, etc.). It is legal for a script to declare both forms of message ownership. Thus the same script may be both registered owner and the registered override owner.

Initiator vs. Handler

For STRIDE, the owner will be the message initiator for all broadcast messages. This means that a user will be the handler for all broadcast messages (that it has subscribed to). Also, the user will be the message intiator for all One-Way or Two-Way messages. The owner will be the message handler for these cases.

Message Payloads

Payloads are Dynamic Objects containing data related to a message. A One-Way Command message may have a Command Payload. A One-Way Response message may have a Response Payload. A Two-Way Message may have both a Command Payload and a Response Payload. The word 'may' is used here because these are the legal conditions of what payloads may exist. For a Command Payload to exist, the captured message must take one or more parameters. For a Response Payload to exist, the captured message must be defined with a response payload.

These payloads are defined as part of both a message user (ascript.Messages.Item().User.Command and ascript.Messages.Item().User.Response) and a message owner (ascript.Messages.Item().Owner.Command and ascript.Messages.Item().Owner.Response). By being part of both user and owner allows their values can be checked for validity in the event that a message didn't make it from user to owner (or visa-versa).

Synchronous / Asynchronous Messaging

Messages that are sent between a message owner and a message user will be either asynchronous or synchronous.

Asynchronous

An asynchronous message is also known as a "non-blocking" message. A message transfers between message owner and message user. The message user initiates a message (using one of the Send methods), the message is sent to the message owner and the message user continues processing. If the message owner is initiating a message transfer (using Broadcast messaging), the message is sent to the message users (that have subscribed to the message) and the message owner continues processing. In either case the message transfer is completed by enqueueing a message event to the message receiver's script queue. The initiator was not blocked from continuing processing.

Synchronous

A synchronous message is also known as a "blocking" message. A message transfer occurs between message owner and message user. If the message user initiates the message, the message is sent to the message owner and the message user waits until it receives a response. If the message owner is initiating the message, it too is blocked until it receives a response from the message user. The initiator of the message is blocked until it receives a response from the handler of the message.

Messaging Types

Broadcast Messaging

Broadcast messaging is the simplest form of asynchronous messaging. All broadcast messages are asynchronous (there is no synchronous form). A message user subscribes to a message. The message owner broadcasts messages. The messages are placed on the message user's event queue. When the message user script is finished listening for messages, the script calls Unsubscribe to cease receiving messages.

One-Way Command Messages

One-Way Command messaging may be either synchronous or asynchronous. One-Way Command messaging means that the message user sent a message command payload to the message owner. The message user did not receive a message response payload from the message owner.

One-Way Response Messages

One-Way Response messaging may be either synchronous or asynchronous. One-Way Response messaging means that the message user expects a message response payload from the message owner. The message owner did not receive a message command payload from the message user.

Two-Way Command/Response Messages

Two-Way messaging may be either synchronous or asynchronous. Two-Way messaging means that the message user sent the message owner a message command payload and expected to receive a message response payload back.




Broadcast Messages

Broadcast messaging is used to have a message owner broadcast messages. A message user will subscribe to a message for a time. The message user will receive messages until the message user's script exits or until it unsubscribes from the message. The exact process for how this is achieved is as follows:

1. A Message User calls Subscribe() to register that it is interested in receiving message events from a given message.
2. When the Message Owner calls Broadcast(), a message event is sent to all Subscribers of the message. The message event received by the Message User is enqueued to its script's event queue. The Message User may then evaluate the messages it has received by making calls to WaitForEvent().
3. When a Message User no longer wishes to receive message events from a given message, it will call Unsubscribe() to unregister its interest in receiving events.

For a broadcast message (a message whose ascript.Messages.Item().Type is "BroadcastMessage"):

  • Its owner (ascript.Messages.Item().Owner) will have a Broadcast method.
  • Its user object (ascript.Messages.Item().User) will have a Subscribe method and an Unsubscribe method.
  • These are the only methods available for this message type. Thus other message methods (e.g. Register/Unregister) will not be available.

Command/Response Messaging

The other form of messaging provided by STRIDE involves direct messaging between a message owner and message user. There are three types of direct messaging between a message owner and message user and they depend upon what information is being passed in which direction.

Message Type
Meaning
One-Way Command Messaging The message user will only send a command payload to the message owner. The message user will not receive any information back from the message owner.
One-Way Response Messaging The message user will only receive a response payload from the message owner. The message owner will not receive any information from the message user.
Two-Way Command/Response Messaging The message user will send a command payload from the message owner AND it will receive a response payload as part of the messaging.

One-Way Command Messaging

One-Way Response Messaging

Two-Way Command/Response Messaging