Class PduRecorder

java.lang.Object
edu.nps.moves.dis7.utilities.stream.PduRecorder
All Implemented Interfaces:
PduReceiver

public class PduRecorder extends Object implements PduReceiver
Utility to save PDUs received over the network to disk
Author:
Mike Bailey, jmbailey@nps.edu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static String
    Character sentinel indicating remainder of line is a comment
    static String
    Default multicast group address 239.1.2.3 for send and receive connections.
    static int
    Default socket port 3000, matches Wireshark DIS capture default
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor that uses default values for output directory, DIS address and port.
    PduRecorder​(String initialOutputDirectory)
    Constructor to let the use specify an output directory.
    PduRecorder​(String initialOutputDirectory, String initialAddress, int initialPort)
    Constructor to let the user specify all required parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    Get current multicast (or unicast) network address for send and receive connections.
    Get simple descriptor (such as parent class name) for this network interface, used in trace statements
     
    Retrieve the path to the log file
    static String
    TODO change this to enumeration type for strictness
    int
    Get network port used, multicast or unicast.
    boolean
     
    static void
    main​(String[] args)
    Entry point invocation.
    void
    Pause operation of this instance
    void
    receivePdu​(byte[] newBuffer, int newLength)
    receivePdu from DIS data stream
    void
    Resume instance operation
    void
    setAddress​(String newAddress)
    Network address for send and receive connections.
    void
    setDescriptor​(String newDescriptor)
    Set new simple descriptor (such as parent class name) for this network interface, used in trace statements
    static void
    setPduLogEncoding​(String newPduLogEncoding)
     
    void
    setPort​(int newPortValue)
    /** Set network port used, multicast or unicast.
    void
    Start instance operation
    End operation of this instance, removing interfaces

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • PduRecorder

      public PduRecorder() throws IOException
      Default constructor that uses default values for output directory, DIS address and port. Each instance must invoke start() to begin operations, pause() to suspend operations, resume() to continue operations, and stop() to terminate operations.
      Throws:
      IOException - if something goes wrong during instantiation
    • PduRecorder

      public PduRecorder(String initialOutputDirectory) throws IOException
      Constructor to let the use specify an output directory. Uses default values for multicast address and port. Each instance must invoke start() to begin operations, pause() to suspend operations, resume() to continue operations, and stop() to terminate operations.
      Parameters:
      initialOutputDirectory - the directory to write log files to
      Throws:
      IOException - if something goes wrong during instantiation
    • PduRecorder

      public PduRecorder(String initialOutputDirectory, String initialAddress, int initialPort)
      Constructor to let the user specify all required parameters. Each instance must invoke start() to begin operations, pause() to suspend operations, resume() to continue operations, and stop() to terminate operations..
      Parameters:
      initialOutputDirectory - local path for directory where the log files are written
      initialAddress - multicast group address to receive data from (TODO allow unicast UDP)
      initialPort - UDP port to listen for data
  • Method Details

    • getPduLogEncoding

      public static String getPduLogEncoding()
      TODO change this to enumeration type for strictness
      Returns:
      the pduLogEncoding
    • setPduLogEncoding

      public static void setPduLogEncoding(String newPduLogEncoding)
      Parameters:
      newPduLogEncoding - the pduLogEncoding to set
    • resume

      public void resume()
      Resume instance operation
      See Also:
      start(), stop(), pause()
    • start

      public void start()
      Start instance operation
      See Also:
      stop(), pause(), resume()
    • pause

      public void pause()
      Pause operation of this instance
      See Also:
      start(), stop(), resume()
    • stop

      public File stop()
      End operation of this instance, removing interfaces
      Returns:
      recorder logFile
      See Also:
      start(), pause(), resume()
    • receivePdu

      public void receivePdu(byte[] newBuffer, int newLength)
      receivePdu from DIS data stream
      Specified by:
      receivePdu in interface PduReceiver
      Parameters:
      newBuffer - byte array for receiving data
      newLength - length of byte array
    • getLogFilePath

      public String getLogFilePath()
      Retrieve the path to the log file
      Returns:
      the path to the log file
    • getDisThreadedNetworkInterface

      public DisThreadedNetworkInterface getDisThreadedNetworkInterface()
      Returns:
      an instance of this DisThreadedNetworkInterface
    • isRunning

      public boolean isRunning()
      Returns:
      the pduRecorderRunning
    • main

      public static void main(String[] args)
      Entry point invocation. Saves a PDU output log to ./pduLog. Invoking the edu.nps.moves.dis7.examples.PduReaderPlayer will playback all logs written to the log directory
      Parameters:
      args - none supported, TODO offer path/filename
    • getAddress

      public String getAddress()
      Get current multicast (or unicast) network address for send and receive connections.
      Returns:
      current multicast address value
      See Also:
      https://en.wikipedia.org/wiki/Multicast_address
    • setAddress

      public void setAddress(String newAddress)
      Network address for send and receive connections.
      Parameters:
      newAddress - the new network address to set
      See Also:
      https://en.wikipedia.org/wiki/Multicast_address
    • getPort

      public int getPort()
      Get network port used, multicast or unicast.
      Returns:
      current port value
      See Also:
      https://en.wikipedia.org/wiki/Port_(computer_networking)
    • setPort

      public void setPort(int newPortValue)
      /** Set network port used, multicast or unicast.
      Parameters:
      newPortValue - the disPort value to set
      See Also:
      https://en.wikipedia.org/wiki/Port_(computer_networking)
    • 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