From 408125eec37b72ce841833fe13a7ed650ec9fd74 Mon Sep 17 00:00:00 2001
From: brutzman <brutzman@nps.edu>
Date: Sun, 11 Aug 2024 16:15:35 -0700
Subject: [PATCH] renamed for clarity

---
 .../TcpExample4DispatchServer.java            | 75 -------------------
 ...enarioClient.java => TcpSentryClient.java} | 18 ++---
 ...rver.java => TcpSentryDispatchServer.java} | 14 ++--
 ...hread.java => TcpSentryHandlerThread.java} |  8 +-
 4 files changed, 20 insertions(+), 95 deletions(-)
 delete mode 100644 examples/src/TcpExamples/TcpExample4DispatchServer.java
 rename examples/src/TcpExamples/{TcpSentryScenarioClient.java => TcpSentryClient.java} (92%)
 rename examples/src/TcpExamples/{TcpSentryScenarioDispatchServer.java => TcpSentryDispatchServer.java} (89%)
 rename examples/src/TcpExamples/{TcpSentryScenarioHandlerThread.java => TcpSentryHandlerThread.java} (97%)

diff --git a/examples/src/TcpExamples/TcpExample4DispatchServer.java b/examples/src/TcpExamples/TcpExample4DispatchServer.java
deleted file mode 100644
index c03fcf080c..0000000000
--- a/examples/src/TcpExamples/TcpExample4DispatchServer.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package TcpExamples;
-
-import java.io.IOException;
-import java.net.*;
-
-/**
- * This server program works a bit differently by creating and dispatching a
- * new thread to handle multiple incoming socket connections, one after another, all running in parallel.
- * This advanced technique is often used in high=performance high=capacity server programs.
- * 
- * @see TcpExample4Client
- * @see TcpExample4HandlerThread
- *
- * @see <a href="../../../src/TcpExamples/TcpExample4TerminalLog.txt" target="blank">TcpExample4TerminalLog.txt</a>
- * @see <a href="../../../src/TcpExamples/TcpExample4SequenceDiagram.png" target="blank">TcpExample4SequenceDiagram.png</a>
- * @see <a href="../../../src/TcpExamples/TcpExample4SequenceSketch.png" target="blank">TcpExample4SequenceSketch.png</a>
- *
- * @author Don McGregor
- * @author Don Brutzman
- * @author MV3500 class
- */
-public class TcpExample4DispatchServer
-{
-    /** Default constructor */
-    public TcpExample4DispatchServer()
-    {
-        // default constructor
-    }
-    /**
-     * Program invocation, execution starts here
-     * @param args command-line arguments
-     */
-    public static void main(String[] args)
-    {
-        try {
-            ServerSocket             serverSocket = new ServerSocket(2317);
-            Socket                   clientConnectionSocket;
-            TcpExample4HandlerThread handlerThread;
-
-            int connectionCount = 0; // state variable
-
-            System.out.println(TcpExample4DispatchServer.class.getName() + " ready to accept socket connections...");
-            while (true) // infinite loop
-            {
-                clientConnectionSocket = serverSocket.accept(); // block! until connected
-
-                connectionCount++; // unblocked, got another connection
-                
-                // TODO option for the student, provide initial message *to the client*
-                // that we are handing off to a dispatch thread... because that is polite behavior.
-                // Plenty of code in Example3, we instead let our proxy thread
-                // TcpExample4HandlerThread introduce itself to the client.
-                
-                System.out.println("=============================================================");
-                System.out.println(TcpExample4DispatchServer.class.getName() + ".handlerThread created for connection #" + connectionCount + "...");
-                
-                // hand off this aready-created and connected socket to constructor
-                handlerThread = new TcpExample4HandlerThread(clientConnectionSocket); 
-                handlerThread.start();// invokes the run() method in that object
-                System.out.println(TcpExample4DispatchServer.class.getName() + ".handlerThread is now dispatched and running, using most recent connection...");
-                
-                // while(true) continue looping, serverSocket is still waiting for another customer client
-            }
-        } 
-        catch (IOException e) {
-            System.out.println("Problem with " + TcpExample4DispatchServer.class.getName() + " networking:"); // describe what is happening
-            System.out.println("Error: " + e);
-            // Provide more helpful information to user if exception occurs due to running twice at one time
-            if (e instanceof java.net.BindException) {
-                System.out.println("*** Be sure to stop any other running instances of programs using this port!");
-            }
-        }
-        System.out.println("============================================================="); // execution complete
-    }
-}
diff --git a/examples/src/TcpExamples/TcpSentryScenarioClient.java b/examples/src/TcpExamples/TcpSentryClient.java
similarity index 92%
rename from examples/src/TcpExamples/TcpSentryScenarioClient.java
rename to examples/src/TcpExamples/TcpSentryClient.java
index 4ec04abb2e..444983c9ef 100644
--- a/examples/src/TcpExamples/TcpSentryScenarioClient.java
+++ b/examples/src/TcpExamples/TcpSentryClient.java
@@ -1,9 +1,9 @@
 package TcpExamples;
 
-import static TcpExamples.TcpSentryScenarioHandlerThread.HALT_WHO_GOES_THERE;
-import static TcpExamples.TcpSentryScenarioHandlerThread.HOLD_IT_RIGHT_THERE;
-import static TcpExamples.TcpSentryScenarioHandlerThread.SENTRY_WATCH_PRESENT;
-import static TcpExamples.TcpSentryScenarioHandlerThread.YOU_MAY_PASS;
+import static TcpExamples.TcpSentryHandlerThread.HALT_WHO_GOES_THERE;
+import static TcpExamples.TcpSentryHandlerThread.HOLD_IT_RIGHT_THERE;
+import static TcpExamples.TcpSentryHandlerThread.SENTRY_WATCH_PRESENT;
+import static TcpExamples.TcpSentryHandlerThread.YOU_MAY_PASS;
 import java.io.*;
 import java.net.*;
 
@@ -13,7 +13,7 @@ import java.net.*;
  * No fancy footwork here, it is pretty simple and similar to {@link TcpExample3Client}.
  * 
  * @see TcpSentryScenarioDispatchServer
- * @see TcpSentryScenarioHandlerThread
+ * @see TcpSentryHandlerThread
  * @see TcpExample4Client
  * @see TcpExample4DispatchServer
  * @see TcpExample4HandlerThread
@@ -26,12 +26,12 @@ import java.net.*;
  * @author Don McGregor
  * @author MV3500 class
  */
-public class TcpSentryScenarioClient
+public class TcpSentryClient
 {
     static String prefix = "[client] ";
     
     /** Default constructor */
-    public TcpSentryScenarioClient()
+    public TcpSentryClient()
     {
         // no action needed here
     }
@@ -46,7 +46,7 @@ public class TcpSentryScenarioClient
         try
         {
             System.out.println("===============================================================================");
-            System.out.println(prefix + "startup, menu 1h.TcpSentryClient, " + TcpSentryScenarioClient.class.getName());
+            System.out.println(prefix + "startup, menu 1h.TcpSentryClient, " + TcpSentryClient.class.getName());
             System.out.println(prefix + "up to " + MAX_LOOP_COUNT + " visitors may approach.");
             System.out.println("===============================================================================");
             for (int loopCount = 1; loopCount <= MAX_LOOP_COUNT; loopCount++) // loop then exit
@@ -117,7 +117,7 @@ public class TcpSentryScenarioClient
                     else System.out.println (prefix + "I'm not sure what that means, say again please...");
                 }
                 System.out.println("===============================================================================");
-                // To push this further, launch multiple copies of TcpSentryScenarioClient simultaneously
+                // To push this further, launch multiple copies of TcpSentryClient simultaneously
             }
 
 ////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/examples/src/TcpExamples/TcpSentryScenarioDispatchServer.java b/examples/src/TcpExamples/TcpSentryDispatchServer.java
similarity index 89%
rename from examples/src/TcpExamples/TcpSentryScenarioDispatchServer.java
rename to examples/src/TcpExamples/TcpSentryDispatchServer.java
index add710881e..8c84be4bb5 100644
--- a/examples/src/TcpExamples/TcpSentryScenarioDispatchServer.java
+++ b/examples/src/TcpExamples/TcpSentryDispatchServer.java
@@ -9,7 +9,7 @@ import java.net.*;
  * This advanced technique is often used in high=performance high=capacity server programs.
  * 
  * @see TcpSentryScenarioClient
- * @see TcpSentryScenarioHandlerThread
+ * @see TcpSentryHandlerThread
  * @see TcpExample4Client
  * @see TcpExample4DispatchServer
  * @see TcpExample4HandlerThread
@@ -22,12 +22,12 @@ import java.net.*;
  * @author Don Brutzman
  * @author MV3500 class
  */
-public class TcpSentryScenarioDispatchServer
+public class TcpSentryDispatchServer
 {
     static String prefix = "[dispatcher] ";
             
     /** Default constructor */
-    public TcpSentryScenarioDispatchServer()
+    public TcpSentryDispatchServer()
     {
         // default constructor
     }
@@ -40,12 +40,12 @@ public class TcpSentryScenarioDispatchServer
         try {
             ServerSocket                   serverSocket = new ServerSocket(2317);
             Socket                         serverSocketConnection;
-            TcpSentryScenarioHandlerThread sentryHandlerThread;
+            TcpSentryHandlerThread sentryHandlerThread;
 
             int connectionCount = 0; // state variable
 
             System.out.println("===============================================================================");
-            System.out.println(prefix + "startup, menu 1g.TcpSentryServer, " + TcpSentryScenarioDispatchServer.class.getName());
+            System.out.println(prefix + "startup, menu 1g.TcpSentryServer, " + TcpSentryDispatchServer.class.getName());
             
             while (true) // infinite loop, handling client connections and dispatching another handler thread
             {
@@ -57,12 +57,12 @@ public class TcpSentryScenarioDispatchServer
                 // TODO option for the student, provide initial message *to the client*
                 // that we are handing off to a dispatch thread... because that is polite behavior.
                 // Plenty of code in Example3, we instead let our proxy thread
-                // TcpSentryScenarioHandlerThread introduce itself to the client.
+                // TcpSentryHandlerThread introduce itself to the client.
                 
                 System.out.println(prefix + "received socket connection, creating handlerThread for visitor #" + connectionCount + "...");
                 
                 // hand off this aready-created and connected socket to constructor
-                sentryHandlerThread = new TcpSentryScenarioHandlerThread(serverSocketConnection); // creation logs a message
+                sentryHandlerThread = new TcpSentryHandlerThread(serverSocketConnection); // creation logs a message
                 sentryHandlerThread.start();// invokes the run() method in that object, which sends initial reply on the socket
                 System.out.println(prefix + "a new sentry is now dispatched and running, using socket connection #" + connectionCount);
                 System.out.println("===============================================================================");
diff --git a/examples/src/TcpExamples/TcpSentryScenarioHandlerThread.java b/examples/src/TcpExamples/TcpSentryHandlerThread.java
similarity index 97%
rename from examples/src/TcpExamples/TcpSentryScenarioHandlerThread.java
rename to examples/src/TcpExamples/TcpSentryHandlerThread.java
index ea41a18761..f5b3d27df5 100644
--- a/examples/src/TcpExamples/TcpSentryScenarioHandlerThread.java
+++ b/examples/src/TcpExamples/TcpSentryHandlerThread.java
@@ -31,7 +31,7 @@ import java.util.List;
  * @author Don Brutzman
  * @author MV3500 class
  */
-public class TcpSentryScenarioHandlerThread extends Thread
+public class TcpSentryHandlerThread extends Thread
 {
     /** Sentry Scenario access list, as written this list is case sensitive.
      * See {@linktourl https://stackoverflow.com/questions/1005073/initialization-of-an-arraylist-in-one-line }
@@ -55,10 +55,10 @@ public class TcpSentryScenarioHandlerThread extends Thread
      * 
      * @param socket The socket connection handled by this thread
      */
-    TcpSentryScenarioHandlerThread(Socket socket)
+    TcpSentryHandlerThread(Socket socket)
     {
         this.socket = socket;
-        System.out.println(prefix + "1h.TcpSentryClient, " + TcpSentryScenarioHandlerThread.class.getName());
+        System.out.println(prefix + "1h.TcpSentryClient, " + TcpSentryHandlerThread.class.getName());
     }
     /**
      * Program invocation and execution starts here - but is illegal and unwanted, so warn the unsuspecting user!
@@ -80,7 +80,7 @@ public class TcpSentryScenarioHandlerThread extends Thread
     {
         try
         {
-            System.out.println(prefix + "startup, menu 1g.TcpSentryServer, " + TcpSentryScenarioHandlerThread.class.getName());
+            System.out.println(prefix + "startup, menu 1g.TcpSentryServer, " + TcpSentryHandlerThread.class.getName());
             // now starting to handle the thread
             
             // setup input stream and output stream 
-- 
GitLab