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

refactor rename for clairty

parent c7791d2d
No related branches found
No related tags found
No related merge requests found
...@@ -16,17 +16,16 @@ import java.net.UnknownHostException; ...@@ -16,17 +16,16 @@ import java.net.UnknownHostException;
* *
* @author brutzman * @author brutzman
*/ */
public class OpenDis7NetworkCapabilities { public class ChannelOpenDis7 {
static final String NETWORK_ADDRESS_DEFAULT = "239.1.2.3";
static final int NETWORK_PORT_DEFAULT = 3000;
String thisHostName = "localhost";
String DEFAULT_PDULOG_OUTPUT_DIRECTORY = "./pduLog";
/** /**
* Output prefix to help with logging by identifying this class (can be overridden in subclass). * Output prefix to help with logging by identifying this class.
*/ */
protected static String TRACE_PREFIX; private static String TRACE_PREFIX = "[OpenDis7]";
static String thisHostName = "localhost";
private static final String NETWORK_ADDRESS_DEFAULT = "239.1.2.3";
private static final int NETWORK_PORT_DEFAULT = 3000;
private static final String DEFAULT_PDULOG_OUTPUT_DIRECTORY = "./pduLog";
protected boolean verboseComments = true; protected boolean verboseComments = true;
String networkAddress = NETWORK_ADDRESS_DEFAULT; String networkAddress = NETWORK_ADDRESS_DEFAULT;
int networkPort = NETWORK_PORT_DEFAULT; int networkPort = NETWORK_PORT_DEFAULT;
...@@ -38,7 +37,7 @@ public class OpenDis7NetworkCapabilities { ...@@ -38,7 +37,7 @@ public class OpenDis7NetworkCapabilities {
Pdu receivedPdu; Pdu receivedPdu;
PduRecorder pduRecorder; PduRecorder pduRecorder;
public OpenDis7NetworkCapabilities() public ChannelOpenDis7()
{ {
DisTime.setTimestampStyle(timestampStyle); // DISTime is a singleton shared class DisTime.setTimestampStyle(timestampStyle); // DISTime is a singleton shared class
...@@ -131,6 +130,24 @@ public class OpenDis7NetworkCapabilities { ...@@ -131,6 +130,24 @@ public class OpenDis7NetworkCapabilities {
pduRecorder.stop(); // handles disNetworkInterface.close(), tears down threads and sockets pduRecorder.stop(); // handles disNetworkInterface.close(), tears down threads and sockets
} }
/**
* Send a single Protocol Data Unit (PDU) of any type
* @param pdu the pdu to send
*/
protected void sendSinglePdu(Pdu pdu)
{
try
{
disNetworkInterface.send(pdu);
Thread.sleep(100); // TODO consider refactoring the wait logic and moving externally
}
catch (InterruptedException ex)
{
System.err.println(this.getClass().getName() + " Error sending PDU: " + ex.getLocalizedMessage());
System.exit(1);
}
}
/** /**
* test for verboseComments mode * test for verboseComments mode
* @return whether verboseComments mode is enabled * @return whether verboseComments mode is enabled
...@@ -146,5 +163,33 @@ public class OpenDis7NetworkCapabilities { ...@@ -146,5 +163,33 @@ public class OpenDis7NetworkCapabilities {
public void setVerboseComments(boolean newVerboseComments) { public void setVerboseComments(boolean newVerboseComments) {
this.verboseComments = newVerboseComments; this.verboseComments = newVerboseComments;
} }
/**
* @return the TRACE_PREFIX
*/
public static String getTRACE_PREFIX() {
return TRACE_PREFIX;
}
/**
* @param aTRACE_PREFIX the TRACE_PREFIX to set
*/
public static void setTRACE_PREFIX(String aTRACE_PREFIX) {
TRACE_PREFIX = aTRACE_PREFIX;
}
/**
* Print message with TRACE_PREFIX prepended
* @param message String to print
*/
public void printTRACE(String message) {
System.out.print(TRACE_PREFIX + message);
}
/**
* Print message with TRACE_PREFIX prepended
* @param message String to print
*/
public void printlnTRACE(String message) {
System.out.println(TRACE_PREFIX + message);
}
} }
...@@ -9,12 +9,7 @@ import edu.nps.moves.dis7.entities.swe.platform.surface._001Poseidon; ...@@ -9,12 +9,7 @@ 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.*; import edu.nps.moves.dis7.enumerations.*;
import edu.nps.moves.dis7.pdus.*; import edu.nps.moves.dis7.pdus.*;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import edu.nps.moves.dis7.utilities.DisTime;
import edu.nps.moves.dis7.utilities.PduFactory; import edu.nps.moves.dis7.utilities.PduFactory;
import edu.nps.moves.dis7.utilities.stream.PduRecorder;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -25,7 +20,7 @@ import java.util.logging.Logger; ...@@ -25,7 +20,7 @@ import java.util.logging.Logger;
* Default program initialization includes PDU recording turned on by default. * Default program initialization includes PDU recording turned on by default.
* @see <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/blob/master/examples/src/OpenDis7Examples/ExampleSimulationProgramLog.txt">ExampleSimulationProgramLog.txt</a> * @see <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/blob/master/examples/src/OpenDis7Examples/ExampleSimulationProgramLog.txt">ExampleSimulationProgramLog.txt</a>
*/ */
public class ExampleSimulationProgram extends OpenDis7NetworkCapabilities public class ExampleSimulationProgram extends ChannelOpenDis7
{ {
/** seconds for real-time execution (not simulation time, which may or may not be the same) */ /** seconds for real-time execution (not simulation time, which may or may not be the same) */
double currentTimeStep = 1.0; // seconds double currentTimeStep = 1.0; // seconds
...@@ -237,24 +232,6 @@ public class ExampleSimulationProgram extends OpenDis7NetworkCapabilities ...@@ -237,24 +232,6 @@ public class ExampleSimulationProgram extends OpenDis7NetworkCapabilities
} }
/**
* Send a single Protocol Data Unit (PDU) of any type
* @param pdu the pdu to send
*/
protected void sendSinglePdu(Pdu pdu)
{
try
{
disNetworkInterface.send(pdu);
Thread.sleep(100); // TODO consider refactoring the wait logic and moving externally
}
catch (InterruptedException ex)
{
System.err.println(this.getClass().getName() + " Error sending PDU: " + ex.getLocalizedMessage());
System.exit(1);
}
}
/** /**
* Send Comment PDU * Send Comment PDU
* @see <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html">Passing Information to a Method or a Constructor</a> Arbitrary Number of Arguments * @see <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html">Passing Information to a Method or a Constructor</a> Arbitrary Number of Arguments
...@@ -303,6 +280,7 @@ public class ExampleSimulationProgram extends OpenDis7NetworkCapabilities ...@@ -303,6 +280,7 @@ public class ExampleSimulationProgram extends OpenDis7NetworkCapabilities
if (commentType == null) if (commentType == null)
commentType = otherComment; // fallback value otherComment commentType = otherComment; // fallback value otherComment
// now build the commentPdu from these string inputs, thus constructing a narrative entry // now build the commentPdu from these string inputs, thus constructing a narrative entry
@SuppressWarnings("CollectionsToArray")
CommentPdu commentPdu = pduFactory.makeCommentPdu(commentType, newCommentsList.toArray(new String[0])); // comments); CommentPdu commentPdu = pduFactory.makeCommentPdu(commentType, newCommentsList.toArray(new String[0])); // comments);
sendSinglePdu(commentPdu); sendSinglePdu(commentPdu);
if (isVerboseComments()) if (isVerboseComments())
...@@ -347,9 +325,9 @@ public class ExampleSimulationProgram extends OpenDis7NetworkCapabilities ...@@ -347,9 +325,9 @@ public class ExampleSimulationProgram extends OpenDis7NetworkCapabilities
*/ */
public static void main(String[] args) public static void main(String[] args)
{ {
TRACE_PREFIX = "[" + ExampleSimulationProgram.class.getName() + "] "; setTRACE_PREFIX("[" + ExampleSimulationProgram.class.getName() + "] ");
System.out.println(TRACE_PREFIX + "main() started..."); System.out.println(getTRACE_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
...@@ -363,7 +341,7 @@ public class ExampleSimulationProgram extends OpenDis7NetworkCapabilities ...@@ -363,7 +341,7 @@ public class ExampleSimulationProgram extends OpenDis7NetworkCapabilities
thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering
System.out.println(TRACE_PREFIX + "complete."); // report successful completion System.out.println(getTRACE_PREFIX() + "complete."); // report successful completion
System.exit(0); // ensure all threads and sockets released System.exit(0); // ensure all threads and sockets released
} }
......
...@@ -152,7 +152,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram ...@@ -152,7 +152,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram
if (false) // real-time operation or simulation speedup if (false) // real-time operation or simulation speedup
{ {
Thread.sleep((long) (currentTimeStep * 1000)); // seconds * (1000 msec/sec) = milliseconds Thread.sleep((long) (currentTimeStep * 1000)); // seconds * (1000 msec/sec) = milliseconds
System.out.println(TRACE_PREFIX + "Pausing for " + currentTimeStep + " seconds"); System.out.println(getTRACE_PREFIX() + "Pausing for " + currentTimeStep + " seconds");
} }
// OK now send the status PDUs for this loop, and then continue // OK now send the status PDUs for this loop, and then continue
...@@ -161,7 +161,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram ...@@ -161,7 +161,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram
sendSinglePdu(espdu_1); sendSinglePdu(espdu_1);
sendCommentPdu(currentTimeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); sendCommentPdu(currentTimeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3);
if (pduRecorder.hasVerboseOutput()) if (pduRecorder.hasVerboseOutput())
System.out.println(TRACE_PREFIX + "PDUs successfully sent for this loop"); System.out.println(getTRACE_PREFIX() + "PDUs successfully sent for this loop");
pduSentList.add(espdu_1); pduSentList.add(espdu_1);
pduTrack_1.addPdu(espdu_1); pduTrack_1.addPdu(espdu_1);
Vector3Double location = espdu_1.getEntityLocation(); Vector3Double location = espdu_1.getEntityLocation();
...@@ -171,15 +171,15 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram ...@@ -171,15 +171,15 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram
// current loop now finished, check whether to terminate if simulation complete, otherwise continue // current loop now finished, check whether to terminate if simulation complete, otherwise continue
if (simulationComplete || (simulationLoopCount > 10000)) // for example; including fail-safe condition is good if (simulationComplete || (simulationLoopCount > 10000)) // for example; including fail-safe condition is good
{ {
System.out.println(TRACE_PREFIX + "loop termination condition met, simulationComplete=" + simulationComplete); // ", final loopCount=" + loopCount + System.out.println(getTRACE_PREFIX() + "loop termination condition met, simulationComplete=" + simulationComplete); // ", final loopCount=" + loopCount +
break; break;
} }
} // end of simulation loop } // end of simulation loop
// =================================================================================================== // ===================================================================================================
System.out.println(TRACE_PREFIX + "all PDUs successfully sent for this loop (pduSentList.size()=" + pduSentList.size() + " total)"); System.out.println(getTRACE_PREFIX() + "all PDUs successfully sent for this loop (pduSentList.size()=" + pduSentList.size() + " total)");
// track analysis // track analysis
System.out.println(TRACE_PREFIX + "pduTrack_1 initialLocation=" + pduTrack_1.getInitialLocation() + ", latestLocation=" + pduTrack_1.getLatestLocation()); System.out.println(getTRACE_PREFIX() + "pduTrack_1 initialLocation=" + pduTrack_1.getInitialLocation() + ", latestLocation=" + pduTrack_1.getLatestLocation());
pduTrack_1.sortPdus() pduTrack_1.sortPdus()
.createRawWaypoints(); .createRawWaypoints();
...@@ -193,7 +193,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram ...@@ -193,7 +193,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram
narrativeMessage2 = "runSimulation() completed successfully"; // all done narrativeMessage2 = "runSimulation() completed successfully"; // all done
sendCommentPdu(narrativeComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); sendCommentPdu(narrativeComment, narrativeMessage1, narrativeMessage2, narrativeMessage3);
if (pduRecorder.hasVerboseOutput()) if (pduRecorder.hasVerboseOutput())
System.out.println(TRACE_PREFIX + "final CommentPdu successfully sent for simulation"); System.out.println(getTRACE_PREFIX() + "final CommentPdu successfully sent for simulation");
// TODO simulation management PDUs // TODO simulation management PDUs
} }
catch (InterruptedException iex) // handle any exception that your code might choose to provoke! catch (InterruptedException iex) // handle any exception that your code might choose to provoke!
...@@ -233,9 +233,9 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram ...@@ -233,9 +233,9 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram
*/ */
public static void main(String[] args) public static void main(String[] args)
{ {
TRACE_PREFIX = "[" + ExampleTrackInterpolation.class.getName() + "] "; setTRACE_PREFIX("[" + ExampleTrackInterpolation.class.getName() + "] ");
System.out.println(TRACE_PREFIX + "main() started..."); System.out.println(getTRACE_PREFIX() + "main() started...");
thisProgram = new ExampleTrackInterpolation(); // creates instance of self within static main() method thisProgram = new ExampleTrackInterpolation(); // creates instance of self within static main() method
...@@ -243,7 +243,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram ...@@ -243,7 +243,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram
thisProgram.setUpNetworkInterface(); thisProgram.setUpNetworkInterface();
thisProgram.pduRecorder.setDescriptor (TRACE_PREFIX.replace("[","").replace("]","") + " pduRecorder"); thisProgram.pduRecorder.setDescriptor (getTRACE_PREFIX().replace("[","").replace("]","") + " pduRecorder");
thisProgram.pduRecorder.setVerbose(false); thisProgram.pduRecorder.setVerbose(false);
thisProgram.setVerboseComments(false); thisProgram.setVerboseComments(false);
...@@ -253,7 +253,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram ...@@ -253,7 +253,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram
thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering
System.out.println(TRACE_PREFIX + "complete."); // report successful completion System.out.println(getTRACE_PREFIX() + "complete."); // report successful completion
System.exit(0); // ensure all threads and sockets released System.exit(0); // ensure all threads and sockets released
} }
......
package SimkitOpenDis7Examples; package SimkitOpenDis7Examples;
import OpenDis7Examples.OpenDis7NetworkCapabilities; import OpenDis7Examples.ChannelOpenDis7;
import simkit.SimEntityBase; import simkit.SimEntityBase;
import simkit.random.RandomVariate; import simkit.random.RandomVariate;
...@@ -13,7 +13,7 @@ import simkit.random.RandomVariate; ...@@ -13,7 +13,7 @@ import simkit.random.RandomVariate;
*/ */
public class ArrivalProcessOpenDis7 extends SimEntityBase { public class ArrivalProcessOpenDis7 extends SimEntityBase {
private final OpenDis7NetworkCapabilities opendis7 = new OpenDis7NetworkCapabilities(); private final ChannelOpenDis7 channelOpenDis7 = new ChannelOpenDis7();
/** /**
* Generates interarrival times * Generates interarrival times
...@@ -24,6 +24,13 @@ public class ArrivalProcessOpenDis7 extends SimEntityBase { ...@@ -24,6 +24,13 @@ public class ArrivalProcessOpenDis7 extends SimEntityBase {
* State variable that counts the number of Arrival events * State variable that counts the number of Arrival events
*/ */
protected int numberArrivals; protected int numberArrivals;
/** initialization */
private void initialize()
{
channelOpenDis7.printTRACE ("opendis7.getNetworkAddress()=" + channelOpenDis7.getNetworkAddress());
channelOpenDis7.printlnTRACE (", getNetworkPort()=" + channelOpenDis7.getNetworkPort());
}
/** /**
* Instantiate an ArrivalProcess with the given interarrivalTimeGenerator * Instantiate an ArrivalProcess with the given interarrivalTimeGenerator
...@@ -32,7 +39,8 @@ public class ArrivalProcessOpenDis7 extends SimEntityBase { ...@@ -32,7 +39,8 @@ public class ArrivalProcessOpenDis7 extends SimEntityBase {
* times * times
*/ */
public ArrivalProcessOpenDis7(RandomVariate interarrivalTimeGenerator) { public ArrivalProcessOpenDis7(RandomVariate interarrivalTimeGenerator) {
this.setInterarrivalTimeGenerator(interarrivalTimeGenerator); this.interarrivalTimeGenerator = interarrivalTimeGenerator;
initialize();
} }
/** /**
...@@ -41,7 +49,7 @@ public class ArrivalProcessOpenDis7 extends SimEntityBase { ...@@ -41,7 +49,7 @@ public class ArrivalProcessOpenDis7 extends SimEntityBase {
* explicit call to its setter method. * explicit call to its setter method.
*/ */
public ArrivalProcessOpenDis7() { public ArrivalProcessOpenDis7() {
System.out.println("opendis7.getNetworkAddress()=" + opendis7.getNetworkAddress()); initialize();
} }
/** /**
......
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