Studio:AutoScript Messages
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.
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.
Message User
A Message User may be any script that is not registered as the message owner or message override owner. The Message User may be access via the message as ascript.Messages.Item.User.
Message 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). The Message Owner may be accessed via ascript.Messages.Item.Owner.
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 properties for both a Message User and a Message Owner. 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 Process
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 constructs a Response Payload.
3. The Message Owner script makes a call to Broadcast() to broadcast its Response Payload.
4. The Response Payload is placed on the event queue of each of its subscribers.
5. The Message User script may retrieve messages from its event queue by calling WaitForEvent().
6. When the Message User script is finished listening for messages, a call to Unsubscribe() is made to cease receiving messages.
Broadcast Messaging Methods
For a broadcast message (a message whose ascript.Messages.Item().Type is "BroadcastMessage"):
- Its Message Owner (ascript.Messages.Item().Owner) will have a Broadcast method.
- Its Message 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.
Point-To-Point Messaging
Point-to-Point messaging refers to messaging where there is a single sender and a single receiver for a message (as opposed to broadcast messaging with multiple receivers). Point-to-Point messages are either Two-Way or One-Way.
Two-Way Messaging
Two-Way Messaging Process
Two-Way Command/Response messaging is synchronous. The process for two-way messages is as follows:
1. The Message User script constructs a Command Payload Dynamic Object.
2. The Message User script makes a call (SendAndRead or SendCmd) to send the Command Payload to the Message Owner script.
3. The Message User script:
3.1. in case of SendAndRead blocks and if the RspTimeoutPeriod is non-zero and the call does not complete in the specified time, an exception is thrown.
3.2. or explicitly would need to read an event from its event queue using WaitForEvent().
4. The Message Owner script processes the Command Payload.
5. The Message Owner script performs some processing.
6. The Message Owner script constructs a Response Payload.
7. The Message Owner script makes a SendRsp call to return its Response Payload.
8. The Message User script receives the Response Payload and processes it.
Two-Way Messaging Methods
For a two-way message (a message whose ascript.Messages.Item().Type is "TwoWayMessage"):
- Its Message Owner (ascript.Messages.Item().Owner) will have a SendRsp method.
- Its Message User object (ascript.Messages.Item().User) will have a SendCmd and SendAndRead methods as well as SendCmdBypassOverride and SendAndReadBypassOverride methods.
- These are the only methods available for this message type. Thus other message methods (e.g. Subscribe) will not be available.
One-Way Messaging
One-Way Messaging Process
One-Way Command messaging is asynchronous. The process for One-Way messages is as follows:
1. The Message User script constructs a Command Payload Dynamic Object.
2. The Message User script makes a call (SendCmd or SendCmdBypass) to send the Command Payload to the Message Owner.
3. The Command Payload is logged onto the event queue for the Message Owner script.
4. The Message User script continues processing.
5. The Message Owner script eventually reads an event from its event queue using WaitForEvent().
6. The Message Owner script formulates a Response Payload.
7. The Message Owner makes a call (SendRsp) to send its Response Payload to the Message User script.
8. The Response Payload is logged onto the event queue for the Message User script.
9. The Message User eventually reads an event from its event queue using WaitForEvent().
One-Way Messaging Methods
For a One-Way Command message (a message whose ascript.Messages.Item().Type is "OneWayMessage"):
- Its Message User (ascript.Messages.Item().User) will have a SendCmd method as well as a SendCmdBypassOverride method.
- These are the only methods available for this message type. Thus other message methods (e.g. Subscribe/SendCmd) will not be available.
For a One-Way Response message (a message whose ascript.Messages.Item().Type is "OneWayResponse"):
- Its Message Owner (ascript.Messages.Item().Owner) will have a SendRsp method.
- These are the only methods available for this message type. Thus other message methods (e.g. Subscribe/SendCmd) will not be available.
Message Methods
The message methods available to a message owner or a message user are based upon the message type. This section describes the methods available for the given message types.
Message Owner Methods
|
Message Type | |||
Method |
One-Way Command |
One-Way Response |
Two-Way |
Broadcast |
Broadcast() | ||||
SendRsp() | ||||
Register() | ||||
RegisterOverride() | ||||
Unregister() | ||||
UnregisterOverride() |
Message User Methods
|
Message Type | |||
Method |
One-Way Command |
One-Way Response |
Two-Way |
Broadcast |
SendAndRead() | ||||
SendAndReadBypassOverride() | ||||
SendCmd() | ||||
SendCmdBypassOverride() | ||||
Subscribe() | ||||
UnSubscribe() |