You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2014/08/14 15:27:39 UTC
svn commit: r1617936 - in
/ofbiz/trunk/framework/start/src/org/ofbiz/base/start:
CommonsDaemonStart.java Start.java
Author: adrianc
Date: Thu Aug 14 13:27:39 2014
New Revision: 1617936
URL: http://svn.apache.org/r1617936
Log:
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/trunk/framework/start/src/org/ofbiz/base/start/CommonsDaemonStart.java
Modified:
ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java
Added: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/CommonsDaemonStart.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/CommonsDaemonStart.java?rev=1617936&view=auto
==============================================================================
--- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/CommonsDaemonStart.java (added)
+++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/CommonsDaemonStart.java Thu Aug 14 13:27:39 2014
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.base.start;
+
+
+/**
+ * Special startup class for Commons Daemon users.
+ *
+ * @see <a href="http://commons.apache.org/proper/commons-daemon/jsvc.html">Commons Daemon</a>
+ */
+public final class CommonsDaemonStart {
+
+ public CommonsDaemonStart() {
+ }
+
+ public void init(String[] args) throws StartupException {
+ Start.getInstance().init(args, true);
+ }
+
+ public void destroy() {
+ // FIXME: undo init() calls.
+ }
+
+ public void start() throws Exception {
+ Start.getInstance().start();
+ }
+
+ public void stop() {
+ Start.getInstance().shutdownServer();
+ }
+}
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=1617936&r1=1617935&r2=1617936&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 Thu Aug 14 13:27:39 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) {
@@ -129,14 +142,14 @@ public final class Start {
// ---------------------------------------------- //
- private Config config = null;
+ Config config = null;
private final List<String> loaderArgs = new ArrayList<String>();
private final ArrayList<StartupLoader> loaders = new ArrayList<StartupLoader>();
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 {