Class and Attribute handles

Now you have started a Federation and joined a Federate, its time to take the handles of classes and attributes concerning to your Federate.

Lets take a look on this object class in a SOM file:

  <objects>
      <objectClass>
          <name>HLAobjectRoot</name>
    
          <objectClass>
              <name>Core</name>
              <sharing>PublishSubscribe</sharing>
              <semantics>A Computer Processor Core Representation</semantics>
              <attribute>
                  <name>OwnerNode</name>
                  <dataType>HLAunicodeString</dataType>
                  <updateType>Static</updateType>
                  <updateCondition>NA</updateCondition>
                  <ownership>NoTransfer</ownership>
                  <sharing>PublishSubscribe</sharing>
                  <dimensions/>
                  <transportation>HLAreliable</transportation>
                  <order>Receive</order>
                  <semantics>Owner Computer's MAC Address</semantics>
              </attribute>
      
              <attribute>
                  <name>SerialNumber</name>
                  <dataType>HLAunicodeString</dataType>
                  <updateType>Static</updateType>
                  <updateCondition>NA</updateCondition>
                  <ownership>NoTransfer</ownership>
                  <sharing>PublishSubscribe</sharing>
                  <dimensions/>
                  <transportation>HLAreliable</transportation>
                  <order>Receive</order>
                  <semantics>Serial number of the node</semantics>
              </attribute>
    </objectClass>
  </objectClass>
<objects>

You can see a class called “Core” and two attributes: “OwnerNode” and “SerialNumber”. The RTI knows nothing about objects! So you can’t take the handle for the entire “Core” class and its attributes. This is because the owner of this class may not puplished all of them or you may not want to subscribe to receive all of attributes changes.

You’ll take the handle of each one individually.  Here I’ll supose you’re already connected to the RTI and have a RTIAmbassador object ( rtiamb ). If don’t, please go to Starting your first Portico Federation post.

ObjectClassHandle classHandle = rtiamb.getObjectClassHandle( "HLAobjectRoot.Core" );

To avoid naming conflicts, aways refer to elements by using its fully qualified names ( in this case, the Core class have HLAobjectRoot as parent ). Now you can take the handles of Core attributes.

AttributeHandle serialNumberHandle = rtiamb.getAttributeHandle( classHandle, "SerialNumber" );
AttributeHandle ownerNodeHandle = rtiamb.getAttributeHandle( classHandle, "OwnerNode" );

I like to create a Java Class to represent this class. It will hold all class handles for future use, but it is not a rule. Note I’m talking about classes, no objects exists yet!

public class CoreClass {
  private RTIambassador rtiamb;
  private ObjectClassHandle classHandle;
  private AttributeHandle ownerNodeHandle;
  private AttributeHandle serialNumberHandle;
  
  private List<CoreObject> objects; // Just ignore this for now. Will cover it later.
  
  public void takeHandles() {
      this.classHandle = rtiamb.getObjectClassHandle( "HLAobjectRoot.Core" );
      this.serialNumberHandle = rtiamb.getAttributeHandle( classHandle, "SerialNumber" );
      this.ownerNodeHandle = rtiamb.getAttributeHandle( classHandle, "OwnerNode" );    
  }
  
  ...

}

You can publish the attributes you want to other Federates receive updates…

AttributeHandleSet attributes = rtiamb.getAttributeHandleSetFactory().create();
attributes.add( serialNumberHandle );
attributes.add( ownerNodeHandle );
rtiamb.publishObjectClassAttributes( classHandle, attributes );

…or subscribe to receive updates from it.

AttributeHandleSet attributes = rtiamb.getAttributeHandleSetFactory().create();
attributes.add( serialNumberHandle );
attributes.add( ownerNodeHandle );
rtiamb.subscribeObjectClassAttributes( classHandle, attributes );

Now you’re able to exchange data!

 

Add Comment