Getting Started With Portico Java

This article will give you just the bare essentials required to get a federate up and running with Portico. If you need to know how to download and install Portico (or how to start the Portico server) see the Installing Portico guide. Please note that this is not a guide on how to use the HLA. We assume that you already have some HLA experience and are just wanting to get started with Portico.

Writing Federates for Portico
Writing federates for Portico is basically the same as writing federates for any other RTI. All the standard interfaces and types are provided, in addition to an implementation of the Dynamic Link Compatibility (DLC) API. There are a some cases in which Portico specific details must be referenced or provided, but the only situations that would tie your code to Portico (that is, require recompilation to get working with another RTI) are due to limitations in the standards themselves. These issues are clearly marked.

So, with that out of the way, let's look at some basic code that creates, joins, resigns from and destroys a federation. This code provides all the necessary details required to get up and running with Portico. Beyond what is provided below, it is just a matter of making use of the standard interfaces and types. For a copy of the sample code that uses the IEEE 1516 interface, see the HLA1516 Example Federate article.

Sample Code
 import hla.rti.jlc.NullFederateAmbassador; import hla.rti.jlc.RtiFactory; import hla.rti.jlc.RtiFactoryFactory; import hla.rti.FederateAmbassador; import hla.rti.ResignAction; import hla.rti.RTIambassador;

import java.io.File;

public class ExampleFederate {   public void runFederate throws Exception {       //////////////////////////////        // 1. get a link to the RTI // //////////////////////////////       RtiFactory factory = RtiFactoryFactory.getRtiFactory; RTIambassador rti = factory.createRtiAmbassador;

////////////////////////////       // 2. create a federation // ////////////////////////////       File fom = new File( "testfom.fed" ); rti.createFederationExecution( "exampleFederation", fom.toURL ); ////////////////////////////       // 3. join the federation // ////////////////////////////       FederateAmbassador fedamb = new MyFederateAmbassador; rti.joinFederationExecution( "myFederate", "exampleFederation", fedamb ); ///////////////////////////////       // 4. resign from federation // ///////////////////////////////       rti.resignFederationExecution( ResignAction.DELETE_OBJECTS ); /////////////////////////////       // 5. destroy a federation // /////////////////////////////       rti.destroyFederationExecution( "exampleFederation" ); }   public static void main( String[] args ) throws Exception {       new ExampleFederate.runFederate; }   private class MyFederateAmbassador extends NullFederateAmbassador {   } }

The DLC
The DLC API allows a developer to create a new RTI ambassador without needing to know the exact implementation type. Through the  you can get a reference to a vendor-specific implementation of the , and through this you can create new  s.

The Problem With Time
While the DLC is meant to abstract away RTI-implementation specific details, when it comes to the issue of logical time, for some reason the standards board has decided not to act. There is no way to obtain an instance of the LogicalTime implementation required by the interface specification without making direct use of vendor-specific classes. While this problem is not addressed by the DLC, it isn't a DLC-specific issue. Rather, it is just a problem inherited from the actual HLA specification itself.

When using time, you will need to reference Portico specific types. The following example shows how you might do this when requesting a time advance:

 rti.timeAdvanceRequest( new org.portico.shared.types.hla13.DoubleTime(100.7) );

The above code attempts to advance logical time to 100.7. You must create the Portico-specific type (thus breaking link compatibility) and pass it to the time advance request. There is a corresponding type for time intervals in the form of org.portico.shared.types.hla13.DoubleTimeInterval.

Compiling Federates with Portico
To compile a federate with Portico, just make sure you include the  file on your classpath:

javac -cp $RTI_HOME/lib/portico.jar *.java

Running Federates With Portico
Now that we've written and compiled our example federate, it's time to run it. For this example, we will assume that the code has no package and has been stored in the mycode directory.

[tim@moby mycode]$ vim ExampleFederate.java

[tim@moby mycode]$ javac -cp $RTI_HOME/lib/portico.jar ExampleFederate.java

[tim@moby mycode]$ java -cp ./:$RTI_HOME/lib/portico.jar ExampleFederate

Since we've got no logging in our federate, the fact that it exits without error is an indication of success. If you want to see some action, you can turn up logging through The RID File. Just place a file called "RTI.RID" in the directory you are executing the federate from and make sure it has the following line in it:

portico.loglevel=DEBUG

Where Next?
From this point on, you should be able to make use of standard the standard HLA interfaces and types (from the hla.rti package) to get the functionality you require. Larger example federates are shipped with Portico, for more information in them, see Example Federates Using Portico.

If you need more help regarding Portico, see Support.