Chat Example


TOC

  1. Introduction
  2. How to compile
    1. On Unix
    2. On Windows/NT
  3. How to run
    1. On Unix
    2. On Windows/NT
  4. User Interface
  5. Software Design
  6. Changes

1. Introduction

Chat example uses the shared objects (Chatter) to publish its messages to all the connected federates. Each object models the user which has Name and Say attributes. Each federate simulates a Chatter object which has Name and Say attributes.

User interface contains four action buttons:

Connect: joins the federation execution and creates a new object,
Mail: publishes the Say attribute if the federate is joined the execution,
Disconnect: resigns from federation execution, and deletes the object,
Exit: terminates the program. If the federate did not resign yet, it also resigns from the federation execution.

The Main menu contains a name button that allows user to enter its name. This name is used as a federate name during the registration.

Chatter2.xml in $(OWRTI_HOME)/xml directory contains the federation definition. Federates simulate objects to publish their messages to other subscribed federates. Chatter object has two attributes: Name and Say. Each federate simulates a Chatter object and subscribes those attributes of Chatter objects. When a federate needs to send a message (Mail), Say attribute is updated. This update is broadcasted by RTI to all the subscribers. When a new Chatter object is defined in the federation execution, RTI informs all the subscribers. When a defined Chatter object is removed from the execution, then RTI informs all the subscribers.

2. How to compile

JDK1.2 is required.

2.1. On Unix

  1. Makefile contains necessary compile parameters. It includes $(OWRTI_HOME)/mk/config.mk configuration file. This file contains variables for:

    1. Java installation directory (J_HOME),
    2. OWRTI installation directory (OWRTI_HOME), and
    3. JWORB installation directory (JWORB_HOME).

    These variables should be set to the proper directories.

  2. make

    compiles the codes.

2.2. On Windows/NT

  1. Makefile.win contains necessary compile parameters. It includes $(OWRTI_HOME)/mk/config.win configuration file. This file contains variables for:

    1. Java installation directory (J_HOME),
    2. OWRTI installation directory (OWRTI_HOME), and
    3. JWORB installation directory (JWORB_HOME).

    These variables should be set to the proper directories.

  2. nmake /f Makefile.win

    compiles the codes.

3. How to run

3.1. On Unix

  1. Makefile contains necessary parameters. It includes $(OWRTI_HOME)/mk/config.mk configuration file. This file contains variables for:

    1. Java installation directory (J_HOME),
    2. OWRTI installation directory (OWRTI_HOME), and
    3. JWORB installation directory (JWORB_HOME).

    These variables should be set to the proper directories.

  2. Chatter2.xml file is stored in $(OWRTI_HOME)/xml directory. This file should be placed in $(JWORB_HOME)/config directory since the JWORB actually starts up the OWRTI.

  3. kernel.srv file contains machine name and port number pairs. These pairs are used to find a running JWORB server. Therefore, you should add your running JWORB's machine name and port number information into this file. Assume that your JWORB is running on herman.arl.mil port number 3142, then kernel.srv should contain

    herman.arl.mil 3142
    osprey2.npac.syr.edu 4004

    During the runtime, system goes through the entries in order and uses the first JWORB that runs the OWRTI.

  4. runChat

    script starts up the GUI.

3.2. On Windows/NT

  1. Makefile.win contains necessary parameters. It includes $(OWRTI_HOME)/mk/config.win configuration file. This file contains variables for:

    1. Java installation directory (J_HOME),
    2. OWRTI installation directory (OWRTI_HOME), and
    3. JWORB installation directory (JWORB_HOME).

    These variables should be set to the proper directories.

  2. Chatter2.xml file is stored in $(OWRTI_HOME)/xml directory. This file should be placed in $(JWORB_HOME)/config directory since the JWORB actually starts up the OWRTI.

  3. kernel.srv file contains machine name and port number pairs. These pairs are used to find a running JWORB server. Therefore, you should add your running JWORB's machine name and port number information into this file. Assume that your JWORB is running on herman.arl.mil port number 3142, then kernel.srv should contain

    herman.arl.mil 3142
    osprey2.npac.syr.edu 4004

    During the runtime, system goes through the entries in order and uses the first JWORB that runs the OWRTI.

  4. runChat

    script starts up the GUI. (This is a .BAT file).

4. User Interface

Chat program requires that the user enters a name and joins the federation (by clicking Connect button). The user can see, send its messages (by using Mail button) or leaves the federation execution (by clicking Disconnect or Exit). A possible steps can be sumarized as follows:

  1. Select Name from Menu (Figure 2 and 3),
  2. Enter a name, this enables the Connect button (Figure 4),
  3. Click on Connect button to join the session (Figure 5),
  4. Message box is used to type in messages that the user wants to send.
  5. Click on Mail button to send the message (Figure 6).

Figure 1. Initial screen when the user does not enter his/her name.
Figure 2. Name option asks the nameof the user.
Figure 3. User enters his/her name in the pop up window.
Figure 4. User can connect to RTI since name is already provided.
Figure 5. After the connection, a user can send message or disconnect from the session.
Figure 6. A snapshot for the ongoing session.

5. Software Design

It included the following files:

ChatFedAmb.java: Federation Ambassador implementation for Chat.
ChatGUI.java: GUI and logic.
GetName.java: Gets the name.
mainChat.java: starts up the program.
ChatBudy.java: a chat object representing remote user.
EntityManager.java: a manager for chat objects.
SimChatBudy.java: a chat object representing the local user.
Figure 7. UML diagram for the objects in the program.

ChatFedAmb.java is the Federation Ambassador implementation for RTI callbacks. These callbacks are forwarded to EntityManager objects.

EntityManager keeps association between the RTI object id and the object representation (ChatBudy) and updates the corresponding object's state based on the RTI messages. It can define an object, delete an object, and update the attributes of an object.

ChatGUI.java controls the users interaction with the RTI. It contains the following buttons:

  1. Connect
  2. Mail
  3. Disconnect
  4. Exit

and Menu with Name and Exit option.

GUI behaves as a finite state machine with 4 states:

A:Not Connected with no-name
B:Not Connected with name
C:Connected
D:Exit
     State Transitions:
        A --- (enter Name) ---->B
        B --- (click Connect) ---->C
        C --- (click Disconnect) ---->B
        C --- (click Mail) ---->C
        A --- (click Exit) ---->D
        B --- (click Exit) ---->D
        C --- (click Exit) ---->B,D
        A --- (choose Exit in Menu) ---->D
        B --- (choose Exit in Menu) ---->D
        C --- (choose Exit in Menu) ---->B,D

The Name is used as a federation name during the registration process. Therefore, the name should be given first. There is a restriction that in the same federation no two federates can have the same name.

After the Name is specified, Connect button can be used.

Connect button starts the Federation execution and informs RTI that it publishes and subscribes interaction and Chat objects. Also Connect button defines a new SimChatBudy object.

The Middle window is used for displaying messages.

The bottom window is used to enter a message.

The Mail button sends the message in the bottom window.

The Disconnect button deletes the RTI object and resigns from the federation execution.

6. Changes

  1. gif directory is added. (7.2.1999)
  2. Buttons have images. (7.2.1999)
  3. JDK1.2 is in use. (7.2.1999)
  4. makedoc is added (7.2.1999)
===================================================================The End.
Prepared by H. Timucin Ozdemir, July 2, 1999.
E-mail : timucin@npac.syr.edu
===========================================================================