cz.zcu.fav.kiv.jsim.hla
Class JSimHLAConnection

java.lang.Object
  extended bycz.zcu.fav.kiv.jsim.hla.JSimHLAConnection

public class JSimHLAConnection
extends java.lang.Object

JSimHLAConnection provides connection between J-Sim and the Runtime Infrastructure (RTI). Instance of this class is created automatically by JSimHLASimulation when HLA is used. You should never need to create an instance of this class.

Author:
Stanislav Kozina

Field Summary
static java.lang.String IC_JSIM_END_OF_SIMULATION
          Interaction class JSimEndOfSimulation.
static java.lang.String IC_JSIM_REQUEST
          Interaction class JSimRequest.
static java.lang.String IC_JSIM_RESPONSE
          Interaction class JSimResponse.
static java.lang.String ICP_JSIM_END_DATA
           
static java.lang.String ICP_JSIM_REQUEST_DATA
           
static java.lang.String ICP_JSIM_REQUEST_HEADER
           
static java.lang.String ICP_JSIM_RESPONSE_DATA
           
static java.lang.String ICP_JSIM_RESPONSE_HEADER
           
static int JSIM_HEAD_CARDINAL
           
static int JSIM_HEAD_EMPTY
           
static int JSIM_HEAD_FIRST
           
static int JSIM_HEAD_GET_LW
           
static int JSIM_HEAD_GET_TW
           
static int JSIM_HEAD_GET_TW_FOR_ALL_LINKS
           
static int JSIM_HEAD_LAST
           
static int JSIM_LINK_INTO
           
static int JSIM_PROCESS_ACTIVATE
           
static int JSIM_PROCESS_CANCEL
           
static int JSIM_PROCESS_GET_STATE
           
static int JSIM_PROCESS_IS_IDLE
           
static int JSIM_RESPONSE_NOT_RECEIVED
           
static int JSIM_RESULT_EXCEPTION
           
static int JSIM_RESULT_OK
           
static java.lang.String PROTOCOL_VERSION
          JSim HLA Protocol version.
 
Constructor Summary
JSimHLAConnection(JSimHLASimulation simulation, java.util.Properties configurationRTI)
          Constructor.
 
Method Summary
protected  void announceSynchronizationPoint(java.lang.String synchronizationPointLabel)
          Notifies the federate that a synchronization point has been announced.
protected  void beginFederationExecution(int numberOfFederates, int modeEndOfSimulation)
          Begins JSim federation execution.
static java.lang.Object byteArrayToObject(byte[] byteArray)
          Deserializes object from byte array.
protected  void debug(java.lang.String message)
          Prints debug message.
protected  void discoverObjectInstance(ObjectInstanceHandle theObject, ObjectClassHandle theObjectClass, java.lang.String objectName)
          Notifies the federate of the presence of an object instance.
protected  void endFederationExecution(boolean destroy)
          Ends JSim federation execution.
protected  void federationSynchronized(java.lang.String synchronizationPointLabel)
          Notifies the federate that the federation has been synchronized.
 LogicalTime getLogicalTime()
          Returns federate's granted logical time.
 void nextMessageRequestAvailable(LogicalTime theTime)
          Calls service nextMessageRequestAvailable() of the RTIambassador.
static byte[] objectToByteArray(java.lang.Object object)
          Serializes specified object into byte array.
protected  void printErrorMessage(java.lang.String message)
          Prints an error message.
protected  void printMessage(java.lang.String message)
          Prints a message.
 void processReceivedInteractions()
          Performs processing of received interactions stored in interactions callback queue.
protected  void receiveInteraction(InteractionClassHandle interactionClass, ParameterHandleValueMap theParameters, byte[] userSuppliedTag, OrderType receivedOrdering)
          Receives interaction from RTI.
protected  void reflectAttributeValues(ObjectInstanceHandle theObject, AttributeHandleValueMap theAttributes, byte[] userSuppliedTag, OrderType sentOrdering, TransportationType theTransport)
          Notifies the federate of changes to the state of an object instance.
protected  JSimHLAResponse sendRequestHeadCardinal(java.lang.String headName)
          Sends request for head.cardinal().
protected  JSimHLAResponse sendRequestHeadEmpty(java.lang.String headName)
          Sends request for head.empty().
protected  JSimHLAResponse sendRequestHeadFirst(java.lang.String headName)
          Sends request for head.first().
protected  JSimHLAResponse sendRequestHeadGetLw(java.lang.String headName)
          Sends request for head.getLw().
protected  JSimHLAResponse sendRequestHeadGetTw(java.lang.String headName)
          Sends request for head.getTw().
protected  JSimHLAResponse sendRequestHeadGetTwForAllLinks(java.lang.String headName)
          Sends request for head.getTwForAllLinks().
protected  JSimHLAResponse sendRequestHeadLast(java.lang.String headName)
          Sends request for head.last().
protected  JSimHLAResponse sendRequestLinkInto(java.lang.String headName, JSimLink link)
          Sends request for link.into().
protected  JSimHLAResponse sendRequestProcessActivate(java.lang.String processName, double when)
          Sends request for process.activate().
protected  JSimHLAResponse sendRequestProcessCancel(java.lang.String processName)
          Sends request for process.cancel().
protected  JSimHLAResponse sendRequestProcessGetState(java.lang.String processName)
          Sends request for process.getState().
protected  JSimHLAResponse sendRequestProcessIsIdle(java.lang.String processName)
          Sends request for process.isIdle().
protected  void timeAdvanceGrant(LogicalTime time)
          Notifies the federate that a time advance has been granted.
protected  void timeConstrainedEnabled(LogicalTime time)
          Notifies the federate that time-constrained mode has been enabled.
protected  void timeRegulationEnabled(LogicalTime time)
          Notifies the federate that time regulation has been enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_VERSION

public static final java.lang.String PROTOCOL_VERSION
JSim HLA Protocol version.

See Also:
Constant Field Values

IC_JSIM_REQUEST

public static final java.lang.String IC_JSIM_REQUEST
Interaction class JSimRequest. It has two parameters.

See Also:
Constant Field Values

ICP_JSIM_REQUEST_HEADER

public static final java.lang.String ICP_JSIM_REQUEST_HEADER
See Also:
Constant Field Values

ICP_JSIM_REQUEST_DATA

public static final java.lang.String ICP_JSIM_REQUEST_DATA
See Also:
Constant Field Values

IC_JSIM_RESPONSE

public static final java.lang.String IC_JSIM_RESPONSE
Interaction class JSimResponse. It has two parameters.

See Also:
Constant Field Values

ICP_JSIM_RESPONSE_HEADER

public static final java.lang.String ICP_JSIM_RESPONSE_HEADER
See Also:
Constant Field Values

ICP_JSIM_RESPONSE_DATA

public static final java.lang.String ICP_JSIM_RESPONSE_DATA
See Also:
Constant Field Values

IC_JSIM_END_OF_SIMULATION

public static final java.lang.String IC_JSIM_END_OF_SIMULATION
Interaction class JSimEndOfSimulation.

See Also:
Constant Field Values

ICP_JSIM_END_DATA

public static final java.lang.String ICP_JSIM_END_DATA
See Also:
Constant Field Values

JSIM_PROCESS_ACTIVATE

public static final int JSIM_PROCESS_ACTIVATE
See Also:
Constant Field Values

JSIM_PROCESS_CANCEL

public static final int JSIM_PROCESS_CANCEL
See Also:
Constant Field Values

JSIM_PROCESS_GET_STATE

public static final int JSIM_PROCESS_GET_STATE
See Also:
Constant Field Values

JSIM_PROCESS_IS_IDLE

public static final int JSIM_PROCESS_IS_IDLE
See Also:
Constant Field Values

JSIM_HEAD_EMPTY

public static final int JSIM_HEAD_EMPTY
See Also:
Constant Field Values

JSIM_HEAD_CARDINAL

public static final int JSIM_HEAD_CARDINAL
See Also:
Constant Field Values

JSIM_HEAD_FIRST

public static final int JSIM_HEAD_FIRST
See Also:
Constant Field Values

JSIM_HEAD_LAST

public static final int JSIM_HEAD_LAST
See Also:
Constant Field Values

JSIM_HEAD_GET_LW

public static final int JSIM_HEAD_GET_LW
See Also:
Constant Field Values

JSIM_HEAD_GET_TW

public static final int JSIM_HEAD_GET_TW
See Also:
Constant Field Values

JSIM_HEAD_GET_TW_FOR_ALL_LINKS

public static final int JSIM_HEAD_GET_TW_FOR_ALL_LINKS
See Also:
Constant Field Values

JSIM_LINK_INTO

public static final int JSIM_LINK_INTO
See Also:
Constant Field Values

JSIM_RESULT_OK

public static final int JSIM_RESULT_OK
See Also:
Constant Field Values

JSIM_RESULT_EXCEPTION

public static final int JSIM_RESULT_EXCEPTION
See Also:
Constant Field Values

JSIM_RESPONSE_NOT_RECEIVED

public static final int JSIM_RESPONSE_NOT_RECEIVED
See Also:
Constant Field Values
Constructor Detail

JSimHLAConnection

public JSimHLAConnection(JSimHLASimulation simulation,
                         java.util.Properties configurationRTI)
Constructor. Instance of this class is created automatically when HLA is used. You should never need to create an instance of this class.

Parameters:
simulation - Parent simulation object.
configurationRTI - Configuration properties for Runtime Infrastructure (RTI).
Method Detail

objectToByteArray

public static byte[] objectToByteArray(java.lang.Object object)
                                throws java.io.IOException
Serializes specified object into byte array.

Parameters:
object - Object to be serialized. It must implement java.io.Serializable.
Returns:
Byte array of serialized object.
Throws:
java.io.IOException

byteArrayToObject

public static java.lang.Object byteArrayToObject(byte[] byteArray)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
Deserializes object from byte array.

Parameters:
byteArray - Byte array to be deserialized.
Returns:
Deserialized object.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

printMessage

protected void printMessage(java.lang.String message)
Prints a message.

Parameters:
message - message to print

debug

protected void debug(java.lang.String message)
Prints debug message.

Parameters:
message - message to print

printErrorMessage

protected void printErrorMessage(java.lang.String message)
Prints an error message.

Parameters:
message - Error message to print.

timeConstrainedEnabled

protected void timeConstrainedEnabled(LogicalTime time)
Notifies the federate that time-constrained mode has been enabled.

Parameters:
time - the current logical time

timeRegulationEnabled

protected void timeRegulationEnabled(LogicalTime time)
Notifies the federate that time regulation has been enabled.

Parameters:
time - the current logical time

timeAdvanceGrant

protected void timeAdvanceGrant(LogicalTime time)
Notifies the federate that a time advance has been granted.

Parameters:
time - the new logical time

announceSynchronizationPoint

protected void announceSynchronizationPoint(java.lang.String synchronizationPointLabel)
Notifies the federate that a synchronization point has been announced. Synchronization point must be announced by RTI before federate can achieve it.

Parameters:
synchronizationPointLabel - the label of the synchronization point

federationSynchronized

protected void federationSynchronized(java.lang.String synchronizationPointLabel)
Notifies the federate that the federation has been synchronized.

Parameters:
synchronizationPointLabel - the label of the synchronization point

discoverObjectInstance

protected void discoverObjectInstance(ObjectInstanceHandle theObject,
                                      ObjectClassHandle theObjectClass,
                                      java.lang.String objectName)
Notifies the federate of the presence of an object instance.

Parameters:
theObject - the instance handle of the newly discovered object
theObjectClass - the class handle of the newly discovered object
objectName - the name of the newly discovered object

reflectAttributeValues

protected void reflectAttributeValues(ObjectInstanceHandle theObject,
                                      AttributeHandleValueMap theAttributes,
                                      byte[] userSuppliedTag,
                                      OrderType sentOrdering,
                                      TransportationType theTransport)
Notifies the federate of changes to the state of an object instance.

Parameters:
theObject - the instance handle of the modified object
theAttributes - the map between attribute handles and the new values of the identified attributes
userSuppliedTag - a user-supplied tag associated with the state change
sentOrdering - the type of ordering with which the update was sent
theTransport - the type of transport associated with the update

sendRequestProcessActivate

protected JSimHLAResponse sendRequestProcessActivate(java.lang.String processName,
                                                     double when)
Sends request for process.activate().

Parameters:
processName - The name of the process.
when - Absolute simulation time when the process should be activated.
Returns:
Response for request.

sendRequestProcessCancel

protected JSimHLAResponse sendRequestProcessCancel(java.lang.String processName)
Sends request for process.cancel().

Parameters:
processName - The name of the process.
Returns:
Response for request.

sendRequestProcessGetState

protected JSimHLAResponse sendRequestProcessGetState(java.lang.String processName)
Sends request for process.getState().

Parameters:
processName - The name of the process.
Returns:
Response for request.

sendRequestProcessIsIdle

protected JSimHLAResponse sendRequestProcessIsIdle(java.lang.String processName)
Sends request for process.isIdle().

Parameters:
processName - The name of the process.
Returns:
Response for request.

sendRequestHeadEmpty

protected JSimHLAResponse sendRequestHeadEmpty(java.lang.String headName)
Sends request for head.empty().

Parameters:
headName - The name of the head.
Returns:
Response for request.

sendRequestHeadCardinal

protected JSimHLAResponse sendRequestHeadCardinal(java.lang.String headName)
Sends request for head.cardinal().

Parameters:
headName - The name of the head.
Returns:
Response for request.

sendRequestHeadFirst

protected JSimHLAResponse sendRequestHeadFirst(java.lang.String headName)
Sends request for head.first().

Parameters:
headName - The name of the head.
Returns:
Response for request.

sendRequestHeadLast

protected JSimHLAResponse sendRequestHeadLast(java.lang.String headName)
Sends request for head.last().

Parameters:
headName - The name of the head.
Returns:
Response for request.

sendRequestHeadGetLw

protected JSimHLAResponse sendRequestHeadGetLw(java.lang.String headName)
Sends request for head.getLw().

Parameters:
headName - The name of the head.
Returns:
Response for request.

sendRequestHeadGetTw

protected JSimHLAResponse sendRequestHeadGetTw(java.lang.String headName)
Sends request for head.getTw().

Parameters:
headName - The name of the head.
Returns:
Response for request.

sendRequestHeadGetTwForAllLinks

protected JSimHLAResponse sendRequestHeadGetTwForAllLinks(java.lang.String headName)
Sends request for head.getTwForAllLinks().

Parameters:
headName - The name of the head.
Returns:
Response for request.

sendRequestLinkInto

protected JSimHLAResponse sendRequestLinkInto(java.lang.String headName,
                                              JSimLink link)
Sends request for link.into().

Parameters:
headName - The name of the head.
Returns:
Response for request.

receiveInteraction

protected void receiveInteraction(InteractionClassHandle interactionClass,
                                  ParameterHandleValueMap theParameters,
                                  byte[] userSuppliedTag,
                                  OrderType receivedOrdering)
Receives interaction from RTI. The interaction will be added into callback queue. All interactions in the queue will be processed after calling processInteractions(). You should never call this method.

Parameters:
interactionClass - the class of the received interaction
theParameters - the map between parameter handles and the values of the identified parameters
userSuppliedTag - a user-supplied tag associated with the interaction

processReceivedInteractions

public void processReceivedInteractions()
Performs processing of received interactions stored in interactions callback queue.


getLogicalTime

public LogicalTime getLogicalTime()
Returns federate's granted logical time.

Returns:
Federate's granted logical time.

nextMessageRequestAvailable

public void nextMessageRequestAvailable(LogicalTime theTime)
Calls service nextMessageRequestAvailable() of the RTIambassador. You should never call this method.


beginFederationExecution

protected void beginFederationExecution(int numberOfFederates,
                                        int modeEndOfSimulation)
                                 throws JSimInvalidParametersException
Begins JSim federation execution. Performs RTI ambassador initalization, creates federation execution and joins to federation execution. You should never call this method. It is called from JSimSimulation.

Parameters:
numberOfFederates - Total number of federates who are involved in federation.
modeEndOfSimulation - The mode how to terminate the HLA simulation. Possible values are HLA_END_OF_SIMULATION_RESPECT and HLA_END_OF_SIMULATION_IGNORE.
Throws:
JSimInvalidParametersException - This exception is thrown number of federates is less than two, or endOfSimulation has an unknown value.

endFederationExecution

protected void endFederationExecution(boolean destroy)
Ends JSim federation execution. Resigns from federation execution. It can also destroy federation execution. You should never call this method. It is called from JSimSimulation.

Parameters:
destroy - Determines if to destroy federation execution or not. Federation execution of JSim federation should be always destroyed. Please use false only if you know what are you doing.