Click here to Skip to main content
15,616,746 members
Articles / Programming Languages / VC++
Posted 25 May 2015

Tagged as


1 bookmarked

HLA Listener

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
25 May 2015CPOL7 min read
An introduction to HLA simulation and HLA Listener



Simulation is the process that tries to imitate the real world inside a virtual environment. It is a cheap process that can be used to test different scenarios without requiring experiment setup or special equipment.

There are many types of simulation; I will talk today about “High-level architecture (HLA)” which is a generic simulation that decomposes the virtual environment into separate components; each component is responsible about a certain task(s) and has an interface to communicate with other components.

HLA borrowed its concept from Object Oriented Programming (OOP); it consists of an application (called Federation) which consists of several objects (called Federates). Like in OOP, each federate perform some tasks and interacts with other federates. However, in distributed simulation each federate might be running on different machine and communicate with each other through a central hub called RTI as shown in the following figure.

Image 1

Figure 1 Federates communicate through RTI

A little bit of history

HLA appeared in mid-90 in military world; but now it is a standardized simulation that regulated and published by IEEE. There are three versions of this standard:

HLA components


RTI is a key component in HLA standards, it creates the federation and provides infrastructure that can be used be federates to communicate with each other. RTI must be fully compliant with the standard by implementing all methods in the java and/or C++ interface ( that is provided by HLA community.

Unfortunately, there is no open source fully-compliant RTI. However, you can get a free version of two commercial RTIs (Pitch RTI, MAK RTI) but it is limited to 2 federates per federation.


The second key component of HLA simulation is a federate. This is a piece of code that references RTI library to send/receive messages with other federates. Because all RTI implement the same interface you can write a code referencing an RTI library and will work with other RTIs by simply change the referenced library.

A federate does not have to be a brand new code; an existing software can be used as federate by writing a small piece of code that transfer data between the existing software and RTI. For example, one can write a plug-in for AutoCAD or Excel etc. to utilize their features in the simulation as will be shown in the Example section.


In order to send/receive messages, federates have to agree on what will be sent (e.g. messages names, data type, etc.). This is done through an XML file called Federation Object Model (FOM) which can be generated by a free software called “simGe” ( HLA community developed a sample FOM for sushi restaurant simulation (

An Example: Traffic simulation

To clarify HLA simulation concept, let’s imagine we are trying to develop a traffic system simulation; the system will be used to investigate the effect of the following parameters:

  • Weather
  • Road width
  • Maximum speed
  • Driver expertise

Once all objectives are defined, we can start defining federates. There are no hard rules to define federates, but intuitively we can say we will have the following federates:

  • Road federate: to outline the roads, schedule road maintenance, etc.
  • Weather federate: to provide weather updates (e.g. precipitation).
  • Traffic controller federate: staff like traffic light.
  • Driver federate: to simulate car movements.
  • Visualizer: to visually display simulation to the end user.

Different teams might be responsible for different federates. Each team can use a different programming language (this is one of the powerful aspects of HLA simulation) to develop their federate. In addition, not all federate have to be written from scratch; for example, for visualizer federate we can tweak existing software (e.g. Unity, or WPF) by developing a plug-in to visualize updates from RTI.

Before developing their federate, all teams have to agree on the federation FOM. FOM is an XML file with two important sections “Object class” & “Interaction class”; These two sections specify what will be published be federates. For instance, we might have an object class “HourlyWeather” with attributes as following:























Also we can have an interaction class “RoadClosure” with an attribute “RoadID”











Note: The complete FOM file can be downloaded from the link in the top.

Please note that the FOM file doesn’t tell which federate will publish/ subscribe object and interaction classes; it just specify what will be published/ subscribed and each federate after joining the federation should inform RTI about what will be published /subscribed. So, in our example after joining the federation the weather federate should inform RIT that it will publish “HourlyWeather” while the driver federate will subscribe to it. Hence; whenever the weather federate sends “HourlyWeather” updates, it will be forward to the driver federate by the RTI. I should mention here that each object / interaction class might have more than one publisher / subscriber.

Note: The federation might have multiple FOMs and RTI will automatically merge them into one file based on certain rules, but this is outside the article scope.

HLA Listener


HLA simulation has a very steep learning curve, it requires a lot of effort to wrap your head around all of its concept. Therefore, I developed a small app called “HLA Listener” for debugging and learning HLA concepts.

HLA Listener is a federate with a GUI, which upon completion will implement all methods in the standard. It can be used to digest all HLA concepts before delving into the code. I can safely say with even my experience in writing federates code, I learned a lot from this tool because it enables me to answer any if-question with few clicks.


HLA Listener is a maven open source project, hosted in github (

In order to use this software, first install any fully compliant RTI (I recommend using Pitch RTI), then run HLA Listener and select the library jar file (Figure 2). After this you will see the main window as shown in Figure 3. It is highly recommended to run two versions of this tool to see how the communication happens through the RTI.

Image 2

Figure 2 First step select HLA library

Image 3

Figure 3 HLA Listener main window


Note: All samples here are extracted from GitHub repository.

Load jar file in the runtime

Because all fully-compliant RTI has to implement the exact same interface, I build my app based on this interface and at runtime the user has to provide the actual implementation that will be added to the class path as following:

private static int AddtoBuildPath(File f) {


        try {

            URI u = f.toURI();

            URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();

            Class<URLClassLoader> urlClass = URLClassLoader.class;

            Method method = urlClass.getDeclaredMethod("addURL", new Class[]{URL.class});


            method.invoke(urlClassLoader, new Object[]{u.toURL()});

        } catch (NoSuchMethodException | SecurityException | IllegalArgumentException |

                InvocationTargetException | MalformedURLException | IllegalAccessException ex) {

            logger.log(Level.FATAL, "Error adding the jar file to the class path", ex);

            return 1;



        return 0;


After that, we have to use “getRtiFactory method to get a pointer to actual RTI implementation (known as RTI ambassador).

URL[] urls = new URL[]{file.toURI().toURL()};

            URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader());

            Class RtiFactoryFactory = Class.forName("hla.rti1516e.RtiFactoryFactory", true, child);

            Method getRtiFactory = RtiFactoryFactory.getMethod("getRtiFactory");

            rtiFactory = (RtiFactory) getRtiFactory.invoke(null);

            rtiAmb = rtiFactory.getRtiAmbassador();

Send to RTI

Once we have a pointer to RTI ambassador we can send request by invoking the corresponding method; the following code connect to RTI, create a federation, and then join the federation

rtiAmb.connect(fedAmb, CallbackModel_choiceBox.getValue());

rtiAmb.createFederationExecution(FederationExecutionName.getText(), foms.toArray(new URL[foms.size()]), LogicalTimeImplementation.getValue());

rtiAmb.joinFederationExecution(FederateType.getText(), FederationExecutionName.getText());

Receive from RTI

The above code shows how to send requests to RTI; in order to receive callbacks from RTI, we have to extend the “NullFederateAmbassador” abstract class and override its methods. The following code writes a message to the console in case of lost connection.

public class ListenerFederateAmb extends NullFederateAmbassador {

//Section 4.4 in standards


    public void connectionLost(String faultDescription) throws FederateInternalError {

           System.out.println("Unfortunately, connection to RTI Lost. Try to reconnect");



Progress so far

So far, I implemented the following chapters in the standard:

  1. Chapter 4: Connect to RTI, Create federation, Join federation, etc.
  2. Chapter 5: publish/subscribe attributes and interaction
  3. Chapter 8: Time management.
  4. Scattered items in the remaining chapters.

What is next?

This is an initiative step to leverage awareness about HLA simulation, which hopefully will lead to develop a free RTI. If you are new to HLA simulation download the code, build it, and teach yourself. If you are familiar with HLA, feel free to give me a hand with implementing the standards.


I tried as much as I can to keep this article concise; therefore, I didn’t discuss much about HLA concepts (e.g. Time management), nor went through the code thoroughly. But if required, I can write a series of articles that explains HLA concepts. I can also provide a step by step tutorial using HLA Listener but I am not sure if this match codeproject theme.


  • May 24, 2015: Initial version
  • May 25, 2015: Expand the article, add sample codes, and resize picture


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Canada Canada
Programming for me is a hobby

Comments and Discussions

QuestionFddObjectmODEL-1.0.0.jar and HLAInterface-1.0.0.jar Pin
Juan Jose Perez20-Oct-16 1:13
Juan Jose Perez20-Oct-16 1:13 
QuestionExcelent post Pin
Carlos Magno Abreu2-Feb-16 15:05
Carlos Magno Abreu2-Feb-16 15:05 
QuestionHLA-1516e jar Pin
saimealey19-Nov-15 2:53
saimealey19-Nov-15 2:53 
AnswerRe: HLA-1516e jar Pin
Mostafa A. Ali20-Nov-15 4:25
professionalMostafa A. Ali20-Nov-15 4:25 
QuestionError when usin MAK RTI Pin
Juan Jose Perez11-Aug-15 9:22
Juan Jose Perez11-Aug-15 9:22 
AnswerRe: Error when usin MAK RTI Pin
Mostafa A. Ali12-Aug-15 2:45
professionalMostafa A. Ali12-Aug-15 2:45 
GeneralRe: Error when usin MAK RTI Pin
Juan Jose Perez14-Aug-15 7:14
Juan Jose Perez14-Aug-15 7:14 
GeneralRe: Error when usin MAK RTI Pin
Mostafa A. Ali15-Aug-15 2:15
professionalMostafa A. Ali15-Aug-15 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.