svn commit: r1374711 - /ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1374711 - /ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java

adrianc
Author: adrianc
Date: Sun Aug 19 08:46:21 2012
New Revision: 1374711

URL: http://svn.apache.org/viewvc?rev=1374711&view=rev
Log:
Some work on Start.java:

1. Removed unused method.
2. Consolidated/separated the Commons Daemon implementation - this just makes it easier to distinguish it from the rest of the code.
3. Changed some public methods to private, and added a private constructor.
4. Made ServerState enum public.

These changes are in preparation for enabling client code to query the class for the server's state.

Modified:
    ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java

Modified: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java?rev=1374711&r1=1374710&r2=1374711&view=diff
==============================================================================
--- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java (original)
+++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java Sun Aug 19 08:46:21 2012
@@ -117,12 +117,16 @@ public class Start {
         }
     }
 
+    // ---------------------------------------------- //
+
     private Config config = null;
     private List<String> loaderArgs = new ArrayList<String>();
     private final ArrayList<StartupLoader> loaders = new ArrayList<StartupLoader>();
     private AtomicReference<ServerState> serverState = new AtomicReference<ServerState>(ServerState.STARTING);
     private Thread adminPortThread = null;
 
+    private Start() {}
+
     private void createListenerThread() throws StartupException {
         if (config.adminPort > 0) {
             this.adminPortThread = new AdminPortThread();
@@ -141,16 +145,7 @@ public class Start {
         }
     }
 
-    // org.apache.commons.daemon.Daemon.destroy()
-    public void destroy() {
-        // FIXME: undo init() calls.
-    }
-
-    public void init(String[] args) throws StartupException {
-        init(args, true);
-    }
-
-    public void init(String[] args, boolean fullInit) throws StartupException {
+    private void init(String[] args, boolean fullInit) throws StartupException {
         String globalSystemPropsFileName = System.getProperty("ofbiz.system.props");
         if (globalSystemPropsFileName != null) {
             FileInputStream stream = null;
@@ -268,7 +263,7 @@ public class Start {
         return response;
     }
 
-    public String shutdown() throws IOException {
+    private String shutdown() throws IOException {
         return sendSocketCommand(Control.SHUTDOWN);
     }
 
@@ -298,20 +293,6 @@ public class Start {
         }
     }
 
-    // org.apache.commons.daemon.Daemon.start()
-    public void start() throws Exception {
-        if (!startStartLoaders()) {
-            if (this.serverState.get() == ServerState.STOPPING) {
-                return;
-            } else {
-                throw new Exception("Error during start.");
-            }
-        }
-        if (config.shutdownAfterLoad) {
-            stopServer();
-        }
-    }
-
     /**
      * Returns <code>true</code> if all loaders were started.
      *
@@ -335,7 +316,7 @@ public class Start {
         return this.serverState.compareAndSet(ServerState.STARTING, ServerState.RUNNING);
     }
 
-    public String status() throws IOException {
+    private String status() throws IOException {
         try {
             return sendSocketCommand(Control.STATUS);
         } catch (ConnectException e) {
@@ -345,16 +326,41 @@ public class Start {
         }
     }
 
-    // org.apache.commons.daemon.Daemon.stop()
-    public void stop() {
+    private void stopServer() {
         shutdownServer();
+        System.exit(0);
+    }
+
+    // ----------------------------------------------- //
+    // org.apache.commons.daemon.Daemon implementation //
+    // ----------------------------------------------- //
+
+    // org.apache.commons.daemon.Daemon.destroy()
+    public void destroy() {
+        // FIXME: undo init() calls.
     }
 
-    public void stopServer() {
+    // org.apache.commons.daemon.Daemon.start()
+    public void start() throws Exception {
+        if (!startStartLoaders()) {
+            if (this.serverState.get() == ServerState.STOPPING) {
+                return;
+            } else {
+                throw new Exception("Error during start.");
+            }
+        }
+        if (config.shutdownAfterLoad) {
+            stopServer();
+        }
+    }
+
+    // org.apache.commons.daemon.Daemon.stop()
+    public void stop() {
         shutdownServer();
-        System.exit(0);
     }
 
+    // ----------------------------------------------- //
+
     private class AdminPortThread extends Thread {
         private ServerSocket serverSocket = null;
 
@@ -447,7 +453,7 @@ public class Start {
         abstract void processRequest(Start start, PrintWriter writer);
     }
 
-    private enum ServerState {
+    public enum ServerState {
         STARTING, RUNNING, STOPPING;
 
         public String toString() {