HelloWorld 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. Software Design

1. Introduction

HelloWorld is one of the HLA RTI demos. This simple demo simulates the population growth of a given country starting from an initial population with specified number of iterations. The command line option contains the country name, the initial population, and the number of iterations. The order is important.

Each country defines a Country object with Population and Name attributes. In each iteration, the population attribute of the country is published. The growth is calculated based on a linear function. The name of the country is published during the first registration. The simulation also uses interaction class, every 2,3 iterations, it sends a Message interaction so that the Object and Interaction aspects of the HLA is tested.

It is a simple and efficient example to demonstrate the Object Management, Federation Management, Declaration Management, and Time Management features of HLA RTI.

HelloWorld.xml in $(OWRTI_HOME)/xml directory contains the federation definition.

docs directory contains the instructions to run and compile this demo.

jdocs directory contains the javadoc output of the sources. makedoc script produces the javadoc.

2. How to compile

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

When you execute the runHello script, you should get the output given in runHello.out file (it looks as the following).

Script started on Mon Jul 05 13:47:34 1999
osprey7:/owrti/demos/hello% runHello
/usr/npac/jdk1.2.1/bin/java  -Dorg.omg.CORBA.ORBClass=worb.protocols.iiop.ORBImpl -Dorg.omg.CORBA.ORBSingletonClass=worb.protocols.iiop.ORBImpl -classpath /usr/npac/jdk1.2.1/lib/classes.zip:/project/iwt98/oldiwt98/iwt_worb/p/projects/owrti/src:/project/iwt98/oldiwt98/iwt_worb/p/projects/owrti/classes:/project/iwt98/oldiwt98/iwt_worb/p/projects/owrti/classes/owrti.jar:/project/iwt98/oldiwt98/iwt_worb/p/projects/jworb/classes:/project/iwt98/oldiwt98/iwt_worb/p/projects/jworb/classes/jworb.jar:. mainHWorld us 10 3
 query :http://osprey1.npac.syr.edu:4004/servlet/naming?cmd=getIOR&IDL=IDL:npacrti/RTIKernelInterface:1.0
 Version is : RTI Kernel 0.0.1 for spec HLA 1.3

 FED_HW: 
 FED_HW: HelloWorld Event Loop Iteration #: 1 GrantTime : 0.0
 FED_HW: Country[1].name : us ,  Country[1].pop : 10.0

 FED_HW: 
 FED_HW: HelloWorld Event Loop Iteration #: 2 GrantTime : 5.0
 FED_HW: Country[1].name : us ,  Country[1].pop : 12.5

 FED_HW: 
 FED_HW: HelloWorld Event Loop Iteration #: 3 GrantTime : 10.0
 FED_HW: Country[1].name : us ,  Country[1].pop : 15.0
osprey7:/owrti/demos/hello% 
script done on Mon Jul 05 13:47:53 1999

When two country simulation is run concurrently, then each federate receives the attribute update related to other simulated country objects.

 FED_HW: 
 FED_HW: HelloWorld Event Loop Iteration #: 96 GrantTime : 475.0
 FED_HW: Country[2].name : fr ,  Country[2].pop : 1237.5
 FED_HW: Country[1].name : au ,  Country[1].pop : 1237.5

 FED_HW: 
 FED_HW: HelloWorld Event Loop Iteration #: 97 GrantTime : 480.0
 FED_HW: Country[2].name : fr ,  Country[2].pop : 1240.0
 FED_HW: Country[1].name : au ,  Country[1].pop : 1240.0

 FED_HW: 
 FED_HW: HelloWorld Event Loop Iteration #: 98 GrantTime : 485.0
 FED_HW: Country[2].name : fr ,  Country[2].pop : 1242.5
 FED_HW: Country[1].name : au ,  Country[1].pop : 1242.5

 FED_HW: 
 FED_HW: HelloWorld Event Loop Iteration #: 99 GrantTime : 490.0
 FED_HW: Country[2].name : fr ,  Country[2].pop : 1245.0
 FED_HW: Country[1].name : au ,  Country[1].pop : 1245.0

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. HelloWorld.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. runHello: runs one HelloWorld example(for au).
    runHello1: runs one HelloWorld example(for us).
    runHello2: runs one HelloWorld example(for fr).

    runHello1 can be started in one window as runHello2 in another window. If the any one of run* scripts produce 'Permission denied' or 'not command' errors, then run* scripts should be configured as an executable file by using chmod +x, for example;

    chmod +x runHello

    Note that the JWORB server should be running before application of any run* scripts. Two run* script can produce a name clash if they are using the same country name since this name is used during the registration process as a name of the federate.

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. HelloWorld.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. runHello: runs one HelloWorld example(for au).
    runHello1: runs one HelloWorld example(for us).
    runHello2: runs one HelloWorld example(for fr).

    runHello1 can be started in one window as runHello2 in another window. run* scripts are written as .BAT files.

    Note that the JWORB server should be running before application of any run* scripts. Two run* script can produce a name clash if they are using the same country name since this name is used during the registration process as a name of the federate.

4. Software Design

It includes the following files:

HwFederateAmbassador.java: Federation Ambassador implementation for HelloWorld.
HelloWorld.java: RTIambassador interactions and simulation is handled in this file.
mainHWorld.java: starts up the program.
EntityManager.java: a manager for country objects.
Country.java: a country object representing remote user.
SimCountry.java: a country object representing the local user.

Figure 1. UML diagram for the objects in the program.
====================================================================The End.
Prepared by Hasan Timucin Ozdemir, June 23, 1999
E-mail : timucin@npac.syr.edu
===========================================================================