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:

  1. Create a capsule role
  2. Create ports and bind to protocols
  3. Define a capsule state machine
  4. Define states and substates
  5. Define state transitions
  6. Define attributes on classes

1. Create a capsule role To top of page

Capsules are created in the Logical View of the model browser.

  1. Select the Capsule Role tool in the toolbox.
  2. Place the cursor at the location where the capsule role is to be placed, and left-click.
  3. Select the new capsule role's associated capsule from the drop-down list.
  4. Give the capsule role an appropriate name.
  5. Repeat the above steps for each capsule role to be created.

2. Create ports and bind to protocols To top of page

  1. Find the capsule in the model browser or on a class diagram.
  2. 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.
  3. 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.
  4. Set the name of the port.
  5. Select a protocol from the list, or create a new one.
  6. Right-click on the port to select the Port Specification dialog.
  7. 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.

3. Define a capsule state machine To top of page

  1. Find the capsule in the model browser or on a class diagram.
  2. 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.
  3. Use the State Diagram toolbox to place states and transitions into the state diagram.

4. Define states and substates To top of page

  1. Find the capsule for which the behavior is being updated. Capsules can be found in the model browser or on a class diagram.
  2. Right-click on the capsule to open the State Diagram. This will open the diagram in a State Diagram Editor.
  3. Use the State tool in the toolbox to drop a new state on the diagram. Do this for each state you want to create.
  4. Give each state an appropriate name.
  5. Double-click on a state that will have substates. This will expose a new state diagram on which you may add substates.
  6. 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.

5. Define state transitions To top of page

Add initial transition

  1. 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.
  2. 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

  1. Select the transition tool from the toolbox and draw a transition from the source state to the target state.
  2. 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.

  1. Double-click the transition to open the Transition Specification dialog. 
  2. Select the Trigger tab.
  3. With the cursor in the port list area, right-click and select Insert from the menu.
  4. In the Port area, select the port on which the trigger will be received.
  5. In the Signal area, select the port signal that will cause the trigger event.
  6. 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.

  1. Double-click the transition to open the Transition Specification dialog.
  2. Select the Actions tab to display the code window.
  3. Add the code that will be executed on the transition.
  4. 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.

6. Define attributes on classes To top of page

  1. 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.
  2. Select the Attributes Tab in the Capsule Specification.
  3. With the cursor in the open area of the tab, right-click and select Insert.
  4. Change the name from NewAttribute1 to something more meaningful and then press ENTER.
  5. Double-click on the new attribute to display the Attribute Specification dialog.
  6. Use the Attribute Specification dialog to set the attribute type and initial value.


Rational Unified Process   2003.06.13