Class DisChannel
java.lang.Object
edu.nps.moves.dis7.utilities.DisChannel
DisChannel integrates multiple utility capabilities to handle most networking and entity-management tasks.
Provides a simplified interface wrapping DisThreadedNetworkInterface, PduRecorder, and SimulationManager
for programs connecting to OpenDis7 communications. This lets library users avoid handling of network threads.
TODO future work will confirm that multiple different DisChannel connections can be used simultaneously by a parent program.
TODO future work will confirm that multiple different DisChannel connections can be used simultaneously by a parent program.
- Author:
- brutzman
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final VariableRecordType
CommentPdu type providing simulation program status, used for consistent reporting and logging.static final VariableRecordType
CommentPdu type documenting current waypoint number, used for consistent reporting and logging.static final VariableRecordType
CommentPdu type providing a description, used for consistent reporting and logging.static final VariableRecordType
CommentPdu type documenting current elapsed time, used for consistent reporting and logging.static final VariableRecordType
CommentPdu type providing an event report, used for consistent reporting and logging.static final VariableRecordType
CommentPdu type documenting simulation program timestep, used for consistent reporting and logging.static final VariableRecordType
CommentPdu type documenting simulation program time, used for consistent reporting and logging.protected static final String
default directory for PDULOG filesprotected String
Output prefix to help with logging by identifying this class.protected DisThreadedNetworkInterface
Common thread-safe interface for low-level networkingprotected PduRecorder
utility class for recording PDUs -
Constructor Summary
ConstructorsConstructorDescriptionBase constructorDisChannel
(boolean verbosenessDisNetworkInterface, boolean verbosenessPduRecorder) Constructor with new verbosenessDisChannel
(String initialDescriptor) Constructor with new descriptorDisChannel
(String initialDescriptor, boolean verbosenessDisNetworkInterface, boolean verbosenessPduRecorder) Constructor with new descriptor, verboseness -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add entity using SimulationManagerGet simple descriptor (such as parent class name) for this network interface, used in trace statementsGet reference to current singleton DisThreadedNetworkInterfaceget current networkAddress as a stringint
get current networkPortGet link to an already-created PduFactoryGet link to an already-created PduRecorder connected to current disThreadedInterfacestatic String
Get current host nameGet timestampStyle used by PduFactoryGet prefix string used in trace messagesboolean
whether in verboseComments modeboolean
Get whether DisNetworkInterface setting is verboseboolean
Get whether PduRecorder setting is verbosevoid
join()
Join DIS channel using SimulationManagervoid
leave()
Leave DIS channel using SimulationManagervoid
printlnTRACE
(String message) Print message with TRACE_PREFIX prependedvoid
printTRACE
(String message) Print message with TRACE_PREFIX prependedvoid
removeEntity
(EntityID entity) Remove entity using SimulationManagersendCommentPdu
(double timestampSeconds, VariableRecordType commentType, String... comments) Send Comment PDU using given DIS time in seconds, after setting the PDU with given timestamp in secondssendCommentPdu
(VariableRecordType commentType, String... comments) Send Comment PDU using current DIS timestampvoid
sendCommentPduDelayed
(VariableRecordType commentType, long delayTimeMilliseconds, String... comments) Send Comment PDU following time delayvoid
sendSinglePdu
(double timestampSeconds, Pdu pdu) Send a single Protocol Data Unit (PDU) of any type, after setting the PDU with given timestamp in secondsvoid
sendSinglePdu
(Pdu pdu) Send a single Protocol Data Unit (PDU) of any type, using timestamp value already provided in PDUvoid
sendSinglePduDelayed
(Pdu pdu, long delayTimeMilliseconds) Send a single Protocol Data Unit (PDU) of any type following a real-time delayvoid
setDescriptor
(String newDescriptor) Set new simple descriptor (such as parent class name) for this network interface, used in trace statementsfinal void
setNetworkAddress
(String newNetworkAddress) set current networkAddress using a stringfinal void
setNetworkPort
(int newNetworkPort) set current networkPortstatic void
setThisHostName
(String aThisHostName) Override and set current host namevoid
setTimestampStyle
(DisTime.TimestampStyle newTimestampStyle) Set timestampStyle used by PduFactoryfinal void
setTRACE_PREFIX
(String newTRACE_PREFIX) Set prefix string used in trace messagesvoid
Initialize network interface, choosing best available network interface.void
setVerboseComments
(boolean newVerboseComments) set verboseComments modevoid
setVerboseDisNetworkInterface
(boolean verboseDisNetworkInterface) Set whether DisNetworkInterface setting is verbosevoid
setVerbosePduRecorder
(boolean verbosePduRecorder) Set whether PduRecorder setting is verbosevoid
All done, release network resources
-
Field Details
-
descriptor
Output prefix to help with logging by identifying this class. -
DEFAULT_PDULOG_OUTPUT_DIRECTORY
default directory for PDULOG files- See Also:
-
disNetworkInterface
Common thread-safe interface for low-level networking -
pduRecorder
utility class for recording PDUs -
COMMENTPDU_DESCRIPTION
CommentPdu type providing a description, used for consistent reporting and logging. -
COMMENTPDU_NARRATIVE
CommentPdu type providing an event report, used for consistent reporting and logging. -
COMMENTPDU_APPLICATION_STATUS
CommentPdu type providing simulation program status, used for consistent reporting and logging. -
COMMENTPDU_ELAPSED_TIME
CommentPdu type documenting current elapsed time, used for consistent reporting and logging. -
COMMENTPDU_SIMULATION_TIMESTEP
CommentPdu type documenting simulation program timestep, used for consistent reporting and logging. -
COMMENTPDU_TIME
CommentPdu type documenting simulation program time, used for consistent reporting and logging. -
COMMENTPDU_CURRENT_WAYPOINT_NUMBER
CommentPdu type documenting current waypoint number, used for consistent reporting and logging.
-
-
Constructor Details
-
DisChannel
public DisChannel()Base constructor -
DisChannel
Constructor with new descriptor- Parameters:
initialDescriptor
- descriptor for this instance
-
DisChannel
public DisChannel(boolean verbosenessDisNetworkInterface, boolean verbosenessPduRecorder) Constructor with new verboseness- Parameters:
verbosenessDisNetworkInterface
- whether channel is initially verboseverbosenessPduRecorder
- whether PduRecorder is initially verbose
-
DisChannel
public DisChannel(String initialDescriptor, boolean verbosenessDisNetworkInterface, boolean verbosenessPduRecorder) Constructor with new descriptor, verboseness- Parameters:
initialDescriptor
- descriptor for this instanceverbosenessDisNetworkInterface
- whether channel is initially verboseverbosenessPduRecorder
- whether PduRecorder is initially verbose
-
-
Method Details
-
addEntity
Add entity using SimulationManager- Parameters:
newEntity
- new entity to add with announcement by SimulationManager
-
removeEntity
Remove entity using SimulationManager- Parameters:
entity
- entity to remove with announcement by SimulationManager
-
join
public void join()Join DIS channel using SimulationManager -
leave
public void leave()Leave DIS channel using SimulationManager -
getNetworkAddress
get current networkAddress as a string- Returns:
- the networkAddress
-
setNetworkAddress
set current networkAddress using a string- Parameters:
newNetworkAddress
- the networkAddress to set
-
getNetworkPort
public int getNetworkPort()get current networkPort- Returns:
- the networkPort
-
setNetworkPort
public final void setNetworkPort(int newNetworkPort) set current networkPort- Parameters:
newNetworkPort
- the networkPort to set
-
getTimestampStyle
Get timestampStyle used by PduFactory- Returns:
- current timestampStyle
-
setTimestampStyle
Set timestampStyle used by PduFactory- Parameters:
newTimestampStyle
- the timestampStyle to set
-
setUpNetworkInterface
public void setUpNetworkInterface()Initialize network interface, choosing best available network interface. Singleton pattern. -
tearDownNetworkInterface
public void tearDownNetworkInterface()All done, release network resources -
sendSinglePdu
Send a single Protocol Data Unit (PDU) of any type, using timestamp value already provided in PDU- Parameters:
pdu
- the pdu to send
-
sendSinglePdu
Send a single Protocol Data Unit (PDU) of any type, after setting the PDU with given timestamp in seconds- Parameters:
timestampSeconds
- timestamp to set for this PDU, seconds since epochpdu
- the pdu to send
-
sendSinglePduDelayed
Send a single Protocol Data Unit (PDU) of any type following a real-time delay- Parameters:
pdu
- the pdu to senddelayTimeMilliseconds
- delay before sending
-
sendCommentPdu
public CommentPdu sendCommentPdu(double timestampSeconds, VariableRecordType commentType, String... comments) Send Comment PDU using given DIS time in seconds, after setting the PDU with given timestamp in seconds- Parameters:
timestampSeconds
- timestamp to set for this PDU, seconds since epochcommentType
- enumeration value describing purpose of the narrative commentcomments
- String array of narrative comments- Returns:
- constructed CommentPdu if sent, null otherwise
- See Also:
-
sendCommentPdu
Send Comment PDU using current DIS timestamp- Parameters:
commentType
- enumeration value describing purpose of the narrative commentcomments
- String array of narrative comments- Returns:
- constructed CommentPdu if sent, null otherwise
- See Also:
-
sendCommentPduDelayed
public void sendCommentPduDelayed(VariableRecordType commentType, long delayTimeMilliseconds, String... comments) Send Comment PDU following time delay- Parameters:
commentType
- enumeration value describing purpose of the narrative commentdelayTimeMilliseconds
- delay before sendingcomments
- String array of narrative comments- See Also:
-
isVerboseComments
public boolean isVerboseComments()whether in verboseComments mode- Returns:
- whether verboseComments mode is enabled
-
setVerboseComments
public void setVerboseComments(boolean newVerboseComments) set verboseComments mode- Parameters:
newVerboseComments
- whether verboseComments mode is enabled
-
getTRACE_PREFIX
-
setTRACE_PREFIX
Set prefix string used in trace messages- Parameters:
newTRACE_PREFIX
- the TRACE_PREFIX to set
-
printTRACE
Print message with TRACE_PREFIX prepended- Parameters:
message
- String to print
-
printlnTRACE
Print message with TRACE_PREFIX prepended- Parameters:
message
- String to print
-
getPduFactory
Get link to an already-created PduFactory- Returns:
- the pduFactory, simplifying program imports and configuration
-
getDisNetworkInterface
Get reference to current singleton DisThreadedNetworkInterface- Returns:
- the disNetworkInterface
-
getThisHostName
-
setThisHostName
Override and set current host name- Parameters:
aThisHostName
- the thisHostName to set
-
getPduRecorder
Get link to an already-created PduRecorder connected to current disThreadedInterface- Returns:
- the pduRecorder
-
getDescriptor
Get simple descriptor (such as parent class name) for this network interface, used in trace statements- Returns:
- simple descriptor name
-
setDescriptor
Set new simple descriptor (such as parent class name) for this network interface, used in trace statements- Parameters:
newDescriptor
- simple descriptor name for this interface
-
isVerboseDisNetworkInterface
public boolean isVerboseDisNetworkInterface()Get whether DisNetworkInterface setting is verbose- Returns:
- the verboseDisNetworkInterface
-
setVerboseDisNetworkInterface
public void setVerboseDisNetworkInterface(boolean verboseDisNetworkInterface) Set whether DisNetworkInterface setting is verbose- Parameters:
verboseDisNetworkInterface
- the verboseDisNetworkInterface to set
-
isVerbosePduRecorder
public boolean isVerbosePduRecorder()Get whether PduRecorder setting is verbose- Returns:
- the verbosePduRecorder
-
setVerbosePduRecorder
public void setVerbosePduRecorder(boolean verbosePduRecorder) Set whether PduRecorder setting is verbose- Parameters:
verbosePduRecorder
- the verbosePduRecorder to set
-