manager
Class Coupler

java.lang.Object
  extended by manager.Coupler
All Implemented Interfaces:
LogicalTimeListener

public class Coupler
extends java.lang.Object
implements LogicalTimeListener

The coupler class transparently couples the federate to the federation in a controlled manner. The general use for a Coupler is:

  1. Create a federation execution, if succesful then you are leader (boolean)
  2. Create Coupler using boolean from 1 (and some n for num_federates)
  3. Initilalise the coupler
  4. 'Turn on' (in some way) delegation of callbacks to delegation methods
  5. Call finalise
  6. Once finalise returns the federate will be in a federation of exactly n federates all of which will share the same Timestamp value as the fedexid which is retrievable by the call to getFedExId


Constructor Summary
Coupler(boolean isLeader, int numFederates)
          Creates a Coupler with the given details
 
Method Summary
 boolean delegatedDiscover(int id, int classID)
          Delegates a discoverObjectInstance callback to the coupler.
 boolean delegatedReflect(int instID, hla.rti13.java1.ReflectedAttributes attrs)
          Delegates a reflectAttributeValues callback to the coupler.
 boolean delegatedReflect(int instID, ReflectedAttributes13 attrs)
           
 java.sql.Timestamp finalise(double time)
          Finalise the coupling procedure, once this method returns the federate will be coupled to exactly n other federates in a single federation all of whom will share the given fedexid.
 void grantTo(double newTime)
           
 void initialise()
          Sets up the master/slave relationship by ensuring exactly 1 federate has the job of waiting for all federates to join, then sending the fedexid (for logging/debugging) whilst n-1 federates have the job of joining, then listening for the fedexid.
 boolean isCoupled()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Coupler

public Coupler(boolean isLeader,
               int numFederates)
        throws hla.rti13.java1.RTIexception
Creates a Coupler with the given details

Parameters:
isLeader - if the parent federate created the fedex
numFederates - the number of federates which should be coupled to
Throws:
hla.rti13.java1.RTIexception - usually if the .fed file does not contain the correct classes.
Method Detail

initialise

public void initialise()
                throws hla.rti13.java1.RTIexception
Sets up the master/slave relationship by ensuring exactly 1 federate has the job of waiting for all federates to join, then sending the fedexid (for logging/debugging) whilst n-1 federates have the job of joining, then listening for the fedexid. This is done by the leader subscribing to nodeHandle objects and publishing fedexID objects, whilst everyone else does the converse.

Throws:
RTIException - usually if the RTI doesn't support publication/subscription management services, or if the .fed file is not correctly configured with the HLA_RePast admin types:
  • node
    • name
  • fedexID
    • ts
hla.rti13.java1.RTIexception

finalise

public java.sql.Timestamp finalise(double time)
                            throws hla.rti13.java1.RTIexception
Finalise the coupling procedure, once this method returns the federate will be coupled to exactly n other federates in a single federation all of whom will share the given fedexid.

Parameters:
time - the time the federate is currently at (usually 0.0)
Returns:
the fedexid of the federation to which the Federate is now coupled. Useful for logging, distributed debugging, etc.
Throws:
java.lang.Exception
hla.rti13.java1.RTIexception

delegatedDiscover

public boolean delegatedDiscover(int id,
                                 int classID)
Delegates a discoverObjectInstance callback to the coupler. If the callback is involving objects used in the coupling procedure they will be processed (usually moving the finalise method on in some way).

Parameters:
id - the instanceID obtained through the callback
classID - the classID obtained through the callback
Returns:
true if the callback concerned coupling (if not you're in trouble)

delegatedReflect

public boolean delegatedReflect(int instID,
                                hla.rti13.java1.ReflectedAttributes attrs)
                         throws java.lang.Exception
Delegates a reflectAttributeValues callback to the coupler. If the callback is coupler business then it will process the events, moving the finalise method on in some way.

Parameters:
instID - the instanceHandle from the callback
attrs - the values from the callback
Returns:
true if the callback was coupler business
Throws:
java.lang.Exception - usually during de-serialisation or if the attrs object is bad

delegatedReflect

public boolean delegatedReflect(int instID,
                                ReflectedAttributes13 attrs)
                         throws java.lang.Exception
Throws:
java.lang.Exception

grantTo

public void grantTo(double newTime)
Specified by:
grantTo in interface LogicalTimeListener

isCoupled

public boolean isCoupled()