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

numerous improvements working with DisThreadedNetworkInterface; now an...

numerous improvements working with DisThreadedNetworkInterface; now an implementable superclass for easy extensions
parent b70d4440
No related branches found
No related tags found
No related merge requests found
...@@ -7,8 +7,8 @@ package OpenDis7Examples; ...@@ -7,8 +7,8 @@ package OpenDis7Examples;
import edu.nps.moves.dis7.entities.swe.platform.surface._001Poseidon; import edu.nps.moves.dis7.entities.swe.platform.surface._001Poseidon;
import edu.nps.moves.dis7.entities.swe.platform.surface._002Triton; import edu.nps.moves.dis7.entities.swe.platform.surface._002Triton;
import edu.nps.moves.dis7.enumerations.*; // match any import edu.nps.moves.dis7.enumerations.*;
import edu.nps.moves.dis7.pdus.*; // match any of the PDU classes, easier than listing individually import edu.nps.moves.dis7.pdus.*;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface; import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import edu.nps.moves.dis7.utilities.PduFactory; import edu.nps.moves.dis7.utilities.PduFactory;
import edu.nps.moves.dis7.utilities.stream.PduRecorder; import edu.nps.moves.dis7.utilities.stream.PduRecorder;
...@@ -80,11 +80,14 @@ public class ExampleSimulationProgram ...@@ -80,11 +80,14 @@ public class ExampleSimulationProgram
entityStatePdu_1.setEntityID(entityID_1); entityStatePdu_1.setEntityID(entityID_1);
entityStatePdu_1.setForceId(ForceID.FRIENDLY); entityStatePdu_1.setForceId(ForceID.FRIENDLY);
entityStatePdu_1.setEntityType(new _001Poseidon()); // note import statement above entityStatePdu_1.setEntityType(new _001Poseidon()); // note import statement above
entityStatePdu_1.setMarking("Entity #1");
entityStatePdu_1.getMarkingString(); // check
EntityStatePdu entityStatePdu_2 = pduFactory.makeEntityStatePdu(); EntityStatePdu entityStatePdu_2 = pduFactory.makeEntityStatePdu();
entityStatePdu_2.setEntityID(entityID_2); entityStatePdu_2.setEntityID(entityID_2);
entityStatePdu_2.setForceId(ForceID.OPPOSING); entityStatePdu_2.setForceId(ForceID.OPPOSING);
entityStatePdu_2.setEntityType(new _002Triton()); // note import statement above entityStatePdu_2.setEntityType(new _002Triton()); // note import statement above
entityStatePdu_2.setMarking("Entity #2");
FirePdu firePdu_1a = pduFactory.makeFirePdu(); // for entity 1 first weapon (if any) FirePdu firePdu_1a = pduFactory.makeFirePdu(); // for entity 1 first weapon (if any)
// FirePdu firePdu_1b = pduFactory.makeFirePdu(); // for entity 1 second weapon (if any) // FirePdu firePdu_1b = pduFactory.makeFirePdu(); // for entity 1 second weapon (if any)
...@@ -270,11 +273,11 @@ public class ExampleSimulationProgram ...@@ -270,11 +273,11 @@ public class ExampleSimulationProgram
/** All done, release network resources */ /** All done, release network resources */
public void tearDownNetworkInterface() public void tearDownNetworkInterface()
{ {
pduRecorder.stop(); pduRecorder.stop(); // handles disNetworkInterface.close()
disNetworkInterface.removeListener(pduListener); // disNetworkInterface.removeListener(pduListener);
//
disNetworkInterface.close(); // disNetworkInterface.close();
// disNetworkInterface.kill(); // renamed as close(), deprecated // disNetworkInterface.kill(); // renamed as close(), deprecated
// disNetworkInterface = null; // making sure no possibility of zombie process remaining... // disNetworkInterface = null; // making sure no possibility of zombie process remaining...
} }
...@@ -352,32 +355,59 @@ public class ExampleSimulationProgram ...@@ -352,32 +355,59 @@ public class ExampleSimulationProgram
} }
} }
} }
/** /**
* Main method is first executed when a program instance is loaded. * @return whether verboseComments mode is enabled
* @see <a href="https://docs.oracle.com/javase/tutorial/getStarted/application/index.html">Java Tutorials: A Closer Look at the "Hello World!" Application</a>
* @param args command-line arguments are an array of optional String parameters that are passed from execution environment during invocation
*/ */
public static void main(String[] args) public boolean isVerboseComments() {
return verboseComments;
}
/**
* @param newVerboseComments whether verboseComments mode is enabled
*/
public void setVerboseComments(boolean newVerboseComments) {
this.verboseComments = newVerboseComments;
}
/**
* Initial execution via main() method: handle args array of initialization arguments here
* @param args command-line parameters: network address and port
*/
private static void handleArgs (String[] args)
{ {
System.out.println(TRACE_PREFIX + "main() started...");
ExampleSimulationProgram thisProgram = new ExampleSimulationProgram(); // creates instance within static main() method
// initial execution: handle args array of initialization arguments here // initial execution: handle args array of initialization arguments here
if (args.length == 2) if (args.length == 2)
{ {
if ((args[0] != null) && !args[0].isEmpty()) if ((args[0] != null) && !args[0].isEmpty())
thisProgram.setNetworkAddress(args[0]); thisProgram.setNetworkAddress(args[0]);
if ((args[1] != null) && !args[1].isEmpty()) if ((args[1] != null) && !args[1].isEmpty())
thisProgram.setNetworkPort(Integer.parseInt(args[1])); thisProgram.setNetworkPort(Integer.parseInt(args[1]));
} }
else if (args.length != 0) else if (args.length != 0)
{ {
System.err.println("Usage: " + thisProgram.getClass().getSimpleName() + " [address port]"); System.err.println("Usage: " + thisProgram.getClass().getSimpleName() + " [address port]");
System.exit(-1); System.exit(-1);
} }
}
/** Locally instantiable copy of program, can be subclassed. */
protected static ExampleSimulationProgram thisProgram;
/**
* Main method is first executed when a program instance is loaded.
* @see <a href="https://docs.oracle.com/javase/tutorial/getStarted/application/index.html">Java Tutorials: A Closer Look at the "Hello World!" Application</a>
* @param args command-line parameters: network address and port.
* Command-line arguments are an array of optional String parameters that are passed from execution environment during invocation
*/
public static void main(String[] args)
{
System.out.println(TRACE_PREFIX + "main() started...");
thisProgram = new ExampleSimulationProgram(); // creates instance of self within static main() method
handleArgs (args);
// OK here we go... // OK here we go...
thisProgram.setUpNetworkInterface(); thisProgram.setUpNetworkInterface();
...@@ -388,18 +418,4 @@ public class ExampleSimulationProgram ...@@ -388,18 +418,4 @@ public class ExampleSimulationProgram
System.out.println(TRACE_PREFIX + "complete."); // report successful completion System.out.println(TRACE_PREFIX + "complete."); // report successful completion
} }
/**
* @return whether verboseComments mode is enabled
*/
public boolean isVerboseComments() {
return verboseComments;
}
/**
* @param newVerboseComments whether verboseComments mode is enabled
*/
public void setVerboseComments(boolean newVerboseComments) {
this.verboseComments = newVerboseComments;
}
} }
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