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

main() javadoc logging and inheritance-interoperability improvements

parent d2468a56
No related branches found
No related tags found
No related merge requests found
...@@ -16,9 +16,10 @@ import java.util.ArrayList; ...@@ -16,9 +16,10 @@ import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** The purpose of this program is to provide an easily modifiable example simulation program /** The purpose of this inheritable class is to provide an easily modifiable example simulation program
* that includes DIS-capable entities doing tasks and reporting them to the network. * that includes DIS-capable entities performing tasks of interest, and then reporting activity via PDUs
* Default settings include PDU recording turned on by default. * to the network.
* Default program initialization includes PDU recording turned on by default.
*/ */
public class ExampleSimulationProgram public class ExampleSimulationProgram
{ {
...@@ -39,7 +40,7 @@ public class ExampleSimulationProgram ...@@ -39,7 +40,7 @@ public class ExampleSimulationProgram
/** /**
* Output prefix to identify this class (override in subclass), helps with logging * Output prefix to identify this class (override in subclass), helps with logging
*/ */
private final static String TRACE_PREFIX = "[" + ExampleSimulationProgram.class.getName() + "] "; protected static String TRACE_PREFIX;
/** /**
* This runSimulationLoops() method is for you, a programmer-modifiable code block * This runSimulationLoops() method is for you, a programmer-modifiable code block
...@@ -63,8 +64,8 @@ public class ExampleSimulationProgram ...@@ -63,8 +64,8 @@ public class ExampleSimulationProgram
int simulationLoopCount = 0; // variable, initialized at 0 int simulationLoopCount = 0; // variable, initialized at 0
boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet? boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet?
// TODO reset clock to zero each time for consistent outputs // TODO reset Clock Time to today's date and timestamp to zero, providing consistent outputs for each simulation run
pduRecorder.setVerbose(true); pduRecorder.setVerbose(true);
// Your model setup: define participants. who's who in this zoo? // Your model setup: define participants. who's who in this zoo?
...@@ -72,10 +73,10 @@ public class ExampleSimulationProgram ...@@ -72,10 +73,10 @@ public class ExampleSimulationProgram
// create PDU objects and set their values. // create PDU objects and set their values.
EntityID entityID_1 = new EntityID(); EntityID entityID_1 = new EntityID();
entityID_1.setSiteID(1).setApplicationID(2).setEntityID(3); // made-up example ID; entityID_1.setSiteID(1).setApplicationID(2).setEntityID(3); // made-up example ID;
// create PDU objects and set their values.
EntityID entityID_2 = new EntityID(); EntityID entityID_2 = new EntityID();
entityID_1.setSiteID(1).setApplicationID(2).setEntityID(4); // made-up example ID; entityID_2.setSiteID(1).setApplicationID(2).setEntityID(4); // made-up example ID;
// TODO someday, use enumerations; is there a unique site triplet for MOVES Institute? // TODO someday, use enumerations; is there a unique site triplet for MOVES Institute?
EntityStatePdu entityStatePdu_1 = pduFactory.makeEntityStatePdu(); EntityStatePdu entityStatePdu_1 = pduFactory.makeEntityStatePdu();
...@@ -142,7 +143,7 @@ public class ExampleSimulationProgram ...@@ -142,7 +143,7 @@ public class ExampleSimulationProgram
// OK now send the status PDUs for this loop, and then continue // OK now send the status PDUs for this loop, and then continue
System.out.println ("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent"); System.out.println ("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent");
sendAllPdusForLoopTimestep(entityStatePdu_1, firePdu_1a, timeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); sendAllPdusForLoopTimestep(entityStatePdu_1, firePdu_1a, currentTimeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3);
sendSinglePdu(entityStatePdu_2); // me too i.e. 2! sendSinglePdu(entityStatePdu_2); // me too i.e. 2!
System.out.println ("... [PDUs successfully sent for this loop]"); System.out.println ("... [PDUs successfully sent for this loop]");
...@@ -173,11 +174,11 @@ public class ExampleSimulationProgram ...@@ -173,11 +174,11 @@ public class ExampleSimulationProgram
/* VariableRecordType enumerations have potential use with CommentPdu logs */ /* VariableRecordType enumerations have potential use with CommentPdu logs */
/* TODO contrast to EntityType */ /* TODO contrast to EntityType */
VariableRecordType descriptionComment = VariableRecordType.DESCRIPTION; VariableRecordType descriptionComment = VariableRecordType.DESCRIPTION;
VariableRecordType narrativeComment = VariableRecordType.COMPLETE_EVENT_REPORT; VariableRecordType narrativeComment = VariableRecordType.COMPLETE_EVENT_REPORT;
VariableRecordType statusComment = VariableRecordType.APPLICATION_STATUS; VariableRecordType statusComment = VariableRecordType.APPLICATION_STATUS;
VariableRecordType timeStepComment = VariableRecordType.APPLICATION_TIMESTEP; VariableRecordType currentTimeStepComment = VariableRecordType.APPLICATION_TIMESTEP;
VariableRecordType otherComment = VariableRecordType.OTHER; VariableRecordType otherComment = VariableRecordType.OTHER;
// class variables // class variables
PduFactory pduFactory = new PduFactory(); PduFactory pduFactory = new PduFactory();
...@@ -192,7 +193,7 @@ public class ExampleSimulationProgram ...@@ -192,7 +193,7 @@ public class ExampleSimulationProgram
*/ */
public ExampleSimulationProgram() public ExampleSimulationProgram()
{ {
// Constructor is under consideration. Constructor is not currently needed. // Potential constructor is under consideration. Constructor is not currently needed.
} }
/** /**
...@@ -266,7 +267,6 @@ public class ExampleSimulationProgram ...@@ -266,7 +267,6 @@ public class ExampleSimulationProgram
String outputDirectory = DEFAULT_OUTPUT_DIRECTORY; String outputDirectory = DEFAULT_OUTPUT_DIRECTORY;
System.out.println("Beginning pdu save to directory " + outputDirectory); System.out.println("Beginning pdu save to directory " + outputDirectory);
pduRecorder = new PduRecorder(outputDirectory, getNetworkAddress(), getNetworkPort()); // assumes save pduRecorder = new PduRecorder(outputDirectory, getNetworkAddress(), getNetworkPort()); // assumes save
pduRecorder.setDescriptor ("ExampleSimulationProgram pduRecorder");
pduRecorder.setEncodingPduLog(PduRecorder.ENCODING_PLAINTEXT); pduRecorder.setEncodingPduLog(PduRecorder.ENCODING_PLAINTEXT);
pduRecorder.setVerbose(true); // either sending, receiving or both pduRecorder.setVerbose(true); // either sending, receiving or both
pduRecorder.start(); // begin running pduRecorder.start(); // begin running
...@@ -275,13 +275,7 @@ public class ExampleSimulationProgram ...@@ -275,13 +275,7 @@ public class ExampleSimulationProgram
/** All done, release network resources */ /** All done, release network resources */
public void tearDownNetworkInterface() public void tearDownNetworkInterface()
{ {
pduRecorder.stop(); // handles disNetworkInterface.close() pduRecorder.stop(); // handles disNetworkInterface.close(), teards down threads and sockets
// disNetworkInterface.removeListener(pduListener);
//
// disNetworkInterface.close();
// disNetworkInterface.kill(); // renamed as close(), deprecated
// disNetworkInterface = null; // making sure no possibility of zombie process remaining...
} }
/** /**
...@@ -404,15 +398,17 @@ public class ExampleSimulationProgram ...@@ -404,15 +398,17 @@ public class ExampleSimulationProgram
*/ */
public static void main(String[] args) public static void main(String[] args)
{ {
System.out.println(TRACE_PREFIX + "main() started..."); TRACE_PREFIX = "[" + ExampleSimulationProgram.class.getName() + "] ";
// OK here we go... System.out.println(TRACE_PREFIX + "main() started...");
thisProgram = new ExampleSimulationProgram(); // creates instance of self within static main() method thisProgram = new ExampleSimulationProgram(); // creates instance of self within static main() method
thisProgram.handleArgs (args); // process command-line invocation arguments thisProgram.handleArgs (args); // process command-line invocation arguments
thisProgram.setUpNetworkInterface(); thisProgram.setUpNetworkInterface();
// thisProgram.pduRecorder.setDescriptor (TRACE_PREFIX.replace("[","").replace("]","") + " pduRecorder");
thisProgram.runSimulationLoops(); // ... your simulation execution code goes in there ... thisProgram.runSimulationLoops(); // ... your simulation execution code goes in there ...
...@@ -420,6 +416,6 @@ public class ExampleSimulationProgram ...@@ -420,6 +416,6 @@ public class ExampleSimulationProgram
System.out.println(TRACE_PREFIX + "complete."); // report successful completion System.out.println(TRACE_PREFIX + "complete."); // report successful completion
System.exit(0); // ensure all threading lets go System.exit(0); // ensure all threads and sockets released
} }
} }
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