Skip to content
Snippets Groups Projects
Commit 98659c16 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

handle IOException internally for simpler usage

parent da741484
No related branches found
No related tags found
No related merge requests found
......@@ -20,86 +20,82 @@ import java.util.Scanner;
*/
public class PduListenerSaver
{
private final static String DEFAULT_OUTPUT_DIRECTORY = "pduLog";
/**
* Default multicast group address we send on.
* @see <a href="https://en.wikipedia.org/wiki/Multicast_address">https://en.wikipedia.org/wiki/Multicast_address</a> */
public static final String DEFAULT_MULTICAST_ADDRESS = AllPduSender.DEFAULT_MULTICAST_ADDRESS;
/** @see <a href="https://en.wikipedia.org/wiki/Port_(computer_networking)">https://en.wikipedia.org/wiki/Port_(computer_networking)</a> */
public static final int DEFAULT_MULTICAST_PORT = AllPduSender.DEFAULT_MULTICAST_PORT;
private final static String DEFAULT_OUTPUT_DIRECTORY = "pduLog";
/**
* Default multicast group address we send on.
* @see <a href="https://en.wikipedia.org/wiki/Multicast_address">https://en.wikipedia.org/wiki/Multicast_address</a> */
public static final String DEFAULT_MULTICAST_ADDRESS = AllPduSender.DEFAULT_MULTICAST_ADDRESS;
/** @see <a href="https://en.wikipedia.org/wiki/Port_(computer_networking)">https://en.wikipedia.org/wiki/Port_(computer_networking)</a> */
public static final int DEFAULT_MULTICAST_PORT = AllPduSender.DEFAULT_MULTICAST_PORT;
private enum mystate
{
RUNNING,
PAUSED;
}
private enum mystate
{
RUNNING,
PAUSED;
}
/**
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public static void main(String[] args)
{
String outputDirectory = DEFAULT_OUTPUT_DIRECTORY;
String multicastAddress = DEFAULT_MULTICAST_ADDRESS;
int multicastPort = DEFAULT_MULTICAST_PORT;
System.out.println("OpenDis7Examples.PduListenerSaver started...");
switch (args.length) {
case 0:
break;
case 1:
outputDirectory = args[0];
break;
case 3:
outputDirectory = args[0];
multicastAddress = args[1];
multicastPort = Integer.parseInt(args[2]);
break;
default:
// Common-sense practice is to print help message if invocation is problematic
System.err.println("Usage: PduListenerSaver() or PduListenerSaver(\"outputdir\") or PduListenerSaver(\"outputDirectory\",\"multicastAddress\", multicastPort");
System.exit(1);
}
{
String outputDirectory = DEFAULT_OUTPUT_DIRECTORY;
String multicastAddress = DEFAULT_MULTICAST_ADDRESS;
int multicastPort = DEFAULT_MULTICAST_PORT;
System.out.println("Beginning PduListenerSaver (" + multicastAddress + ":" + multicastPort + ") to directory " + outputDirectory);
try {
mystate state = mystate.RUNNING;
Scanner terminalKeyboardScanner = new Scanner(System.in);
PduRecorder recorder = new PduRecorder(outputDirectory, multicastAddress, multicastPort); // assumes save on quit
System.out.println("OpenDis7Examples.PduListenerSaver started...");
while (true) // monitor user input via keyboard
{
System.out.println("Type p/enter to pause, r/enter to resume, q/enter to quit");
String line = terminalKeyboardScanner.nextLine();
if (line.equalsIgnoreCase("p") && state == mystate.RUNNING) {
recorder.stopPause();
state = mystate.PAUSED;
System.out.println("... now PAUSED");
}
else if (line.equalsIgnoreCase("p")) {
System.out.println("... still PAUSED");
}
else if (line.equalsIgnoreCase("r") && state == mystate.PAUSED) {
recorder.startResume();
state = mystate.RUNNING;
System.out.println("... now RUNNING");
switch (args.length)
{
case 0:
break;
case 1:
outputDirectory = args[0];
break;
case 3:
outputDirectory = args[0];
multicastAddress = args[1];
multicastPort = Integer.parseInt(args[2]);
break;
default:
// Common-sense practice is to print help message if invocation is problematic
System.err.println("Usage: PduListenerSaver() or PduListenerSaver(\"outputdir\") or PduListenerSaver(\"outputDirectory\",\"multicastAddress\", multicastPort");
System.exit(1);
}
else if (line.equalsIgnoreCase("r")) {
System.out.println("... still RUNNING");
}
else if (line.equalsIgnoreCase("q")) {
System.out.println("... QUIT");
recorder.end();
break;
System.out.println("Beginning PduListenerSaver (" + multicastAddress + ":" + multicastPort + ") to directory " + outputDirectory);
mystate state = mystate.RUNNING;
Scanner terminalKeyboardScanner = new Scanner(System.in);
PduRecorder recorder = new PduRecorder(outputDirectory, multicastAddress, multicastPort); // assumes save on quit
while (true) // monitor user input via keyboard
{
System.out.println("Type p/enter to pause, r/enter to resume, q/enter to quit");
String line = terminalKeyboardScanner.nextLine();
if (line.equalsIgnoreCase("p") && state == mystate.RUNNING) {
recorder.stopPause();
state = mystate.PAUSED;
System.out.println("... now PAUSED");
}
else if (line.equalsIgnoreCase("p")) {
System.out.println("... still PAUSED");
}
else if (line.equalsIgnoreCase("r") && state == mystate.PAUSED) {
recorder.startResume();
state = mystate.RUNNING;
System.out.println("... now RUNNING");
}
else if (line.equalsIgnoreCase("r")) {
System.out.println("... still RUNNING");
}
else if (line.equalsIgnoreCase("q")) {
System.out.println("... QUIT");
recorder.end();
break;
}
}
}
System.out.println("Ending PduListenerSaver pdu recording, saved to file:");
System.out.println(recorder.getLogFilePath());
}
catch (IOException ex) {
System.err.println("Exception: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage());
System.out.println("Ending PduListenerSaver pdu recording, saved to file:");
System.out.println(recorder.getLogFilePath());
}
}
}
......@@ -13,6 +13,14 @@ Program response:
===================================================
ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=OpenDis7Examples/PduListenerSaver.java -Drun.class=OpenDis7Examples.PduListenerSaver run-single
init:
Deleting: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties
deps-jar:
Updating property file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties
Compiling 1 source file to C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes
compile-single:
run-single:
OpenDis7Examples.PduListenerSaver started...
Beginning PduListenerSaver (239.1.2.3:3000) to directory pduLog
Recorder log file open: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog1.dislog
......@@ -97,4 +105,4 @@ q
Closing recorder log file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog1.dislog
Ending PduListenerSaver pdu recording, saved to file:
C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog1.dislog
BUILD SUCCESSFUL (total time: 1 minute 0 seconds)
BUILD SUCCESSFUL (total time: 32 seconds)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment