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; ...@@ -20,86 +20,82 @@ import java.util.Scanner;
*/ */
public class PduListenerSaver public class PduListenerSaver
{ {
private final static String DEFAULT_OUTPUT_DIRECTORY = "pduLog"; private final static String DEFAULT_OUTPUT_DIRECTORY = "pduLog";
/** /**
* Default multicast group address we send on. * 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> */ * @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; 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> */ /** @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; public static final int DEFAULT_MULTICAST_PORT = AllPduSender.DEFAULT_MULTICAST_PORT;
private enum mystate private enum mystate
{ {
RUNNING, RUNNING,
PAUSED; PAUSED;
} }
/** /**
* Program invocation, execution starts here * Program invocation, execution starts here
* @param args command-line arguments * @param args command-line arguments
*/ */
public static void main(String[] args) public static void main(String[] args)
{ {
String outputDirectory = DEFAULT_OUTPUT_DIRECTORY; String outputDirectory = DEFAULT_OUTPUT_DIRECTORY;
String multicastAddress = DEFAULT_MULTICAST_ADDRESS; String multicastAddress = DEFAULT_MULTICAST_ADDRESS;
int multicastPort = DEFAULT_MULTICAST_PORT; 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);
}
System.out.println("Beginning PduListenerSaver (" + multicastAddress + ":" + multicastPort + ") to directory " + outputDirectory); System.out.println("OpenDis7Examples.PduListenerSaver started...");
try {
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 switch (args.length)
{ {
System.out.println("Type p/enter to pause, r/enter to resume, q/enter to quit"); case 0:
String line = terminalKeyboardScanner.nextLine(); break;
if (line.equalsIgnoreCase("p") && state == mystate.RUNNING) { case 1:
recorder.stopPause(); outputDirectory = args[0];
state = mystate.PAUSED; break;
System.out.println("... now PAUSED"); case 3:
} outputDirectory = args[0];
else if (line.equalsIgnoreCase("p")) { multicastAddress = args[1];
System.out.println("... still PAUSED"); multicastPort = Integer.parseInt(args[2]);
} break;
else if (line.equalsIgnoreCase("r") && state == mystate.PAUSED) { default:
recorder.startResume(); // Common-sense practice is to print help message if invocation is problematic
state = mystate.RUNNING; System.err.println("Usage: PduListenerSaver() or PduListenerSaver(\"outputdir\") or PduListenerSaver(\"outputDirectory\",\"multicastAddress\", multicastPort");
System.out.println("... now RUNNING"); System.exit(1);
} }
else if (line.equalsIgnoreCase("r")) { System.out.println("Beginning PduListenerSaver (" + multicastAddress + ":" + multicastPort + ") to directory " + outputDirectory);
System.out.println("... still RUNNING");
} mystate state = mystate.RUNNING;
else if (line.equalsIgnoreCase("q")) { Scanner terminalKeyboardScanner = new Scanner(System.in);
System.out.println("... QUIT"); PduRecorder recorder = new PduRecorder(outputDirectory, multicastAddress, multicastPort); // assumes save on quit
recorder.end();
break; 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("Ending PduListenerSaver pdu recording, saved to file:"); System.out.println(recorder.getLogFilePath());
System.out.println(recorder.getLogFilePath());
}
catch (IOException ex) {
System.err.println("Exception: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage());
} }
}
} }
...@@ -13,6 +13,14 @@ Program response: ...@@ -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... OpenDis7Examples.PduListenerSaver started...
Beginning PduListenerSaver (239.1.2.3:3000) to directory pduLog Beginning PduListenerSaver (239.1.2.3:3000) to directory pduLog
Recorder log file open: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog1.dislog Recorder log file open: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog1.dislog
...@@ -97,4 +105,4 @@ q ...@@ -97,4 +105,4 @@ q
Closing recorder log file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog1.dislog Closing recorder log file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog1.dislog
Ending PduListenerSaver pdu recording, saved to file: Ending PduListenerSaver pdu recording, saved to file:
C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog1.dislog 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