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

javadoc, clear warnings

parent d326ef63
No related branches found
No related tags found
No related merge requests found
Showing
with 231 additions and 125 deletions
......@@ -19,8 +19,13 @@ import java.util.*;
* Simple DIS demonstration program
* @author DMcG
*/
public class DisDemonstration {
public class DisDemonstration
{
/** Default constructor */
public DisDemonstration()
{
// default constructor
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
......
......@@ -14,7 +14,13 @@ import java.util.Set;
*
* @author <a href="mailto:tdnorbra@nps.edu?subject=mv4503.PduListenerImpl">Terry Norbraten, NPS MOVES</a>
*/
public class PduListenerImpl implements PduListener {
public class PduListenerImpl implements PduListener
{
/** Default constructor */
public PduListenerImpl()
{
// default constructor
}
/** All ENTITIES in the world we have heard from */
static final Map<EntityID, EntityStatePdu> ENTITIES = Collections.synchronizedMap(new HashMap<>());
......
......@@ -10,8 +10,13 @@ import java.net.*;
* @author mcgredo
* @author brutzman
*/
public class HttpWebPageSource {
public class HttpWebPageSource
{
/** Default constructor */
public HttpWebPageSource()
{
// default constructor
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
......
......@@ -17,6 +17,11 @@ import java.io.IOException;
*/
public class EspduReceiver
{
/** Default constructor */
public EspduReceiver()
{
// default constructor
}
/** Max size of a PDU in binary format that we can receive. This is actually
* somewhat outdated--PDUs can be larger--but this is a reasonable starting point.
*/
......
......@@ -14,8 +14,13 @@ import edu.nps.moves.disutil.DisTime;
*
* @author DMcG
*/
public class EspduSender {
public class EspduSender
{
/** Default constructor */
public EspduSender()
{
// default constructor
}
/** Defining number of packets to send is superior to infinite loops
* which have possible hazard of unstoppably sending packets as a zombie process */
public static final int NUMBER_TO_SEND = 5; // 5000;
......
......@@ -11,6 +11,11 @@ import java.io.IOException;
/** Listen for IEEE DIS Protocol Data Units (PDUs) */
public class PduReceiver
{
/** Default constructor */
public PduReceiver()
{
// default constructor
}
private static final int MULTICAST_PORT = 3000;
private static final String MULTICAST_GROUP = "239.1.2.3";
private static final boolean USE_FAST_ESPDU = false;
......
......@@ -13,6 +13,11 @@ import java.util.List;
/** Listen to all kinds of PDUs and report them */
public class AllPduReceiver
{
/** Default constructor */
public AllPduReceiver()
{
// default constructor
}
/** default multicast address
* @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;
......
......@@ -15,6 +15,11 @@ import java.util.*;
*/
public class EspduReceiver
{
/** Default constructor */
public EspduReceiver()
{
// default constructor
}
/** Max size of a PDU in binary format that we can receive. This is actually
* somewhat outdated--PDUs can be larger--but this is a reasonable starting point.
*/
......
......@@ -19,6 +19,11 @@ import java.util.*;
*/
public class EspduSender
{
/** Default constructor */
public EspduSender()
{
// default constructor
}
/**
* Number of complete loops to perform.
* Putting any upper limit on # packets sent avoids possibility of non-terminating infinite loops that continue sending packets. */
......
......@@ -26,7 +26,9 @@ public class ExampleSimulationProgram
/* **************************** infrastructure code, modification is seldom needed ************************* */
private String descriptor = this.getClass().getSimpleName();
/** DIS channel defined by network address/port combination includes multiple utility capabilities */
protected DisChannel disChannel;
/** Factory object used to create new PDU instances */
protected PduFactory pduFactory;
/** seconds for real-time execution (not simulation time, which may or may not be .the same) */
......@@ -65,6 +67,10 @@ public class ExampleSimulationProgram
{
initialize();
}
/**
* Constructor to create an instance of this class.
* @param newDescriptor describes this program, useful for logging and debugging
*/
public ExampleSimulationProgram(String newDescriptor)
{
descriptor = newDescriptor;
......@@ -229,8 +235,9 @@ public class ExampleSimulationProgram
System.out.flush();
sendAllPdusForLoopTimestep(entityStatePdu_1,
firePdu_1a,
disChannel.currentTimeStepCommentType, narrativeMessage1, narrativeMessage2, narrativeMessage3);
firePdu_1a,
disChannel.COMMENTPDU_APPLICATION_STATUS,
narrativeMessage1, narrativeMessage2, narrativeMessage3);
disChannel.sendSinglePdu(entityStatePdu_2); // me too i.e. 2!
System.out.println ("... [PDUs of interest successfully sent for this loop]");
......@@ -249,7 +256,7 @@ public class ExampleSimulationProgram
narrativeMessage2 = "runSimulation() completed successfully"; // all done, so tell everyone else on the channel
// TODO better javadoc needs to be autogenerated for VariableRecordType enumerations
disChannel.sendCommentPdu(disChannel.narrativeCommentType, narrativeMessage1, narrativeMessage2, narrativeMessage3);
disChannel.sendCommentPdu(disChannel.COMMENTPDU_NARRATIVE, narrativeMessage1, narrativeMessage2, narrativeMessage3);
System.out.println ("... [final=completion CommentPdu successfully sent for simulation]");
disChannel.leave(); // embedded SimulationManager is expected to send appropriate PDUs for entity, application shutdown
......@@ -267,6 +274,7 @@ public class ExampleSimulationProgram
* @param firePdu the FirePDU to send, if any
* @param commentType enumeration value describing purpose of the narrative comment
* @param comments String array of narrative comments
* @see DisChannel
*/
public void sendAllPdusForLoopTimestep(EntityStatePdu entityStatePdu,
FirePdu firePdu,
......
......@@ -29,6 +29,11 @@ import java.util.logging.Logger;
*/
public class ExampleTrackInterpolation extends ExampleSimulationProgram
{
/** Default constructor */
public ExampleTrackInterpolation()
{
// default constructor
}
// -------------------- Begin Variables for X3D autogenerated code
private X3dCreateInterpolators x3dInterpolators = new X3dCreateInterpolators();
private X3dCreateLineSet x3dLineSet = new X3dCreateLineSet();
......@@ -158,7 +163,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram
if (disChannel.getPduRecorder().hasVerboseOutput())
System.out.println("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent");
disChannel.sendSinglePdu(espdu_1);
disChannel.sendCommentPdu(disChannel.currentTimeStepCommentType, narrativeMessage1, narrativeMessage2, narrativeMessage3);
disChannel.sendCommentPdu(disChannel.COMMENTPDU_SIMULATION_TIMESTEP, narrativeMessage1, narrativeMessage2, narrativeMessage3);
if (disChannel.getPduRecorder().hasVerboseOutput())
System.out.println(disChannel.getTRACE_PREFIX() + "PDUs successfully sent for this loop");
pduSentList.add(espdu_1);
......@@ -190,7 +195,7 @@ public class ExampleTrackInterpolation extends ExampleSimulationProgram
System.out.println("=================================");
narrativeMessage2 = "runSimulation() completed successfully"; // all done
disChannel.sendCommentPdu(disChannel.narrativeCommentType, narrativeMessage1, narrativeMessage2, narrativeMessage3);
disChannel.sendCommentPdu(disChannel.COMMENTPDU_NARRATIVE, narrativeMessage1, narrativeMessage2, narrativeMessage3);
if (disChannel.getPduRecorder().hasVerboseOutput())
disChannel.printlnTRACE("final CommentPdu successfully sent for simulation");
// TODO simulation management PDUs
......
......@@ -21,6 +21,11 @@ import java.util.Scanner;
*/
public class PduReaderPlayer
{
/** Default constructor */
public PduReaderPlayer()
{
// default constructor
}
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> */
......
......@@ -18,8 +18,13 @@ import java.net.*;
* @author mcgredo
* @author brutzman
*/
public class Assignment1TCPExample3ClientChange {
public class Assignment1TCPExample3ClientChange
{
/** Default constructor */
public Assignment1TCPExample3ClientChange()
{
// default constructor
}
/** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1
* @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a>
* @see <a href="https://en.wikipedia.org/wiki/IPv6_address">https://en.wikipedia.org/wiki/IPv6_address</a>
......
package TcpExamples;
import java.io.*;
import java.net.*;
/**
* This is Assignment 1 where I have modified the given code from TCPExample3Server
*-server response message changed
*
* Very slightly more complex than example1, further modifying example2. The
* only thing this does differently is introduce a loop into the response, so
* you don't have to restart the program after one response. Also, it prints out
* the socket pair the server sees. Run the program via telnet several times and
* compare the socket pairs.
*
* telnet (nc) localhost 2317
*
* If you're sophisticated you can contact the instructor's computer while
* running this program.
*
* telnet (nc) [ipNumberOfServerLaptop] 2317
*
* and have the instructor display the socket pairs received.
*
* @author mcgredo
* @author brutzman
*/
public class Assignmnet1TCPExample3ServerChange {
/**
* Program invocation, execution starts here
* If already compiled, can run using console in directory ../../build/classes/ by invoking \
* java -classpath . TcpExamples.TcpExample3Server
* @param args command-line arguments
*/
public static void main(String[] args) {
try {
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
System.out.println(Assignmnet1TCPExample3ServerChange.class.getName() + " has started..."); // it helps debugging to put this on console first
ServerSocket serverSocket = new ServerSocket(2317);
OutputStream os;
PrintStream ps;
InetAddress localAddress, remoteAddress;
int localPort, remotePort;
int serverLoopCount = 0;
// Server is up and waiting (i.e. "blocked" or paused)
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while (true) {
// block until connected to a client
try (Socket clientConnectionSocket = serverSocket.accept())
{
serverLoopCount++; // increment at beginning of loop for reliability
// Now hook everything up (i.e. set up the streams), Java style:
os = clientConnectionSocket.getOutputStream();
ps = new PrintStream(os);
ps.println("This is response " + serverLoopCount + " produced by the server, "
+ Assignmnet1TCPExample3ServerChange.class.getName()); // this gets sent back to client!
// Print some information locally about the Socket connection.
// This includes the port and IP numbers on both sides (the socket pair).
localAddress = clientConnectionSocket.getLocalAddress();
remoteAddress = clientConnectionSocket.getInetAddress();
localPort = clientConnectionSocket.getLocalPort();
remotePort = clientConnectionSocket.getPort();
System.out.print ("Server loop " + serverLoopCount + ": ");
// My socket pair connection looks like this, to localhost:
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 ))
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 ))
// Why is the first IP/port the same, while the second set has different ports?
System.out.println(TcpExample3Server.class.getName() + " socket pair showing host name, address, port:");
System.out.println(" (( " +
localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " +
remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))");
if ( localAddress.getHostName().equals( localAddress.getHostAddress()) ||
remoteAddress.getHostName().equals(remoteAddress.getHostAddress()))
System.out.println(" note HostName matches address if host has no DNS name");
// Notice the use of flush() and try w/ resources. Without
// the try w/ resources the Socket object may stay open for
// a while after the client has stopped needing this
// connection. try w/ resources explicitly ends the connection.
ps.flush();
// like it or not, you're outta here!
}
}
} catch (IOException e) {
System.err.println("Problem with " + TcpExample3Server.class.getName() + " networking: " + e);
// Provide more helpful information to user if exception occurs due to running twice at one time
if (e instanceof java.net.BindException) {
System.err.println("*** Be sure to stop any other running instances of programs using this port!");
}
}
}
}
package TcpExamples;
import java.io.*;
import java.net.*;
/**
* This is Assignment 1 where I have modified the given code from TCPExample3Server
*-server response message changed
*
* Very slightly more complex than example1, further modifying example2. The
* only thing this does differently is introduce a loop into the response, so
* you don't have to restart the program after one response. Also, it prints out
* the socket pair the server sees. Run the program via telnet several times and
* compare the socket pairs.
*
* telnet (nc) localhost 2317
*
* If you're sophisticated you can contact the instructor's computer while
* running this program.
*
* telnet (nc) [ipNumberOfServerLaptop] 2317
*
* and have the instructor display the socket pairs received.
*
* @author mcgredo
* @author brutzman
*/
public class Assignmnet1TCPExample3ServerChange
{
/** Default constructor */
public Assignmnet1TCPExample3ServerChange()
{
// default constructor
}
/**
* Program invocation, execution starts here
* If already compiled, can run using console in directory ../../build/classes/ by invoking \
* java -classpath . TcpExamples.TcpExample3Server
* @param args command-line arguments
*/
public static void main(String[] args) {
try {
// ServerSocket waits for a connection from a client.
// Notice that it is outside the loop; ServerSocket
// needs to be made only once.
System.out.println(Assignmnet1TCPExample3ServerChange.class.getName() + " has started..."); // it helps debugging to put this on console first
ServerSocket serverSocket = new ServerSocket(2317);
OutputStream os;
PrintStream ps;
InetAddress localAddress, remoteAddress;
int localPort, remotePort;
int serverLoopCount = 0;
// Server is up and waiting (i.e. "blocked" or paused)
// Loop, infinitely, waiting for client connections.
// Stop the program somewhere else.
while (true) {
// block until connected to a client
try (Socket clientConnectionSocket = serverSocket.accept())
{
serverLoopCount++; // increment at beginning of loop for reliability
// Now hook everything up (i.e. set up the streams), Java style:
os = clientConnectionSocket.getOutputStream();
ps = new PrintStream(os);
ps.println("This is response " + serverLoopCount + " produced by the server, "
+ Assignmnet1TCPExample3ServerChange.class.getName()); // this gets sent back to client!
// Print some information locally about the Socket connection.
// This includes the port and IP numbers on both sides (the socket pair).
localAddress = clientConnectionSocket.getLocalAddress();
remoteAddress = clientConnectionSocket.getInetAddress();
localPort = clientConnectionSocket.getLocalPort();
remotePort = clientConnectionSocket.getPort();
System.out.print ("Server loop " + serverLoopCount + ": ");
// My socket pair connection looks like this, to localhost:
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54876 ))
// Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 54881 ))
// Why is the first IP/port the same, while the second set has different ports?
System.out.println(TcpExample3Server.class.getName() + " socket pair showing host name, address, port:");
System.out.println(" (( " +
localAddress.getHostName() + "=" + localAddress.getHostAddress() + ", " + localPort + " ), ( " +
remoteAddress.getHostName() + "=" + remoteAddress.getHostAddress() + ", " + remotePort + " ))");
if ( localAddress.getHostName().equals( localAddress.getHostAddress()) ||
remoteAddress.getHostName().equals(remoteAddress.getHostAddress()))
System.out.println(" note HostName matches address if host has no DNS name");
// Notice the use of flush() and try w/ resources. Without
// the try w/ resources the Socket object may stay open for
// a while after the client has stopped needing this
// connection. try w/ resources explicitly ends the connection.
ps.flush();
// like it or not, you're outta here!
}
}
} catch (IOException e) {
System.err.println("Problem with " + TcpExample3Server.class.getName() + " networking: " + e);
// Provide more helpful information to user if exception occurs due to running twice at one time
if (e instanceof java.net.BindException) {
System.err.println("*** Be sure to stop any other running instances of programs using this port!");
}
}
}
}
......@@ -32,6 +32,11 @@ import java.net.*;
*/
public class TcpExample1Telnet
{
/** Default constructor */
public TcpExample1Telnet()
{
// default constructor
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
......
......@@ -23,6 +23,11 @@ import java.net.*;
*/
public class TcpExample2ConnectionCounting
{
/** Default constructor */
public TcpExample2ConnectionCounting()
{
// default constructor
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
......
......@@ -14,7 +14,13 @@ import java.net.*;
* @author mcgredo
* @author brutzman
*/
public class TcpExample3Client {
public class TcpExample3Client
{
/** Default constructor */
public TcpExample3Client()
{
// default constructor
}
/** IPv6 String constant for localhost address, similarly IPv4 127.0.0.1
* @see <a href="https://en.wikipedia.org/wiki/localhost">https://en.wikipedia.org/wiki/localhost</a>
......
......@@ -22,7 +22,13 @@ import java.net.*;
* @author mcgredo
* @author brutzman
*/
public class TcpExample3Server {
public class TcpExample3Server
{
/** Default constructor */
public TcpExample3Server()
{
// default constructor
}
/**
* Program invocation, execution starts here
......
......@@ -14,6 +14,11 @@ import java.net.*;
*/
public class TcpExample4Client
{
/** Default constructor */
public TcpExample4Client()
{
// default constructor
}
static String DESTINATION_HOST = "localhost";
static int MAX_LOOP_COUNT = 4;
......
......@@ -11,8 +11,13 @@ import java.net.*;
* @author Don Brutzman
* @author MV3500 class
*/
public class TcpExample4DispatchServer {
public class TcpExample4DispatchServer
{
/** Default constructor */
public TcpExample4DispatchServer()
{
// default constructor
}
/**
* Program invocation, execution starts here
* @param args command-line arguments
......
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