This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git


The following commit(s) were added to refs/heads/master by this push:
     new c6843c7  Inline comments
c6843c7 is described below

commit c6843c7a68dcab1673ab34e7c46ff49ecbc142a9
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Oct 31 07:30:49 2023 -0400

    Inline comments
    
    Formatting
---
 .../commons/daemon/support/DaemonLoader.java       |  21 ++-
 src/samples/AloneService.java                      |  12 +-
 src/samples/ServiceDaemon.java                     |  16 +-
 src/samples/SimpleApplication.java                 | 168 ++++++++++-----------
 src/samples/SimpleDaemon.java                      |  46 +++---
 5 files changed, 125 insertions(+), 138 deletions(-)

diff --git a/src/main/java/org/apache/commons/daemon/support/DaemonLoader.java 
b/src/main/java/org/apache/commons/daemon/support/DaemonLoader.java
index f1b9f62..cf2f9c9 100644
--- a/src/main/java/org/apache/commons/daemon/support/DaemonLoader.java
+++ b/src/main/java/org/apache/commons/daemon/support/DaemonLoader.java
@@ -230,18 +230,17 @@ public final class DaemonLoader
     public static boolean start()
     {
         try {
-            /* Attempt to start the daemon */
+            // Attempt to start the daemon
             start.invoke(daemon);
 
-            /* Set the availability flag in the controller */
+            // Set the availability flag in the controller
             if (controller != null) {
                 controller.setAvailable(true);
             }
 
         } catch (final Throwable t) {
-            /* In case we encounter ANY error, we dump the stack trace and
-             * return false (load, start and stop won't be called).
-             */
+            // In case we encounter ANY error, we dump the stack trace and
+            // return false (load, start and stop won't be called).
             t.printStackTrace(System.err);
             return false;
         }
@@ -251,7 +250,7 @@ public final class DaemonLoader
     public static boolean stop()
     {
         try {
-            /* Set the availability flag in the controller */
+            // Set the availability flag in the controller
             if (controller != null) {
                 controller.setAvailable(false);
             }
@@ -260,9 +259,8 @@ public final class DaemonLoader
             stop.invoke(daemon);
         }
         catch (final Throwable t) {
-            /* In case we encounter ANY error, we dump the stack trace and
-             * return false (load, start and stop won't be called).
-             */
+            // In case we encounter ANY error, we dump the stack trace and
+            // return false (load, start and stop won't be called).
             t.printStackTrace(System.err);
             return false;
         }
@@ -278,9 +276,8 @@ public final class DaemonLoader
             daemon = null;
             controller = null;
         } catch (final Throwable t) {
-            /* In case we encounter ANY error, we dump the stack trace and
-             * return false (load, start and stop won't be called).
-             */
+            // In case we encounter ANY error, we dump the stack trace and
+            // return false (load, start and stop won't be called).
             t.printStackTrace(System.err);
             return false;
         }
diff --git a/src/samples/AloneService.java b/src/samples/AloneService.java
index b720dd5..ffee8e9 100644
--- a/src/samples/AloneService.java
+++ b/src/samples/AloneService.java
@@ -46,12 +46,12 @@ public class AloneService {
      * @throws Exception If the daemon cannot be initialized
      */
     public void init(String[] arguments) throws Exception {
-        /* Set the err */
+        // Set the err
         System.setErr(new PrintStream(new 
FileOutputStream("/ServiceDaemon.err", true)));
         System.err.println("ServiceDaemon: instance "+this.hashCode()+
                            " init");
 
-        /* read the properties file */
+        // read the properties file
         prop = new Properties();
         try {
             prop.load(new FileInputStream("startfile"));
@@ -76,10 +76,10 @@ public class AloneService {
     }
 
     public void start() {
-        /* Dump a message */
+        // Dump a message
         System.err.println("ServiceDaemon: starting");
 
-        /* Start */
+        // Start
         int i=0;
         for (Enumeration<Object> e = prop.keys(); e.hasMoreElements() ;) {
            String name = (String) e.nextElement();
@@ -89,7 +89,7 @@ public class AloneService {
            } catch (Exception ex) {
                System.err.println("Exception: " + ex);
            }
-           /* Start threads to read from Error and Out streams */
+           // Start threads to read from Error and Out streams
            readerr[i] =
                new ServiceDaemonReadThread(proc[i].getErrorStream());
            readout[i] =
@@ -101,7 +101,7 @@ public class AloneService {
     }
 
     public void stop() {
-        /* Dump a message */
+        // Dump a message
         System.err.println("ServiceDaemon: stopping");
 
         for (int i=0;i<proc.length;i++) {
diff --git a/src/samples/ServiceDaemon.java b/src/samples/ServiceDaemon.java
index 6afa423..e5bc9e3 100644
--- a/src/samples/ServiceDaemon.java
+++ b/src/samples/ServiceDaemon.java
@@ -51,21 +51,21 @@ public class ServiceDaemon implements Daemon {
     @Override
     public void init(DaemonContext context)
     throws Exception {
-        /* Set the err */
+        // Set the err
         System.setErr(new PrintStream(new FileOutputStream(new 
File("ServiceDaemon.err")), true));
         System.err.println("ServiceDaemon: instance "+this.hashCode()+
                            " init");
 
-        /* read the properties file */
+        // read the properties file
         prop = new Properties();
         try {
             prop.load(new FileInputStream("startfile"));
         }
         catch (Exception e) {
             // Cannot find startfile.properties.
-            // XXX: Should we print something?
+            // TODO: Should we print something?
         }
-        /* create an array to store the processes */
+        // create an array to store the processes
         int processCount = prop.size();
         System.err.println("ServiceDaemon: init for " + processCount + " 
processes");
         proc = new Process[processCount];
@@ -82,10 +82,10 @@ public class ServiceDaemon implements Daemon {
 
     @Override
     public void start() {
-        /* Dump a message */
+        // Dump a message
         System.err.println("ServiceDaemon: starting");
 
-        /* Start */
+        // Start
         int i=0;
         for (Enumeration<Object> e = prop.keys(); e.hasMoreElements() ;) {
             String name = (String) e.nextElement();
@@ -95,7 +95,7 @@ public class ServiceDaemon implements Daemon {
             } catch (Exception ex) {
                System.err.println("Exception: " + ex);
            }
-           /* Start threads to read from Error and Out streams */
+           // Start threads to read from Error and Out streams
            readerr[i] =
                new ServiceDaemonReadThread(proc[i].getErrorStream());
            readout[i] =
@@ -109,7 +109,7 @@ public class ServiceDaemon implements Daemon {
     @Override
     public void stop()
     throws IOException, InterruptedException {
-        /* Dump a message */
+        // Dump a message
         System.err.println("ServiceDaemon: stopping");
 
         for (int i=0;i<proc.length;i++) {
diff --git a/src/samples/SimpleApplication.java 
b/src/samples/SimpleApplication.java
index 6876c9c..9381bb5 100644
--- a/src/samples/SimpleApplication.java
+++ b/src/samples/SimpleApplication.java
@@ -78,10 +78,10 @@ public class SimpleApplication implements Runnable {
         else
             app.directory="/tmp";
 
-        /* Dump a message */
+        // Dump a message
         System.err.println("SimpleApplication: loading on port "+port);
         Runtime.getRuntime().addShutdownHook(new ShutdownHook(app));
-        /* Set up this simple daemon */
+        // Set up this simple daemon
         app.server = new ServerSocket(port);
         app.thread = new Thread(app);
         app.start();
@@ -89,24 +89,24 @@ public class SimpleApplication implements Runnable {
 
     public void start()
     {
-        /* Dump a message */
+        // Dump a message
         System.err.println("SimpleApplication: starting");
 
-        /* Start */
+        // Start
         this.thread.start();
     }
 
     public void stop()
         throws IOException, InterruptedException
     {
-        /* Dump a message */
+        // Dump a message
         System.err.println("SimpleApplication: stopping");
 
-        /* Close the ServerSocket. This will make our thread to terminate */
+        // Close the ServerSocket. This will make our thread to terminate
         this.stopping=true;
         this.server.close();
 
-        /* Wait for the main thread to exit and dump a message */
+        // Wait for the main thread to exit and dump a message
         this.thread.join(5000);
         System.err.println("SimpleApplication: stopped");
     }
@@ -132,12 +132,12 @@ public class SimpleApplication implements Runnable {
                 new Thread(handler).start();
             }
         } catch (IOException e) {
-            /* Don't dump any error message if we are stopping. A IOException
-               is generated when the ServerSocket is closed in stop() */
+            // Don't dump any error message if we are stopping. A IOException
+            // is generated when the ServerSocket is closed in stop()
             if (!this.stopping) e.printStackTrace(System.err);
         }
 
-        /* Terminate all handlers that at this point are still open */
+        // Terminate all handlers that at this point are still open
         Enumeration<Handler> openhandlers = this.handlers.elements();
         while (openhandlers.hasMoreElements()) {
             Handler handler = openhandlers.nextElement();
@@ -255,18 +255,18 @@ public class SimpleApplication implements Runnable {
         }
 
         public void handle(InputStream in, OutputStream os) {
-            PrintStream out=null;
+            PrintStream out = null;
             try {
-                out=new PrintStream(os, true, "US-ASCII");
+                out = new PrintStream(os, true, "US-ASCII");
             } catch (UnsupportedEncodingException ex) {
-              out=new PrintStream(os, true);
+                out = new PrintStream(os, true);
             }
 
-            while(true) {
+            while (true) {
                 try {
-                    /* If we don't have data in the System InputStream, we want
-                       to ask to the user for an option. */
-                    if (in.available()==0) {
+                    // If we don't have data in the System InputStream, we want
+                    // to ask to the user for an option.
+                    if (in.available() == 0) {
                         out.println();
                         out.println("Please select one of the following:");
                         out.println("    1) Shutdown");
@@ -277,84 +277,74 @@ public class SimpleApplication implements Runnable {
                         out.print("Your choice: ");
                     }
 
-                    /* Read an option from the client */
-                    int x=in.read();
+                    // Read an option from the client
+                    int x = in.read();
 
                     switch (x) {
-                        /* If the socket was closed, we simply return */
-                        case -1:
-                            return;
-
-                        /* Attempt to shutdown */
-                        case '1':
-                            out.println("Attempting a shutdown...");
-                            try {
-                                System.exit(0);
-                            } catch (IllegalStateException e) {
-                                out.println();
-                                out.println("Can't shutdown now");
-                                e.printStackTrace(out);
-                            }
-                            break;
-
-                        /* Create a file */
-                        case '2':
-                            String name=this.getDirectoryName()+
-                                        "/SimpleApplication."+
-                                        this.getConnectionNumber()+
-                                        ".tmp";
-                            try {
-                                this.createFile(name);
-                                out.println("File '"+name+"' created");
-                            } catch (IOException e) {
-                                e.printStackTrace(out);
-                            }
-                            break;
-
-                        /* Disconnect */
-                        case '3':
-                            out.println("Disconnecting...");
-                            return;
-
-                        /* Crash JVM in a native call: It need an so file ;-) 
*/
-                        case '4':
-                            System.load(System.getProperty("native.library", 
"./Native.so"));
-                            toto();
-                            break;
-
-                        /* Create a directory (PR 30177 with 1.4.x and 1.5.0 */
-                        case '5':
-                            String name1=this.getDirectoryName()+
-                                        "/a/b/c/d/e"+
-                                        "/SimpleApplication."+
-                                        this.getConnectionNumber()+
-                                        ".tmp";
-                            try {
-                                this.createDir(name1);
-                                out.println("File '"+name1+"' created");
-                            } catch (IOException e) {
-                                e.printStackTrace(out);
-                            }
-                            break;
-
-
-                        /* Discard any carriage return / newline characters */
-                        case '\r':
-                        case '\n':
-                            break;
-
-                        /* We got something that we weren't supposed to get */
-                        default:
-                            out.println("Unknown option '"+(char)x+"'");
-                            break;
+                    // If the socket was closed, we simply return
+                    case -1:
+                        return;
+
+                    // Attempt to shutdown
+                    case '1':
+                        out.println("Attempting a shutdown...");
+                        try {
+                            System.exit(0);
+                        } catch (IllegalStateException e) {
+                            out.println();
+                            out.println("Can't shutdown now");
+                            e.printStackTrace(out);
+                        }
+                        break;
+
+                    // Create a file
+                    case '2':
+                        String name = this.getDirectoryName() + 
"/SimpleApplication." + this.getConnectionNumber() + ".tmp";
+                        try {
+                            this.createFile(name);
+                            out.println("File '" + name + "' created");
+                        } catch (IOException e) {
+                            e.printStackTrace(out);
+                        }
+                        break;
+
+                    // Disconnect
+                    case '3':
+                        out.println("Disconnecting...");
+                        return;
+
+                    // Crash JVM in a native call: It need an so file ;-)
+                    case '4':
+                        System.load(System.getProperty("native.library", 
"./Native.so"));
+                        toto();
+                        break;
+
+                    // Create a directory (PR 30177 with 1.4.x and 1.5.0
+                    case '5':
+                        String name1 = this.getDirectoryName() + "/a/b/c/d/e" 
+ "/SimpleApplication." + this.getConnectionNumber() + ".tmp";
+                        try {
+                            this.createDir(name1);
+                            out.println("File '" + name1 + "' created");
+                        } catch (IOException e) {
+                            e.printStackTrace(out);
+                        }
+                        break;
+
+                    // Discard any carriage return / newline characters
+                    case '\r':
+                    case '\n':
+                        break;
+
+                    // We got something that we weren't supposed to get
+                    default:
+                        out.println("Unknown option '" + (char) x + "'");
+                        break;
 
                     }
 
-                /* If we get an IOException we return (disconnect) */
+                    // If we get an IOException we return (disconnect)
                 } catch (IOException e) {
-                    System.err.println("SimpleApplication: IOException in "+
-                                       "connection "+
-                                       this.getConnectionNumber());
+                    System.err.println("SimpleApplication: IOException in " + 
"connection " + this.getConnectionNumber());
                     return;
                 }
             }
diff --git a/src/samples/SimpleDaemon.java b/src/samples/SimpleDaemon.java
index b781030..8e36dd1 100644
--- a/src/samples/SimpleDaemon.java
+++ b/src/samples/SimpleDaemon.java
@@ -80,10 +80,10 @@ public class SimpleDaemon implements Daemon, Runnable {
         else
             this.directory = "/tmp";
 
-        /* Dump a message */
+        // Dump a message
         System.err.println("SimpleDaemon: loading on port " + port);
 
-        /* Set up this simple daemon */
+        // Set up this simple daemon
         this.controller = context.getController();
         this.server = new ServerSocket(port);
         this.thread = new Thread(this);
@@ -91,24 +91,24 @@ public class SimpleDaemon implements Daemon, Runnable {
 
     @Override
     public void start() {
-        /* Dump a message */
+        // Dump a message
         System.err.println("SimpleDaemon: starting");
 
-        /* Start */
+        // Start
         this.thread.start();
     }
 
     @Override
     public void stop()
     throws IOException, InterruptedException {
-        /* Dump a message */
+        // Dump a message
         System.err.println("SimpleDaemon: stopping");
 
-        /* Close the ServerSocket. This will make our thread to terminate */
+        // Close the ServerSocket. This will make our thread to terminate
         this.stopping = true;
         this.server.close();
 
-        /* Wait for the main thread to exit and dump a message */
+        // Wait for the main thread to exit and dump a message
         this.thread.join(5000);
         System.err.println("SimpleDaemon: stopped");
     }
@@ -133,12 +133,12 @@ public class SimpleDaemon implements Daemon, Runnable {
                 new Thread(handler).start();
             }
         } catch (IOException e) {
-            /* Don't dump any error message if we are stopping. A IOException
-               is generated when the ServerSocket is closed in stop() */
+            // Don't dump any error message if we are stopping. A IOException
+            // is generated when the ServerSocket is closed in stop()
             if (!this.stopping) e.printStackTrace(System.err);
         }
 
-        /* Terminate all handlers that at this point are still open */
+        // Terminate all handlers that at this point are still open
         Enumeration<Handler> openhandlers = this.handlers.elements();
         while (openhandlers.hasMoreElements()) {
             Handler handler = openhandlers.nextElement();
@@ -246,8 +246,8 @@ public class SimpleDaemon implements Daemon, Runnable {
 
             while(true) {
                 try {
-                    /* If we don't have data in the System InputStream, we want
-                       to ask to the user for an option. */
+                    // If we don't have data in the System InputStream, we want
+                    // to ask to the user for an option.
                     if (in.available() == 0) {
                         out.println();
                         out.println("Please select one of the following:");
@@ -260,15 +260,15 @@ public class SimpleDaemon implements Daemon, Runnable {
                         out.print("Your choice: ");
                     }
 
-                    /* Read an option from the client */
+                    // Read an option from the client
                     int x = in.read();
 
                     switch (x) {
-                        /* If the socket was closed, we simply return */
+                        // If the socket was closed, we simply return
                         case -1:
                             return;
 
-                        /* Attempt to shutdown */
+                        // Attempt to shutdown
                         case '1':
                             out.println("Attempting a shutdown...");
                             try {
@@ -280,7 +280,7 @@ public class SimpleDaemon implements Daemon, Runnable {
                             }
                             break;
 
-                        /* Attempt to reload */
+                        // Attempt to reload
                         case '2':
                             out.println("Attempting a reload...");
                             try {
@@ -292,7 +292,7 @@ public class SimpleDaemon implements Daemon, Runnable {
                             }
                             break;
 
-                        /* Create a file */
+                        // Create a file
                         case '3':
                             String name=this.getDirectoryName()+
                                         "/SimpleDaemon."+
@@ -306,18 +306,18 @@ public class SimpleDaemon implements Daemon, Runnable {
                             }
                             break;
 
-                        /* Disconnect */
+                        // Disconnect
                         case '4':
                             out.println("Disconnecting...");
                             return;
 
-                        /* Crash JVM in a native call: It need an so file ;-) 
*/
+                        // Crash JVM in a native call: It need an so file ;-)
                         case '5':
                             System.load(System.getProperty("native.library", 
"./Native.so"));
                             toto();
                             break;
 
-                        /* Create a directory (PR 30177 with 1.4.x and 1.5.0 */
+                        // Create a directory (PR 30177 with 1.4.x and 1.5.0
                         case '6':
                             String name1=this.getDirectoryName()+
                                         "/a/b/c/d/e"+
@@ -333,19 +333,19 @@ public class SimpleDaemon implements Daemon, Runnable {
                             break;
 
 
-                        /* Discard any carriage return / newline characters */
+                        // Discard any carriage return / newline characters
                         case '\r':
                         case '\n':
                             break;
 
-                        /* We got something that we weren't supposed to get */
+                        // We got something that we weren't supposed to get
                         default:
                             out.println("Unknown option '"+(char)x+"'");
                             break;
 
                     }
 
-                /* If we get an IOException we return (disconnect) */
+                // If we get an IOException we return (disconnect)
                 } catch (IOException e) {
                     System.err.println("SimpleDaemon: IOException in "+
                                        "connection "+

Reply via email to