Discovering Objects

Before read this post, you will need to learn the basics.

This post will show you how to discover new objects in your Federation.

When a new object is created by a Federate using rtiamb.registerObjectInstance( classHandle ), all joined Federates that have subscribed to any of its attributes will be notified thru the discoverObjectInstance event of your Federate Ambassador.

You can download the modified Tank Federate from here. I’ve changed a few things:

First, in Main.class ( the Federate itself ) remove ( or comment ) the line 113:

tankClass.updateAttributeValues();

This is because all Tanks, discovered and created by the Federate, will be in same list in TankClass:

private List<TankObject> instances;

Because of two versions of createNew(). So, when I call updateAttributeValues() the Federate will try to update attributes from Tanks that are not owned by itself, raising a “Not owned By” error. If you want to have many Federates creating objects of same class in your Federation, perhaps you may need to create two lists, one for discovered Tanks and other for Tanks created by the own Federate. If so, you must change the methods: createNew() and update() to use the new list.

The other change ( back to Main.class ) is in the method publishAndSubscribe().

private void publishAndSubscribe() throws Exception	{
  tankClass.publish();
  tankClass.subscribe();
}

We must subscribe to the Tank attributes or will not be notified when new Tanks arrives somewhere.

Run two or more instances of the program to see the results. You can see the “Federation already exists” error. Don’t panic! it is normal.

Run Tank Federate 01

Run Tank Federate 01

The Federates will see the Tanks each other.

Run Tank Federate 02

Run Tank Federate 02

 

3 comments

Add Comment