faa.tg.hla.aircraft
Class HlaAircraftMonitor

java.lang.Object
  extended by faa.tg.hla.aircraft.HlaAircraftMonitor

public class HlaAircraftMonitor
extends java.lang.Object

 This object demonstrates how a Federate can attach to the TgfFed
 Federation Execution. 

 It attaches to the rtiexec; registering for TgfHlaAircraft objects.
 Upon succesffuly doing so it makes copies of those aircraft and
 reflects changes the RTI makes to them within it's copied list.
 When the rti 'ticks' this information is then displayed to 
 standard output.

 Originally this object was written for testing purposes only, however
 the need has arisen to possibly have this tool used for greater
 monitoring purposes.  Expect future changes to incorporate a GUI,
 and allow for data access/query in a user-friendly way. 
 
See the source: HlaAircraftMonitor

Version:
$Id: HlaAircraftMonitor.java,v 3.1 2006/03/14 15:56:56 samf Exp $
Author:
Timothy Swantek

Field Summary
 TgfHlaHandleIDs attributeHandles
          This is a list of handles (IDs) mapped to specific TgfHlaAircraft variables defined in the TgfFed.fed file.
static java.lang.String CVS_VERSION_ID
          The CVS Version ID
private  TgfMonitorFedAmb fedAmbassador
          The TgfMonitorFedAmb is a FederateAmbassador.
private  java.lang.String federateName
          The name of this federate.
private static java.lang.String FEDERATION_EXECUTION_DATA
          The name of the federation execution file to use.
private static java.lang.String FEDERATION_EXECUTION_NAME
          The name of the federation execution to join.
private  TgfHlaAircraftList monitoredAircraft
          A list of all the currently monitored aircraft.
(package private)  boolean resigning
          A flag used to help us exit the federation politely.
private  hla.rti.RTIambassador rtiAmbassador
          The RTIambassador is the data bus used to convey messages from the federate to the RTI.
 
Constructor Summary
HlaAircraftMonitor()
          Constructs a new HlaAircraftMonitor.
 
Method Summary
 void addMonitoredAircraft(TgfHlaAircraft aircraft)
          Adds an aircraft to the list of monitored aircraft.
 void beginMonitoring()
          Monitors the TgfHla federation execution for TgfHlaAircraft.
private  TgfHlaAircraft findAircraft(int instanceId)
          Returns an aircraft whose ID matches the passed parameter or NULL if no match was found.
 void handleInteractions(hla.rti.ReceivedInteraction theInteraction)
          Perform some function based upon theInteraction parameter passed to this object.
static void main(java.lang.String[] args)
          Starts up a new HlaAircraftMonitor.
 void reflect(int aircraftHandle, hla.rti.ReflectedAttributes theAttributes)
          Applies the values in 'theAttributes' parameter to matching aircraft within the 'monitoredAircraft' list of this object.
 void removeMonitoredAircraft(int aircraftHandle)
          Removes an aircraft from the monitored aircraft list.
private  void requestInitialAttributeUpdate()
          Deprecated. This method uses polling to query the rti - make sure the LazyObjectDiscovery is turned on in the RTI for a better way of handling this federate joining a federation. To ensure that it has been enabled check for this line under the FederationSection portion of the .rid file used to run the RTI: (AttributeScopeAdvisories Enabled ;; Some other parameters (LazyObjectDiscovery Enabled) )
(package private)  void resignAndDestroyFedExec()
          Attempts to resign the federate from the federation execution and destroy the FederationExecution process if this federate is the last remaining federate in the federation.
private  void startMainEventLoop()
          The main event loop - reflects aircraft attributes found in the RTI to the list of aircraft this object is monitoring.
private  void subscribeForAircraftAttributes()
          Invoking this method attempts to "subscribe" for aircraft attributes within the RTI.
private  void subscribeForInteractions()
          Invoking this method attempts to "subscribe" for interactions within the RTI.
(package private)  void tick(double min, double max)
          Our own tick method - used as a helper - takes doubles.
 void updateAircraft(int aircraftHandle, hla.rti.AttributeHandleSet theAttributes)
          Takes the passed AttributeHandleSet and updates a matched aircraft with those values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_VERSION_ID

public static final java.lang.String CVS_VERSION_ID
The CVS Version ID

See Also:
Constant Field Values

federateName

private java.lang.String federateName
The name of this federate.


attributeHandles

public TgfHlaHandleIDs attributeHandles
This is a list of handles (IDs) mapped to specific TgfHlaAircraft variables defined in the TgfFed.fed file. These handles are used whenever attribute specific data must be accessed, registered, or examined.


rtiAmbassador

private hla.rti.RTIambassador rtiAmbassador
The RTIambassador is the data bus used to convey messages from the federate to the RTI. Requests for enabling different services, updating object information, and performing RTI related tasks can be invoked by calls to this object.


fedAmbassador

private TgfMonitorFedAmb fedAmbassador
The TgfMonitorFedAmb is a FederateAmbassador. It's used whenever the RTI needs to tell a federate something via callback methods implemented within. The TgfMonitorFedAmb has been written for explicit use with this object.

See Also:
TgfMonitorFedAmb

monitoredAircraft

private TgfHlaAircraftList monitoredAircraft
A list of all the currently monitored aircraft. (Expect this to change to a Hashmap as this code is hammered out more.)


FEDERATION_EXECUTION_NAME

private static final java.lang.String FEDERATION_EXECUTION_NAME
The name of the federation execution to join.

See Also:
Constant Field Values

FEDERATION_EXECUTION_DATA

private static final java.lang.String FEDERATION_EXECUTION_DATA
The name of the federation execution file to use. This file sets up aircraft handle/interaction parameters.

See Also:
Constant Field Values

resigning

boolean resigning
A flag used to help us exit the federation politely. This flag is insurance against calling 'tick()' after we have resigned from the federation execution. Note The flag is private only because it needs to be accessed from the close hook - otherwise it would be private. It is set in the handleInteractions() method, and the close hook. It's status is checked in the main event loop.

Constructor Detail

HlaAircraftMonitor

public HlaAircraftMonitor()
                   throws hla.rti.RTIinternalError
Constructs a new HlaAircraftMonitor. Creating a new instance of this object does *not* make the object attempt to join a federation execution or monitor aircraft. Use the beginMonitoring() method for that functionality.

Throws:
hla.rti.RTIinternalError - if a problem occurs during the construction of this object.
Method Detail

subscribeForAircraftAttributes

private void subscribeForAircraftAttributes()
                                     throws CouldNotSubscribe
Invoking this method attempts to "subscribe" for aircraft attributes within the RTI. Any attributes this object cares to know about are bundled into a AttributeHandleSet, (a listing of IDs) which is then passed to the RTI along with a class ID (Aircraft, ground vehicles, etc) that they are associated with.

Throws:
CouldNotSubscribe - if this method is unable to subscribe for aircraft.

subscribeForInteractions

private void subscribeForInteractions()
                               throws CouldNotSubscribe
Invoking this method attempts to "subscribe" for interactions within the RTI. Interactions are 'immediate' events which occur during a simulation including explosions, warnings, simulation control requests/updates, termination, etc.

Throws:
CouldNotSubscribe - if this method was unable to subscribe for interactions specific to the TgfHla interface.

addMonitoredAircraft

public void addMonitoredAircraft(TgfHlaAircraft aircraft)
Adds an aircraft to the list of monitored aircraft.

Parameters:
aircraft - is the TgfHlaAircraft to add.

findAircraft

private TgfHlaAircraft findAircraft(int instanceId)
Returns an aircraft whose ID matches the passed parameter or NULL if no match was found.

Parameters:
instanceId - is the RTI ID of the aircraft to find. It's the handle associated with a TgfHlaAircraft object that the RTI uses to identify it from other TgfHlaAircraft.
Returns:
the TgfHlaAircraft whose ID matches the passed parameter or NULL if no such match was found.

reflect

public void reflect(int aircraftHandle,
                    hla.rti.ReflectedAttributes theAttributes)
             throws hla.rti.ObjectNotKnown,
                    hla.rti.AttributeNotKnown,
                    hla.rti.FederateInternalError
Applies the values in 'theAttributes' parameter to matching aircraft within the 'monitoredAircraft' list of this object.

Parameters:
aircraftHandle - is the RTI ID for the aircraft to reflect. It's the handle associated with a TgfHlaAircraft object that the RTI uses to identify it from other TgfHlaAircraft.
theAttributes - is a list of handles (ID's to a TgfHlaAircraft attributes) and the new value associated with the ID. (Think of it as a hashtable [ID --- Value]).
Throws:
hla.rti.ObjectNotKnown - if an aircraft which matches the aircraftHandle can not be found.
hla.rti.AttributeNotKnown - if an attribute within theAttributes parameter is unknown to the federate.
hla.rti.FederateInternalError - if an error occurs during the reflection process.

updateAircraft

public void updateAircraft(int aircraftHandle,
                           hla.rti.AttributeHandleSet theAttributes)
                    throws hla.rti.ObjectNotKnown
Takes the passed AttributeHandleSet and updates a matched aircraft with those values.

Parameters:
aircraftHandle - is the RTI ID for the aircraft to update. It's the handle associated with a TgfHlaAircraft object that the RTI uses to identify it from other TgfHlaAircraft.
theAttributes - is a "pair" list. It contains a listing of handles (ID's to a TgfHlaAircraft attributes) and the new value associated with the ID. (Think of it as a hashtable. [ID --- Value]).
Throws:
hla.rti.ObjectNotKnown - if an aircraft which matches the aircraftHandle can not be found.

requestInitialAttributeUpdate

private void requestInitialAttributeUpdate()
                                    throws CouldNotUpdateAircraft
Deprecated. This method uses polling to query the rti - make sure the LazyObjectDiscovery is turned on in the RTI for a better way of handling this federate joining a federation. To ensure that it has been enabled check for this line under the FederationSection portion of the .rid file used to run the RTI: (AttributeScopeAdvisories Enabled ;; Some other parameters (LazyObjectDiscovery Enabled) )

Invokes the RTIambassador's requestClassAttributeUpdate() to ensure all aircraft within the list of monitored aircraft are updated to the current values.

Throws:
CouldNotUpdateAircraft - if one of the following conditions are met: 1)- The attribute handle is not within the listing of valid handles. 2)- The TgfHlaAircraft object class was not defined in the .fed file. 3)- A save was in progress at the time this method was called. 4)- A restore was in progress at the time this method was called.

removeMonitoredAircraft

public void removeMonitoredAircraft(int aircraftHandle)
                             throws hla.rti.ObjectNotKnown
Removes an aircraft from the monitored aircraft list. Note This does NOT remove an aircraft from the RTI - only from the list of monitored aircraft this object possesses.

Parameters:
aircraftHandle - is the RTI ID for the aircraft to remove. It's the handle associated with a TgfHlaAircraft object that the RTI uses to identify it from other TgfHlaAircraft.
Throws:
hla.rti.ObjectNotKnown - if a matching aircraft is not found within the simulatd aircraft list.

beginMonitoring

public void beginMonitoring()
                     throws hla.rti.RTIexception,
                            hla.rti.FederateNotExecutionMember,
                            java.net.MalformedURLException
Monitors the TgfHla federation execution for TgfHlaAircraft. Any aircraft present are added to the monitored list, their data is outputted to standard output when the RTI 'ticks'.

Throws:
hla.rti.RTIexception - if an unrecoverable error occurs during the RTI execution.
hla.rti.FederateNotExecutionMember - if this object fails to join the federation execution.
java.net.MalformedURLException - if the federate has problems reading the .fed or .rid files.

startMainEventLoop

private void startMainEventLoop()
                         throws hla.rti.RTIexception
The main event loop - reflects aircraft attributes found in the RTI to the list of aircraft this object is monitoring.

Throws:
hla.rti.RTIexception

resignAndDestroyFedExec

void resignAndDestroyFedExec()
                       throws CouldNotResign,
                              CouldNotDestroy
Attempts to resign the federate from the federation execution and destroy the FederationExecution process if this federate is the last remaining federate in the federation.

Throws:
CouldNotResign - if one of the following conditons are met: 1) - The federate still owns an attribute. 2) - The federate is not an execution member. 3) - The resign action is not supported. 4) - Concurrent access to this method is attempted.
CouldNotDestroy - if one of the following conditions are met: 1) - There is another federate still attached to the RTI. 2) - The federation execution never existed. 3) - Concurrent access to this method is attempted.

handleInteractions

public void handleInteractions(hla.rti.ReceivedInteraction theInteraction)
                        throws hla.rti.FederateInternalError,
                               hla.rti.InteractionParameterNotKnown
Perform some function based upon theInteraction parameter passed to this object.

Parameters:
theInteraction - is the simulation interaction to handle.
Throws:
hla.rti.FederateInternalError
hla.rti.InteractionParameterNotKnown

main

public static void main(java.lang.String[] args)
Starts up a new HlaAircraftMonitor.

Parameters:
args - are the command line arguments to parse.

tick

void tick(double min,
          double max)
    throws hla.rti.RTIexception
Our own tick method - used as a helper - takes doubles. Tells the RTI ambassador to do rti related things - invoked when the monitor has completed doing everything it can and needs the RTI to do some actions, or process some events so it can do more things.

Parameters:
min - is the minimal amount of time to get things done.
max - is the maximum amount of time to get things done.
Throws:
hla.rti.RTIexception