Starting your first Portico Federation

This topic I will show how to start a Federation. First of all, you will need a valid FOM file.  You can use the HLAstandardMIM.xml for now.

Take the RTI Ambassador:

RTIambassador rtiamb = RtiFactoryFactory.getRtiFactory().getRtiAmbassador();

Next step is connect to the RTI. You will need a class extending “NullFederateAmbassador” and implementing all needed methods. In this case, I have “MyFederateAmbassador”.

public class MyFederateAmbassador extends NullFederateAmbassador {
 // Override your methods here. Explain later
MyFederateAmbassador fedamb = new MyFederateAmbassador();
rtiamb.connect( fedamb, CallbackModel.HLA_IMMEDIATE );

Callback model can be  “HLA_IMMEDIATE” and “HLA_EVOKED”.   Using  “HLA_IMMEDIATE” will tell the RTI to send callbacks to your Federate Ambassador as soon as possible, while using “HLA_EVOKED” you will need to call “evokeMultipleCallbacks()”. I’m using “HLA_EVOKED” when my Federation is Time Constrained ( rtiamb.enableTimeConstrained() ).

Now, you will need to pass the FOM file and create the Federation. If this Federation (same name) is already running, an error will raise. You can just ignore it since is not so bad.

try {
  URL[] modules = new URL[]{
    (new File( "/path/to/HLAstandardMIM.xml") ).toURI().toURL()
  rtiamb.createFederationExecution("MyFederationName", modules );
} catch( FederationExecutionAlreadyExists exists ) {
  logger.debug("Federation already exists. Bypassing...");

It’s time to join your Federate to the Federation. You will need a SOM file now. You can use one or more SOM files just adding them to the URL[] list.

URL[] joinModules = new URL[]{
    (new File("/path/to/MySOMFile.xml")).toURI().toURL()
rtiamb.joinFederationExecution( "MyFederateName","MyFederateType", 
                                "MyFederationName", joinModules );

The name of Federation (MyFederationName) must be the same name used in “createFederationExecution()”.

Congratulations! You have a running Federation. You can call RTI methods by using the RTIAmbassador ( rtiamb ) and the RTI will tell you anything by evoking callback methods in your Federate Ambassador ( fedamb ).

For now, nothing will happen because you have not published nor subscribed to any class, attribute change or interaction.




Add Comment