Studio:AutoScript Messages: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
No edit summary
Line 52: Line 52:
Broadcast messaging is the simplest form of asynchronous messaging. All broadcast messages are asynchronous (there is no synchronous form). The process for broadcast messages is as follows:
Broadcast messaging is the simplest form of asynchronous messaging. All broadcast messages are asynchronous (there is no synchronous form). The process for broadcast messages is as follows:


1. A Message User script makes a call to subscribe to a message. <br>
1. A Message User script makes a call to subscribe() to listen for messages. <br>
2. The Message Owner script makes a call to broadcast a message (or messages) with a Response Payload. <br>
2. The Message Owner script makes a Response Payload to be broadcast to its listeners.<br>
2. The Message Owner script makes a call to Broadcast() to broadcast its Response Payload. <br>
3. The Response Payload is placed on the Message User script's event queue.  <br>
3. The Response Payload is placed on the Message User script's event queue.  <br>
4. When the Message User script is finished listening for messages, the script calls Unsubscribe to cease receiving messages.<br>
4. The Message User script may retrieve messages from its event queue by calling WaitForEvent().<br>
5. The Message User may process messages by processing events from its event queue.<br>
5. When the Message User script is finished listening for messages, a call to Unsubscribe() is made to cease receiving messages.<br>
<br>
<br>



Revision as of 00:14, 11 July 2008

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.

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. This is the type of messaging that occurs for Broadcast messaging, One-Way Command messaging, and One-Way Response messaging. For asynchronous messaging: 1. The initiator script of the action makes a call to transfer a payload (either a command or response).
2. The payload is logged onto the receiving script's event queue.
3. The initiator script continues processing.
4. Later the receiving script makes a call to WaitForEvent to processing the payload.

The initiator script was not blocked from continuing processing.

Synchronous

A synchronous message is also known as a "blocking" message. Only a two-way message is synchronous for STRIDE. For synchronous messaging: 1. The initiator script makes a call to transfer a command payload.
2. The initiator script then waits until the receiving script provides a response (perhaps with a response payload).

The initiator script was blocked from continuing processing until the receiving script responded.

Messaging Types

Broadcast Messaging

Broadcast messaging is the simplest form of asynchronous messaging. All broadcast messages are asynchronous (there is no synchronous form). The process for broadcast messages is as follows:

1. A Message User script makes a call to subscribe() to listen for messages.
2. The Message Owner script makes a Response Payload to be broadcast to its listeners.
2. The Message Owner script makes a call to Broadcast() to broadcast its Response Payload.
3. The Response Payload is placed on the Message User script's event queue.
4. The Message User script may retrieve messages from its event queue by calling WaitForEvent().
5. When the Message User script is finished listening for messages, a call to Unsubscribe() is made to cease receiving messages.

Two-Way Messaging

Two-Way Command/Response messaging is synchronous. The process for two-way messages is as follows:
1. The Message User makes a Command Payload. 2. The Message User makes a call to send the Command Payload to the Message Owner.
3. The Message User waits until the Message Owner responds to the request with a Response Payload.

One-Way Messaging

One-Way Command messaging is asynchronous. The process for One-Way messages is as follows:
1. The Message User makes a call to send a Command Payload to the Message Owner.
2. The Command Payload is logged onto the event queue for the Message Owner.
3. The Message User continues processing.
4. The Message Owner eventually reads an event from its event queue.
5. The Message Owner script formulates a Response Payload.
6. The Message Owner makes a call to sent a Response Payload to the Message User.
7. The Response Payload is logged onto the event queue for the Message User.
8. The Message User eventually reads an event from its event queue.

Broadcast Messages

Broadcast messaging is used to have a message owner broadcast messages. A number of message users 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 its WaitForEvent() method.
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.

Two-Way Command/Response Messaging

Two-Way messaging is as follows:

1. A Message User calls SendAndRead (or SendAndReadBypassOverride) to synchronously connect with the Message Owner.
2. The Message owner sets a response payload and calls SendRsp.

One-Way Command/Response Messaging

One-Way messaging is as follows:

1. A Message User script calls SendCmd (or SendCmdBypassOverride) to log a Command Payload to the event queue of the Message Owner. The Message User script then continues processing.
2. The Message Owner script eventually decides to look in its event queue (using WaitForEvent()) and sees that it has a message Command Payload to be processed.
3. The Message Owner script later decides that it wants to send a Response Payload back to the Message User. It calls SendRsp to send log a Response Payload to the event queue of the Message User. The Message Owner then continues processing.
4. The Message User later makes a call to its WaitForEvent() method and sees that it has a message Response Payload to be processed.