Tool Mentor: Designing
with Active Objects in Rational Rose RealTime
Purpose
This tool mentor describes the components of active objects and explains how
to design with active objects in Rational Rose RealTime.
This section provides links to additional information related to this tool mentor.
Overview
An active object consists of capsules with protocols and ports.
Capsules are highly encapsulated objects using message-based communication
to other capsules through their port objects. Capsules can aggregate other capsules.
A capsule structure can contain other capsules, which are capsule roles.
The set of messages exchanged between two objects conforms to a communication
pattern called a protocol. It is basically a contractual agreement defining
the valid types of messages that can be exchanged between the participants in
the protocol.
A state diagram is one way to define object behavior. It shows the sequence
of states that an object or an interaction goes through during its life in response
to messages received, together with its responses and actions.
Tool Steps
To design with active objects in Rational Rose RealTime, perform these steps:
- Create a capsule role
- Create ports and bind to protocols
- Define a capsule state machine
- Define states and substates
- Define state transitions
- Define attributes on classes
Capsules are created in the Logical View of the model browser.
- Select the Capsule Role tool in the toolbox.
- Place the cursor at the location where the capsule role is to be placed,
and left-click.
- Select the new capsule role's associated capsule from the drop-down list.
- Give the capsule role an appropriate name.
- Repeat the above steps for each capsule role to be created.
- Find the capsule in the model browser or on a class diagram.
- Expand the elements under the capsule in the browser, or right-click on
the capsule in a class diagram to open the capsule's structure diagram.
- Use the Port tool in the toolbox to place a port on the capsule's
structure diagram. The port may be dropped onto the capsule's border or inside
the large rectangle area.
- Set the name of the port.
- Select a protocol from the list, or create a new one.
- Right-click on the port to select the Port Specification dialog.
- Use the Port Specification dialog to change the protocol, to select whether
the port is wired or unwired, and to set whether the port is conjugated.
- Find the capsule in the model browser or on a class diagram.
- Expand the elements under the capsule in the browser, or right-click on
the capsule in a class diagram to open the capsule's state diagram.
- Use the State Diagram toolbox to place states and transitions into
the state diagram.
- Find the capsule for which the behavior is being updated. Capsules can be
found in the model browser or on a class diagram.
- Right-click on the capsule to open the State Diagram. This will open the
diagram in a State Diagram Editor.
- Use the State tool in the toolbox to drop a new state on the diagram.
Do this for each state you want to create.
- Give each state an appropriate name.
- Double-click on a state that will have substates. This will expose a new
state diagram on which you may add substates.
- Use the tab at the bottom of the window to choose which state level to navigate
back to.
Note: Alternatively, you can add states through the Navigator area of
the State Diagram Editor.
Add initial transition
- Click on the initial point in the diagram and drag the transition on top
of the target state. The initial point is the black circle that appears in
the top-left corner of the diagram.
- Give the transition an appropriate name, if not the default. The initial
transition has a default name of Initial. You can change the name by selecting
the label and typing it in. The initial transition will be automatically invoked
at run-time when a capsule instance is created. Any action code associated
with the initial transition will be run as soon as the capsule instance is
created.
Add transitions
- Select the transition tool from the toolbox and draw a transition from the
source state to the target state.
- Give the transition an appropriate name, or accept the default.
Adding detail code to state machines
C, C++, or Java code can be added as actions on transitions, choice points,
and state entry or exit on capsule state diagrams to be executed at run-time.
Only code added to capsule state diagrams is included in the generated code
for the model. Detailed actions on protocol or data class state diagrams are
not included in the generated code for those classes.
Add triggers
Before a trigger can be set for a transition, the port on which the trigger
will be received must be defined.
- Double-click the transition to open the Transition Specification dialog.
- Select the Trigger tab.
- With the cursor in the port list area, right-click and select Insert
from the menu.
- In the Port area, select the port on which the trigger will be received.
- In the Signal area, select the port signal that will cause the trigger event.
- Click on the OK buttons to close the open dialogs.
Add code to transition
Now that you have all the required elements in place (initial state, initial
transition, and ports), you must add detail code to the initial transition,
as well as state to state transitions. The detail code will be executed when
the initial transition is run at model execution time, or when a trigger is
received on the state to state transition.
- Double-click the transition to open the Transition Specification dialog.
- Select the Actions tab to display the code window.
- Add the code that will be executed on the transition.
- Select the OK button to close the open dialog.
Note: You don't have to include opening and closing curly braces '{`,
`}'. These are added automatically by the code generator.
- Open the Capsule Specification dialog box by double-clicking on the capsule
in the browser, or by selecting the capsule in a diagram and selecting Open
Specification from the context menu.
- Select the Attributes Tab in the Capsule Specification.
- With the cursor in the open area of the tab, right-click and select Insert.
- Change the name from NewAttribute1 to something more meaningful and then
press ENTER.
- Double-click on the new attribute to display the Attribute Specification
dialog.
- Use the Attribute Specification dialog to set the attribute type and initial
value.
|