copyright The Portico Project 2008.

org.portico.core.fedex
Class Federation

java.lang.Object
  extended by org.portico.core.fedex.Federation

public class Federation
extends Object

The main representation of a federation within Portico. This class groups together all the relevant components used to provide the federation features. These components are described below.

Messaging and Behaviour

The Federation uses a group of MessageSinks (see the littlebluefrog labs commons project). The Federation class contains all the messaging related components used to process requests from federates and do the general business of the RTI. Requests are processed in three separate "zones":

Threading and Queues

Each federation requires a number of threads to function properly. There are three basic tasks that must be performed within the scope of the federation, and which thread executes them is shown below:

Internally, queues are used as handoff points between the various sinks and processors. The purpose of these queues is outlined below:

Federation State

All federation state is stored in the FederationState object. This includes all the various state-management/altering entities (such as the SyncPointManager and TimeManager). This data is shared between a large number of potential threads, and as such, locking is necessary. Many of the management entities already perform this locking where necessary on behalf of a user. See the javadoc for each component for specific information.

MOM Data

Two entities relating to the MOM are stored in the Federation. The first is an instance of the MomManager that handles all MOM-related requests. The second is a specially created instance of the Federate class that is to represent the actual Mom federate. This is used to interact with incoming HLA-requests at the actual HLA level, and as such, it behaves just like a regular federate with a minor exception. The MOM federate isn't stored in the same place as the other federates that have joined the federation. Rather, this store is kept to be only user created federates. The MOM-federate shouldn't have any bearing on things such as determining whether or not a federation can be destoyed or not (there should be no federates left), and as such, it is kept separate from the other federates.

See the javadoc for the MomManager for more information on MOM behaviour.


Nested Class Summary
private  class Federation.DefaultRequestHandler
          The default handler for messages sent to the request-sink.
 
Field Summary
private  ActionQueueProcessor actionProcessor
           
private  BlockingQueue<com.lbf.commons.messaging.RequestMessage> actionQueue
           
private  com.lbf.commons.messaging.MessageSink actionSink
           
private  Thread actionThread
           
private  CallbackQueueProcessor callbackProcessor
           
private  BlockingQueue<FED_CallbackMessage> callbackQueue
           
private  HashMap<String,Federate> federates
           
static String KEY_FEDERATION
           
private  org.apache.log4j.Logger logger
           
private  Federate momFederate
           
private  MomManager momManager
           
private  String name
           
private  com.lbf.commons.messaging.MessageSink requestSink
           
private  RTIExec rti
           
private  boolean running
           
private  FederationState state
           
 
Constructor Summary
Federation(RTIExec rti, String name, ObjectModel model)
          Create a new federation for the given object model (the model is then passed on to the FederationState where it is stored).
 
Method Summary
 boolean containsFederate(String name)
          Does this federation contain a federate by the given name?
 int federateCount()
          Get a count of the number of joined federates (excludes the mom federate)
 BlockingQueue<com.lbf.commons.messaging.RequestMessage> getActionQueue()
           
 com.lbf.commons.messaging.MessageSink getActionSink()
           
 Set<Federate> getAllFederates()
           
 BlockingQueue<FED_CallbackMessage> getCallbackQueue()
           
 Federate getFederate(int handle)
          Get the joined federate of the given handle.
 Federate getFederate(String name)
          Get the joined federate of the given name.
 org.apache.log4j.Logger getFederationLogger()
           
 MomManager getMomManager()
           
 String getName()
           
 com.lbf.commons.messaging.MessageSink getRequestSink()
           
 RTIExec getRTIExec()
           
 FederationState getState()
           
 void joinFederate(Federate federate)
          Try and add the given federate to this federation.
 Federate resignFederate(String name)
          Remove the joined federate from this federation.
 void shutdown()
          This method will stop the internal processing threads for this federation.
 void startup()
          This method will start the internal processing threads for this federation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_FEDERATION

public static final String KEY_FEDERATION
See Also:
Constant Field Values

rti

private RTIExec rti

name

private String name

federates

private HashMap<String,Federate> federates

running

private boolean running

state

private FederationState state

momManager

private MomManager momManager

momFederate

private Federate momFederate

requestSink

private com.lbf.commons.messaging.MessageSink requestSink

actionSink

private com.lbf.commons.messaging.MessageSink actionSink

actionQueue

private BlockingQueue<com.lbf.commons.messaging.RequestMessage> actionQueue

actionProcessor

private ActionQueueProcessor actionProcessor

actionThread

private Thread actionThread

callbackQueue

private BlockingQueue<FED_CallbackMessage> callbackQueue

callbackProcessor

private CallbackQueueProcessor callbackProcessor

logger

private org.apache.log4j.Logger logger
Constructor Detail

Federation

public Federation(RTIExec rti,
                  String name,
                  ObjectModel model)
           throws JRTIinternalError,
                  JErrorReadingFED
Create a new federation for the given object model (the model is then passed on to the FederationState where it is stored). After construction, the federation still needs to be configured and started (none of the internal threads are active following constuction).

Constructors for this class should never be invoked directly. The FedexFactory should be used to create federations as it will ensure that they are propertly setup and configured.

Throws:
JRTIinternalError
JErrorReadingFED
Method Detail

startup

public void startup()
This method will start the internal processing threads for this federation.


shutdown

public void shutdown()
This method will stop the internal processing threads for this federation. After this call no more callbacks will be sent and no more incoming action-sink messages will be processed.


federateCount

public int federateCount()
Get a count of the number of joined federates (excludes the mom federate)


joinFederate

public void joinFederate(Federate federate)
                  throws JFederateAlreadyExecutionMember
Try and add the given federate to this federation. If successful, it will set the federation property of the federate to this federation.

Parameters:
federate - The federation that wants to join this federation
Throws:
FederateAlreadyExecutionMember - If there is already a federate with the given name that has been joined to this federation
JFederateAlreadyExecutionMember

resignFederate

public Federate resignFederate(String name)
Remove the joined federate from this federation. If the remove is successful, the Federate that was removed will be returned, if not federate of the given name exists to be removed, null will be returned.

Parameters:
name - The name of the federate to remove
Returns:
The federate that was remove, or null

getFederate

public Federate getFederate(String name)
Get the joined federate of the given name.

Parameters:
name - The name of the federate to get
Returns:
The joined federate of the given name or null

getFederate

public Federate getFederate(int handle)
Get the joined federate of the given handle.

Parameters:
handle - The handle of the federate to get
Returns:
The joined federate of the given handle or null

containsFederate

public boolean containsFederate(String name)
Does this federation contain a federate by the given name?


getAllFederates

public Set<Federate> getAllFederates()

getRTIExec

public RTIExec getRTIExec()

getName

public String getName()

getRequestSink

public com.lbf.commons.messaging.MessageSink getRequestSink()

getActionSink

public com.lbf.commons.messaging.MessageSink getActionSink()

getActionQueue

public BlockingQueue<com.lbf.commons.messaging.RequestMessage> getActionQueue()

getCallbackQueue

public BlockingQueue<FED_CallbackMessage> getCallbackQueue()

getState

public FederationState getState()

getFederationLogger

public org.apache.log4j.Logger getFederationLogger()

getMomManager

public MomManager getMomManager()

copyright The Portico Project 2008.