org.eodisp.wrapper.hla
Class ProxyAmbassador

java.lang.Object
  extended by org.eodisp.wrapper.hla.ProxyAmbassador
Direct Known Subclasses:
EodispFederate

public abstract class ProxyAmbassador
extends java.lang.Object

Provides a facade (Facade Pattern) to the HLA interfaces RTIambassador and FederateAmbassador. The HLA interfaces can still be accessed directly if needed (See getFederateAmbassadorDelegator()).

Author:
Andrzej Kapolka, Iwan Birrer

Nested Class Summary
(package private)  class ProxyAmbassador.SyncPointRegistrationState
           
 
Field Summary
protected  hla.rti1516.RTIambassador rtiAmbassador
          The run-time infrastructure ambassador.
 
Constructor Summary
ProxyAmbassador(hla.rti1516.RTIambassador rtiAmbassador)
          Constructor.
 
Method Summary
 void achieveSyncPointAndAwaitFederationSynchronization(java.lang.String syncPointLabel, long timeout, java.util.concurrent.TimeUnit unit)
           Waits until the synchronization point is announced .
 void addObjectClassDiscoveryListener(ObjectClassDiscoveryListener objectClassDiscoveryListener)
          Adds an element to the list of objects interested in discovered object instances
 boolean awaitSynchronizationPointAnnouncement(java.lang.String syncPointLabel, long timeout, java.util.concurrent.TimeUnit unit)
           
 void defaultPublishSubscribe()
          Makes all subscriptions and publications of object classes and interaction classes as defined in the SOM.
 FederateAmbassadorDelegator getFederateAmbassadorDelegator()
          Returns the federate ambassador delegator that is used when joining a federation execution.
 hla.rti1516.FederateHandle getFederatHandle()
          Returns the federate handle of this federate or null if this federate has not joined a federation execution.
 java.util.Collection<ObjectClassInstance> getObjectClassInstances()
          Returns an immutable collection containing the object class instances managed by this proxy ambassador.
 ObjectClassInstance getObjectInstance(hla.rti1516.ObjectInstanceHandle objectInstanceHandle)
          Returns the managed object class instance with the specified handle.
 hla.rti1516.RTIambassador getRtiAmbassador()
           
protected abstract  void initAfterJoin()
          This method is called from the joinFederationExecution(String, String, MobileFederateServices) method just after the federate has been joined.
 hla.rti1516.FederateHandle joinFederationExecution(java.lang.String federateType, java.lang.String federationExecutionName, hla.rti1516.MobileFederateServices serviceReferences)
          Joins the given federation execution and calls initAfterJoin() immediately after.
 hla.rti1516.FederateHandle joinFederationExecution(java.lang.String federateType, java.lang.String federationExecutionName, hla.rti1516.MobileFederateServices serviceReferences, long timeout, java.util.concurrent.TimeUnit unit)
          Convenience method to join a federation execution.
protected  void notifyReceiveInteraction(hla.rti1516.InteractionClassHandle interactionClass, hla.rti1516.ParameterHandleValueMap theParameters, byte[] userSuppliedTag, hla.rti1516.OrderType sentOrdering, hla.rti1516.TransportationType theTransport)
           
abstract  void publishInteractionClasses()
          Publishes all supported interaction classes.
abstract  void publishObjectClassAttributes()
          Publishes all supported object class attributes.
 void registerObjectClassInstance(hla.rti1516.ObjectInstanceHandle objectInstanceHandle, ObjectClassInstance objectClassInstance)
           
 void registerSynchronizationPoint(java.lang.String syncPointLabel, byte[] userSuppliedTag, hla.rti1516.FederateHandleSet synchronizationSet, long timeout, java.util.concurrent.TimeUnit unit)
          Registers a synchronization point and returns if the registration was successful or not.
 void registerSynchronizationPoint(java.lang.String syncPointLabel, byte[] userSuppliedTag, long timeout, java.util.concurrent.TimeUnit unit)
          Registers a synchronization point and returns if the registration was successful or not.
 void removeObjectClassDiscoveryListener(ObjectClassDiscoveryListener objectClassDiscoveryListener)
          Removes an element from the list of objects interested in discovered object instances
 void setDiscoveredObjectClassInstanceFactory(DiscoveredObjectClassInstanceFactory discoveredObjectClassInstanceFactory)
           
abstract  void subscribeInteractionClasses()
          Subscribes to all supported interaction classes.
abstract  void subscribeObjectClassAttributes()
          Subscribe to all supported object class attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rtiAmbassador

protected final hla.rti1516.RTIambassador rtiAmbassador
The run-time infrastructure ambassador.

Constructor Detail

ProxyAmbassador

public ProxyAmbassador(hla.rti1516.RTIambassador rtiAmbassador)
Constructor.

Parameters:
pRTIAmbassador - the run-time infrastructure ambassador
discoveredObjectClassInstanceFactory - The factory that creates the appropriate java instances for each object class instance discovered.
Method Detail

notifyReceiveInteraction

protected void notifyReceiveInteraction(hla.rti1516.InteractionClassHandle interactionClass,
                                        hla.rti1516.ParameterHandleValueMap theParameters,
                                        byte[] userSuppliedTag,
                                        hla.rti1516.OrderType sentOrdering,
                                        hla.rti1516.TransportationType theTransport)
                                 throws hla.rti1516.InteractionClassNotRecognized,
                                        hla.rti1516.InteractionParameterNotRecognized,
                                        hla.rti1516.InteractionClassNotSubscribed,
                                        hla.rti1516.FederateInternalError
Throws:
hla.rti1516.InteractionClassNotRecognized
hla.rti1516.InteractionParameterNotRecognized
hla.rti1516.InteractionClassNotSubscribed
hla.rti1516.FederateInternalError

setDiscoveredObjectClassInstanceFactory

public void setDiscoveredObjectClassInstanceFactory(DiscoveredObjectClassInstanceFactory discoveredObjectClassInstanceFactory)

getFederateAmbassadorDelegator

public FederateAmbassadorDelegator getFederateAmbassadorDelegator()
Returns the federate ambassador delegator that is used when joining a federation execution. This delegator already contains one federate ambassador delegate, the one that is used internally by this class. Additional federate ambassador delegates can be added to receive all the callbacks from the RTI. Just add a FederateAmbassador instance to the returned delegator with FederateAmbassadorDelegator.registerDelegate(FederateAmbassador). This can be done at any time. If you want to receive all callbacks, add the delegate before you call joinFederationExecution(String, String, MobileFederateServices).

Returns:
the federate ambassador delegator that is used when joining a federation execution.

addObjectClassDiscoveryListener

public void addObjectClassDiscoveryListener(ObjectClassDiscoveryListener objectClassDiscoveryListener)
Adds an element to the list of objects interested in discovered object instances

Parameters:
objectClassDiscoveryListener - the listener to add

removeObjectClassDiscoveryListener

public void removeObjectClassDiscoveryListener(ObjectClassDiscoveryListener objectClassDiscoveryListener)
Removes an element from the list of objects interested in discovered object instances

Parameters:
objectClassDiscoveryListener - the listener to remove

joinFederationExecution

public final hla.rti1516.FederateHandle joinFederationExecution(java.lang.String federateType,
                                                                java.lang.String federationExecutionName,
                                                                hla.rti1516.MobileFederateServices serviceReferences)
                                                         throws hla.rti1516.RTIexception,
                                                                hla.rti1516.FederateAlreadyExecutionMember,
                                                                hla.rti1516.FederationExecutionDoesNotExist,
                                                                hla.rti1516.SaveInProgress,
                                                                hla.rti1516.RestoreInProgress,
                                                                hla.rti1516.RTIinternalError
Joins the given federation execution and calls initAfterJoin() immediately after. Makes sure that callbacks from the RTI are processed only after the initAfterJoin() method has returned.

Callbacks that come in during the initAfterJoin() are queued; The FederateAmbassadorDelegator.startProcessing() on the internal federate ambassador delegator (that is returned by getFederateAmbassadorDelegator()) is called just after the initAfterJoin() has returned.

Parameters:
federateType - a string describing the federate's role in the federation
federationExecutionName - the name of the federation to join
serviceReferences - the federate's mobile services
Returns:
the federate handle that was returned by the RTI
Throws:
hla.rti1516.FederateAlreadyExecutionMember - if the federate is already a member of an execution
hla.rti1516.FederationExecutionDoesNotExist - if the federation execution does not exist
hla.rti1516.SaveInProgress - if a save operation is in progress
hla.rti1516.RestoreInProgress - if a restore operation is in progress
hla.rti1516.RTIinternalError - if an internal error occurred in the run-time infrastructure
exceptions - thrown by initAfterJoin()
hla.rti1516.RTIexception

joinFederationExecution

public final hla.rti1516.FederateHandle joinFederationExecution(java.lang.String federateType,
                                                                java.lang.String federationExecutionName,
                                                                hla.rti1516.MobileFederateServices serviceReferences,
                                                                long timeout,
                                                                java.util.concurrent.TimeUnit unit)
                                                         throws hla.rti1516.RTIexception,
                                                                hla.rti1516.FederateAlreadyExecutionMember,
                                                                hla.rti1516.FederationExecutionDoesNotExist,
                                                                hla.rti1516.SaveInProgress,
                                                                hla.rti1516.RestoreInProgress,
                                                                hla.rti1516.RTIinternalError
Convenience method to join a federation execution. Joining is retried every 2 seconds until the timeout is reached.

Parameters:
federateType -
federationExecutionName -
serviceReferences -
timeout -
unit -
Throws:
hla.rti1516.RTIexception
hla.rti1516.FederateAlreadyExecutionMember
hla.rti1516.FederationExecutionDoesNotExist
hla.rti1516.SaveInProgress
hla.rti1516.RestoreInProgress
hla.rti1516.RTIinternalError

getFederatHandle

public hla.rti1516.FederateHandle getFederatHandle()
Returns the federate handle of this federate or null if this federate has not joined a federation execution.

Returns:
the federate handle

initAfterJoin

protected abstract void initAfterJoin()
                               throws hla.rti1516.RTIexception
This method is called from the joinFederationExecution(String, String, MobileFederateServices) method just after the federate has been joined. It is made sure that no callbacks from the RTI will be processed before this method has returned. Therefore, this method is the a suitable place to initialize HLA handles that need to be known when callbacks from the RTI are processed.

Throws:
hla.rti1516.RTIexception

defaultPublishSubscribe

public void defaultPublishSubscribe()
                             throws hla.rti1516.InvalidInteractionClassHandle,
                                    hla.rti1516.NameNotFound,
                                    hla.rti1516.InteractionClassNotDefined,
                                    hla.rti1516.FederateNotExecutionMember,
                                    hla.rti1516.SaveInProgress,
                                    hla.rti1516.RestoreInProgress,
                                    hla.rti1516.RTIinternalError,
                                    hla.rti1516.FederateServiceInvocationsAreBeingReportedViaMOM,
                                    hla.rti1516.InvalidObjectClassHandle,
                                    hla.rti1516.ObjectClassNotDefined,
                                    hla.rti1516.AttributeNotDefined
Makes all subscriptions and publications of object classes and interaction classes as defined in the SOM.

Throws:
hla.rti1516.InvalidInteractionClassHandle
hla.rti1516.NameNotFound
hla.rti1516.InteractionClassNotDefined
hla.rti1516.FederateNotExecutionMember
hla.rti1516.SaveInProgress
hla.rti1516.RestoreInProgress
hla.rti1516.RTIinternalError
hla.rti1516.FederateServiceInvocationsAreBeingReportedViaMOM
hla.rti1516.InvalidObjectClassHandle
hla.rti1516.ObjectClassNotDefined
hla.rti1516.AttributeNotDefined

publishInteractionClasses

public abstract void publishInteractionClasses()
                                        throws hla.rti1516.InvalidInteractionClassHandle,
                                               hla.rti1516.NameNotFound,
                                               hla.rti1516.InteractionClassNotDefined,
                                               hla.rti1516.FederateNotExecutionMember,
                                               hla.rti1516.SaveInProgress,
                                               hla.rti1516.RestoreInProgress,
                                               hla.rti1516.RTIinternalError
Publishes all supported interaction classes.

Throws:
hla.rti1516.InvalidInteractionClassHandle - if an interaction class handle is invalid
hla.rti1516.NameNotFound - if a name is not found
hla.rti1516.InteractionClassNotDefined - if an interaction class is undefined
hla.rti1516.FederateNotExecutionMember - if the federate is not an execution member
hla.rti1516.SaveInProgress - if a save operation is in progress
hla.rti1516.RestoreInProgress - if a restore operation is in progress
hla.rti1516.RTIinternalError - if an internal error occurs in the run-time infrastructure

subscribeInteractionClasses

public abstract void subscribeInteractionClasses()
                                          throws hla.rti1516.InvalidInteractionClassHandle,
                                                 hla.rti1516.NameNotFound,
                                                 hla.rti1516.InteractionClassNotDefined,
                                                 hla.rti1516.FederateNotExecutionMember,
                                                 hla.rti1516.SaveInProgress,
                                                 hla.rti1516.RestoreInProgress,
                                                 hla.rti1516.FederateServiceInvocationsAreBeingReportedViaMOM,
                                                 hla.rti1516.RTIinternalError
Subscribes to all supported interaction classes.

Throws:
hla.rti1516.InvalidInteractionClassHandle - if an interaction class handle is invalid
hla.rti1516.NameNotFound - if a name is not found
hla.rti1516.InteractionClassNotDefined - if an interaction class is undefined
hla.rti1516.FederateNotExecutionMember - if the federate is not an execution member
hla.rti1516.SaveInProgress - if a save operation is in progress
hla.rti1516.RestoreInProgress - if a restore operation is in progress
hla.rti1516.FederateServiceInvocationsAreBeingReportedViaMOM - if service invocations are being reported via MOM
hla.rti1516.RTIinternalError - if an internal error occurs in the run-time infrastructure

publishObjectClassAttributes

public abstract void publishObjectClassAttributes()
                                           throws hla.rti1516.InvalidObjectClassHandle,
                                                  hla.rti1516.NameNotFound,
                                                  hla.rti1516.ObjectClassNotDefined,
                                                  hla.rti1516.AttributeNotDefined,
                                                  hla.rti1516.FederateNotExecutionMember,
                                                  hla.rti1516.SaveInProgress,
                                                  hla.rti1516.RestoreInProgress,
                                                  hla.rti1516.RTIinternalError
Publishes all supported object class attributes.

Throws:
hla.rti1516.InvalidObjectClassHandle - if an object class handle is invalid
hla.rti1516.NameNotFound - if a name is not found
hla.rti1516.ObjectClassNotDefined - if an object class is undefined
hla.rti1516.AttributeNotDefined - if an attribute is undefined
hla.rti1516.FederateNotExecutionMember - if the federate is not an execution member
hla.rti1516.SaveInProgress - if a save operation is in progress
hla.rti1516.RestoreInProgress - if a restore operation is in progress
hla.rti1516.RTIinternalError - if an internal error occurs in the run-time infrastructure

subscribeObjectClassAttributes

public abstract void subscribeObjectClassAttributes()
                                             throws hla.rti1516.InvalidObjectClassHandle,
                                                    hla.rti1516.NameNotFound,
                                                    hla.rti1516.ObjectClassNotDefined,
                                                    hla.rti1516.AttributeNotDefined,
                                                    hla.rti1516.FederateNotExecutionMember,
                                                    hla.rti1516.SaveInProgress,
                                                    hla.rti1516.RestoreInProgress,
                                                    hla.rti1516.RTIinternalError
Subscribe to all supported object class attributes.

Throws:
hla.rti1516.InvalidObjectClassHandle - if an object class handle is invalid
hla.rti1516.NameNotFound - if a name is not found
hla.rti1516.ObjectClassNotDefined - if an object class is undefined
hla.rti1516.AttributeNotDefined - if an attribute is undefined
hla.rti1516.FederateNotExecutionMember - if the federate is not an execution member
hla.rti1516.SaveInProgress - if a save operation is in progress
hla.rti1516.RestoreInProgress - if a restore operation is in progress
hla.rti1516.RTIinternalError - if an internal error occurs in the run-time infrastructure

registerObjectClassInstance

public void registerObjectClassInstance(hla.rti1516.ObjectInstanceHandle objectInstanceHandle,
                                        ObjectClassInstance objectClassInstance)

getObjectInstance

public ObjectClassInstance getObjectInstance(hla.rti1516.ObjectInstanceHandle objectInstanceHandle)
Returns the managed object class instance with the specified handle.

Parameters:
objectInstanceHandle - the object instance handle corresponding to the desired object class instance
Returns:
the managed object class instance with the specified handle, or null if no such object instance exists

getObjectClassInstances

public java.util.Collection<ObjectClassInstance> getObjectClassInstances()
Returns an immutable collection containing the object class instances managed by this proxy ambassador.

Returns:
an immutable collection of all managed object class instances

registerSynchronizationPoint

public void registerSynchronizationPoint(java.lang.String syncPointLabel,
                                         byte[] userSuppliedTag,
                                         long timeout,
                                         java.util.concurrent.TimeUnit unit)
                                  throws hla.rti1516.FederateNotExecutionMember,
                                         hla.rti1516.SaveInProgress,
                                         hla.rti1516.RestoreInProgress,
                                         hla.rti1516.RTIinternalError,
                                         java.lang.InterruptedException,
                                         SynchronizationPointRegistrationException
Registers a synchronization point and returns if the registration was successful or not. Causes the current thread to wait until the CRC returned if the registration was successful, unless the thread is interrupted, or the specified waiting time elapses.

Parameters:
syncPointLabel - the label of synchronization point to be registered, as defined in the SOM/FOM.
userSuppliedTag - user supplied tag
timeout - the maximum time to wait
unit - the time unit of the timeout argument.
Throws:
hla.rti1516.FederateNotExecutionMember
hla.rti1516.SaveInProgress
hla.rti1516.RestoreInProgress
hla.rti1516.RTIinternalError
java.util.concurrent.TimeoutException - the timeout was reached before the RTI acknowledged the synchronization point registration. After this exception has been thrown the registration may still have succeeded.
java.lang.InterruptedException
SynchronizationPointRegistrationException

registerSynchronizationPoint

public void registerSynchronizationPoint(java.lang.String syncPointLabel,
                                         byte[] userSuppliedTag,
                                         hla.rti1516.FederateHandleSet synchronizationSet,
                                         long timeout,
                                         java.util.concurrent.TimeUnit unit)
                                  throws hla.rti1516.FederateNotExecutionMember,
                                         hla.rti1516.SaveInProgress,
                                         hla.rti1516.RestoreInProgress,
                                         hla.rti1516.RTIinternalError,
                                         SynchronizationPointRegistrationException,
                                         java.lang.InterruptedException
Registers a synchronization point and returns if the registration was successful or not. Causes the current thread to wait until the CRC returned if the registration was successful, unless the thread is interrupted, or the specified waiting time elapses.

Parameters:
syncPointLabel - the label of synchronization point to be registered, as defined in the SOM/FOM.
userSuppliedTag - user supplied tag
synchronizationSet - the set of federates that take part in the synchronization
timeout - the maximum time to wait
unit - the time unit of the timeout argument.
Throws:
hla.rti1516.FederateNotExecutionMember
hla.rti1516.SaveInProgress
hla.rti1516.RestoreInProgress
hla.rti1516.RTIinternalError
java.lang.IllegalStateException - if this federate is in the process of registering a synchronization point with the same label. This exception is generated locally, not from the RTI
java.lang.InterruptedException - if the thread has been interrupted
SynchronizationPointRegistrationException - if the synchronization failed because of one of the following reasons:
  • The synchronization point label is already in use
  • At least one member of the synchronization set is not joined to the synchronization point
  • The RTI did not acknowledge the registration within a ceratin amount of time (see TODO)

awaitSynchronizationPointAnnouncement

public boolean awaitSynchronizationPointAnnouncement(java.lang.String syncPointLabel,
                                                     long timeout,
                                                     java.util.concurrent.TimeUnit unit)
                                              throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

achieveSyncPointAndAwaitFederationSynchronization

public void achieveSyncPointAndAwaitFederationSynchronization(java.lang.String syncPointLabel,
                                                              long timeout,
                                                              java.util.concurrent.TimeUnit unit)
                                                       throws java.lang.InterruptedException,
                                                              hla.rti1516.SynchronizationPointLabelNotAnnounced,
                                                              hla.rti1516.FederateNotExecutionMember,
                                                              hla.rti1516.SaveInProgress,
                                                              hla.rti1516.RestoreInProgress,
                                                              hla.rti1516.RTIinternalError,
                                                              FederationSynchronizationException
  1. Waits until the synchronization point is announced
. Informs the RTI that this federate has achieved the synchronization point syncPointLabel.

Parameters:
syncPointLabel -
timeout -
unit -
Throws:
java.lang.InterruptedException
hla.rti1516.RTIinternalError
hla.rti1516.RestoreInProgress
hla.rti1516.SaveInProgress
hla.rti1516.FederateNotExecutionMember
hla.rti1516.SynchronizationPointLabelNotAnnounced
FederationSynchronizationException

getRtiAmbassador

public hla.rti1516.RTIambassador getRtiAmbassador()