< Previous | Next >

Creating the In Use composite state

The In Use composite state defines the dialing behaviour of the telephone.

In this step, you will do the following:
  1. From the palette, click the composite state icon (The composite state icon) and drop it on the canvas below the other states. A composite state appears like the one shown here.
    The initial Composite state
  2. Rename the composite state to In Use, and add an entry called Initialize with the following code:
    dialedNumber = new String();
  3. In the composite state, rename InitialState2, to In Use Start, and FinalState2 to Too long dialing.
  4. Drop new states into the composite state with the following names:
    • Dial Tone Playing
    • Dialing
    • Connecting
    • Talking
  5. Drop a final state into the composite state called In Use End. Your composite state should look like this image:
    The In Use composite state before the states have been linked up.
  6. Add an entry to the Connecting state called TryToConnect with the following code:
    System.out.println("Connecting...");
  7. Add an entry to the Talking state called Connected with the following code:
    java.lang.String __result__1 = "Connected to ";
    java.lang.String __result__3;
    {// append text
    	__result__3 = __result__1.concat(dialedNumber);
    }
    {// print to log
    	System.out.println(__result__3);
    }
  8. Add an entry to the In Use End state called CallEnded with the following code:
    System.out.println("Call ended...");
  9. Link the states within the composite state as follows:
    1. Link the In Use Start state to the Dial Tone Playing state.
      1. Create an action called PlayDialTone on this transition with this code:
        System.out.println("Playing dial tone.");
    2. Link theDial Tone Playing state to the Dialing state.
      1. Drop the operation called digit onto this transition.
      2. Create an action called AppendDigit with this code:
        java.lang.String __result__2 = digit_Input_digit.getString("digit");
        java.lang.String __result__3;
        {// append text
        	__result__3 = dialedNumber.concat(__result__2);
        }
        dialedNumber = __result__3;
    3. Link theDial Tone Playing state to the Too long dialing state.
      1. Create a timeout called No dialing with a literal duration of 30 seconds.
    4. Link theDialing state to the Too long dialing state.
      1. Create a timeout called Too long dialing with a literal duration of 30 seconds.
    5. Link theDialing state to the Connecting state.
      1. Create a condition called FinishedDialing with the following code:
        int __result__2;
        {// text length
        	__result__2 = dialedNumber.length();
        }
        byte __result__3 = 4;
        boolean __result__4;
        {// equal to
        	__result__4 = __result__2 == __result__3;
        }
        return __result__4;
    6. Create and configure a self transition on the Dialing state. Hover over the Dialing state until a yellow grabber appears. Left-click your mouse to create the beginning of the transition, and then drag the cursor back over the state and click it. A self transition will appear as shown in this image:The Dialing state with a self-transition.
      1. Drop the operation called digit onto this transition.
      2. Create an action called AppendDigit with this code:
        java.lang.String __result__2 = digit_Input_digit.getString("digit");
        java.lang.String __result__3;
        {// append text
        	__result__3 = dialedNumber.concat(__result__2);
        }
        dialedNumber = __result__3;
    7. Link the Connecting state to the Talking state.
      1. Create a condition called NotBusy and configure it as follows:
        1. In the Details tab for the NotBusy condition, click the Invoke radio button.
        2. Similarly, click the Invert result check box.
        3. From the Reference drop down list, select TelcoConnectionService.
        4. From the Operation drop down list, select isBusy.
        5. From the Variables column, click on dialedNumber, click to in the Operation input column, and click Set. Your properties area should look like the one shown in this image:
          The NotBusy condition configuration.
      2. Similarly, create a action called Connect, and configure an invoke for it as follows:
        1. Select the TelcoConnectionService reference and the connect operation.
        2. Link the from operation input to the telephoneNumber variable.
        3. Link the to operation input to the dialedNumber variable.
          The Connect action configuration.
        4. Click the Output parameter radio button, and link the connectOK operation output to the dummyBoolean variable.
    8. Link the Connecting state to the In Use End state.
      1. Create a condition called Busy, and configure an invoke for it as follows:
        1. Select the TelcoConnectionService reference and the isBusy operation.
        2. Link the to operation input to the dialedNumber variable.
          The busy condition configuration.
      2. Create an action called NoConnection with the following code:
        System.out.println("The number was busy.");
    9. Link theTalking state to the In Use End state.
      1. Drop the remoteDisconnect operation onto this transition.
      2. Create an action called NotifyDisconnected with the following code:
        System.out.println("The party you were talking to has disconnected.");
The In Use composite state should look like the one in this image when you are finished:
The final In Use composite state with all of the necessary states and transitions.

Feedback
(C) Copyright IBM Corporation 2005, 2006. All Rights Reserved.
< Previous | Next >