Author: adrianc
Date: Thu Aug 14 14:11:48 2014 New Revision: 1617951 URL: http://svn.apache.org/r1617951 Log: Merged revision(s) 1617936 from ofbiz/trunk: Fixed a bug in Start.java reported by Justen Walker (https://issues.apache.org/jira/browse/OFBIZ-5710): The singleton pattern was broken by adding Commons Daemon support code to the class - resulting in multiple instances when using Commons Daemon. I extracted the Commons Daemon code to a separate class - which delegates to the singleton Start instance. Users of Commons Daemon will need to update their scripts/etc to point to the new class instead of Start. I also added a comment describing the design of Start.java, so hopefully this will help others maintain the code without breaking it. Added: ofbiz/branches/release13.07/framework/start/src/org/ofbiz/base/start/CommonsDaemonStart.java - copied unchanged from r1617936, ofbiz/trunk/framework/start/src/org/ofbiz/base/start/CommonsDaemonStart.java Modified: ofbiz/branches/release13.07/ (props changed) ofbiz/branches/release13.07/framework/start/src/org/ofbiz/base/start/Start.java Propchange: ofbiz/branches/release13.07/ ------------------------------------------------------------------------------ Merged /ofbiz/trunk:r1617936,1617938 Modified: ofbiz/branches/release13.07/framework/start/src/org/ofbiz/base/start/Start.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/start/src/org/ofbiz/base/start/Start.java?rev=1617951&r1=1617950&r2=1617951&view=diff ============================================================================== --- ofbiz/branches/release13.07/framework/start/src/org/ofbiz/base/start/Start.java (original) +++ ofbiz/branches/release13.07/framework/start/src/org/ofbiz/base/start/Start.java Thu Aug 14 14:11:48 2014 @@ -40,6 +40,19 @@ import java.util.concurrent.atomic.Atomi */ public final class Start { + /* + * This class implements a thread-safe state machine. The design is critical + * for reliable starting and stopping of the server. + * + * The machine's current state and state changes must be encapsulated in this + * class. Client code may query the current state, but it may not change it. + * + * This class uses a singleton pattern to guarantee that only one server instance + * is running in the VM. Client code retrieves the instance by using the getInstance() + * static method. + * + */ + private static final Start instance = new Start(); private static Command checkCommand(Command command, Command wanted) { @@ -135,8 +148,8 @@ public final class Start { private final AtomicReference<ServerState> serverState = new AtomicReference<ServerState>(ServerState.STARTING); private Thread adminPortThread = null; - /** DO NOT REMOVE: This method is needed by commons-daemon in reflection mode. */ - public Start() { + // DO NOT CHANGE THIS! + private Start() { } private void createListenerThread() throws StartupException { @@ -164,7 +177,7 @@ public final class Start { return serverState.get(); } - private void init(String[] args, boolean fullInit) throws StartupException { + void init(String[] args, boolean fullInit) throws StartupException { String globalSystemPropsFileName = System.getProperty("ofbiz.system.props"); if (globalSystemPropsFileName != null) { FileInputStream stream = null; @@ -298,7 +311,7 @@ public final class Start { return sendSocketCommand(Control.SHUTDOWN); } - private void shutdownServer() { + void shutdownServer() { ServerState currentState; do { currentState = this.serverState.get(); @@ -329,7 +342,7 @@ public final class Start { * * @return <code>true</code> if all loaders were started. */ - private boolean startStartLoaders() { + boolean startStartLoaders() { synchronized (this.loaders) { // start the loaders for (StartupLoader loader : this.loaders) { @@ -357,28 +370,12 @@ public final class Start { } } - private void stopServer() { + void stopServer() { shutdownServer(); System.exit(0); } - // ----------------------------------------------- // - // commons-daemon interface - // http://commons.apache.org/proper/commons-daemon/jsvc.html - // ----------------------------------------------- // - - // DO NOT REMOVE: This method is needed by commons-daemon in reflection mode. - public void init(String[] args) throws StartupException { - init(args, true); - } - - // DO NOT REMOVE: This method is needed by commons-daemon in reflection mode. - public void destroy() { - // FIXME: undo init() calls. - } - - // DO NOT REMOVE: This method is needed by commons-daemon in reflection mode. - public void start() throws Exception { + void start() throws Exception { if (!startStartLoaders()) { if (this.serverState.get() == ServerState.STOPPING) { return; @@ -391,11 +388,6 @@ public final class Start { } } - // DO NOT REMOVE: This method is needed by commons-daemon in reflection mode. - public void stop() { - shutdownServer(); - } - // ----------------------------------------------- // private class AdminPortThread extends Thread { |
Free forum by Nabble | Edit this page |