Class DisChannel

java.lang.Object
edu.nps.moves.dis7.utilities.DisChannel

public class DisChannel extends Object
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.
Author:
brutzman
See Also:
  • Field Details

    • descriptor

      protected String descriptor
      Output prefix to help with logging by identifying this class.
    • DEFAULT_PDULOG_OUTPUT_DIRECTORY

      protected static final String DEFAULT_PDULOG_OUTPUT_DIRECTORY
      default directory for PDULOG files
      See Also:
    • disNetworkInterface

      protected DisThreadedNetworkInterface disNetworkInterface
      Common thread-safe interface for low-level networking
    • pduRecorder

      protected PduRecorder pduRecorder
      utility class for recording PDUs
    • COMMENTPDU_DESCRIPTION

      public static final VariableRecordType COMMENTPDU_DESCRIPTION
      CommentPdu type providing a description, used for consistent reporting and logging.
    • COMMENTPDU_NARRATIVE

      public static final VariableRecordType COMMENTPDU_NARRATIVE
      CommentPdu type providing an event report, used for consistent reporting and logging.
    • COMMENTPDU_APPLICATION_STATUS

      public static final VariableRecordType COMMENTPDU_APPLICATION_STATUS
      CommentPdu type providing simulation program status, used for consistent reporting and logging.
    • COMMENTPDU_ELAPSED_TIME

      public static final VariableRecordType COMMENTPDU_ELAPSED_TIME
      CommentPdu type documenting current elapsed time, used for consistent reporting and logging.
    • COMMENTPDU_SIMULATION_TIMESTEP

      public static final VariableRecordType COMMENTPDU_SIMULATION_TIMESTEP
      CommentPdu type documenting simulation program timestep, used for consistent reporting and logging.
    • COMMENTPDU_TIME

      public static final VariableRecordType COMMENTPDU_TIME
      CommentPdu type documenting simulation program time, used for consistent reporting and logging.
    • COMMENTPDU_CURRENT_WAYPOINT_NUMBER

      public static final VariableRecordType COMMENTPDU_CURRENT_WAYPOINT_NUMBER
      CommentPdu type documenting current waypoint number, used for consistent reporting and logging.
  • Constructor Details

    • DisChannel

      public DisChannel()
      Base constructor
    • DisChannel

      public DisChannel(String initialDescriptor)
      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 verbose
      verbosenessPduRecorder - whether PduRecorder is initially verbose
    • DisChannel

      public DisChannel(String initialDescriptor, boolean verbosenessDisNetworkInterface, boolean verbosenessPduRecorder)
      Constructor with new descriptor, verboseness
      Parameters:
      initialDescriptor - descriptor for this instance
      verbosenessDisNetworkInterface - whether channel is initially verbose
      verbosenessPduRecorder - whether PduRecorder is initially verbose
  • Method Details

    • addEntity

      public void addEntity(EntityID newEntity)
      Add entity using SimulationManager
      Parameters:
      newEntity - new entity to add with announcement by SimulationManager
    • removeEntity

      public void removeEntity(EntityID entity)
      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

      public String getNetworkAddress()
      get current networkAddress as a string
      Returns:
      the networkAddress
    • setNetworkAddress

      public final void setNetworkAddress(String newNetworkAddress)
      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

      public DisTime.TimestampStyle getTimestampStyle()
      Get timestampStyle used by PduFactory
      Returns:
      current timestampStyle
    • setTimestampStyle

      public void setTimestampStyle(DisTime.TimestampStyle newTimestampStyle)
      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

      public void sendSinglePdu(Pdu pdu)
      Send a single Protocol Data Unit (PDU) of any type, using timestamp value already provided in PDU
      Parameters:
      pdu - the pdu to send
    • sendSinglePdu

      public void sendSinglePdu(double timestampSeconds, Pdu pdu)
      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 epoch
      pdu - the pdu to send
    • sendSinglePduDelayed

      public void sendSinglePduDelayed(Pdu pdu, long delayTimeMilliseconds)
      Send a single Protocol Data Unit (PDU) of any type following a real-time delay
      Parameters:
      pdu - the pdu to send
      delayTimeMilliseconds - 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 epoch
      commentType - enumeration value describing purpose of the narrative comment
      comments - String array of narrative comments
      Returns:
      constructed CommentPdu if sent, null otherwise
      See Also:
    • sendCommentPdu

      public CommentPdu sendCommentPdu(VariableRecordType commentType, String... comments)
      Send Comment PDU using current DIS timestamp
      Parameters:
      commentType - enumeration value describing purpose of the narrative comment
      comments - 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 comment
      delayTimeMilliseconds - delay before sending
      comments - 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

      public String getTRACE_PREFIX()
      Get prefix string used in trace messages
      Returns:
      the TRACE_PREFIX
    • setTRACE_PREFIX

      public final void setTRACE_PREFIX(String newTRACE_PREFIX)
      Set prefix string used in trace messages
      Parameters:
      newTRACE_PREFIX - the TRACE_PREFIX to set
    • printTRACE

      public void printTRACE(String message)
      Print message with TRACE_PREFIX prepended
      Parameters:
      message - String to print
    • printlnTRACE

      public void printlnTRACE(String message)
      Print message with TRACE_PREFIX prepended
      Parameters:
      message - String to print
    • getPduFactory

      public PduFactory getPduFactory()
      Get link to an already-created PduFactory
      Returns:
      the pduFactory, simplifying program imports and configuration
    • getDisNetworkInterface

      public DisThreadedNetworkInterface getDisNetworkInterface()
      Get reference to current singleton DisThreadedNetworkInterface
      Returns:
      the disNetworkInterface
    • getThisHostName

      public static String getThisHostName()
      Get current host name
      Returns:
      the thisHostName
    • setThisHostName

      public static void setThisHostName(String aThisHostName)
      Override and set current host name
      Parameters:
      aThisHostName - the thisHostName to set
    • getPduRecorder

      public PduRecorder getPduRecorder()
      Get link to an already-created PduRecorder connected to current disThreadedInterface
      Returns:
      the pduRecorder
    • getDescriptor

      public String getDescriptor()
      Get simple descriptor (such as parent class name) for this network interface, used in trace statements
      Returns:
      simple descriptor name
    • setDescriptor

      public void setDescriptor(String newDescriptor)
      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