You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by sa...@apache.org on 2011/08/03 18:13:26 UTC
svn commit: r1153560 [12/15] - in /ofbiz/branches/jackrabbit20100709: ./
applications/accounting/config/ applications/accounting/data/
applications/accounting/entitydef/
applications/accounting/script/org/ofbiz/accounting/invoice/
applications/accounti...
Modified: ofbiz/branches/jackrabbit20100709/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java Wed Aug 3 16:12:58 2011
@@ -28,6 +28,8 @@ import java.util.Map;
import javax.transaction.Transaction;
import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.datasource.GenericHelperInfo;
import org.ofbiz.entity.jdbc.ConnectionFactory;
@@ -50,8 +52,9 @@ public class SequenceUtil {
private final String tableName;
private final String nameColName;
private final String idColName;
+ private final boolean clustered;
- public SequenceUtil(GenericHelperInfo helperInfo, ModelEntity seqEntity, String nameFieldName, String idFieldName) {
+ public SequenceUtil(GenericDelegator delegator, GenericHelperInfo helperInfo, ModelEntity seqEntity, String nameFieldName, String idFieldName) {
this.helperInfo = helperInfo;
if (seqEntity == null) {
throw new IllegalArgumentException("The sequence model entity was null but is required.");
@@ -76,6 +79,7 @@ public class SequenceUtil {
bankSize = seqEntity.getSequenceBankSize().longValue();
}
this.bankSize = bankSize;
+ clustered = delegator.useDistributedCacheClear() || "Y".equals(UtilProperties.getPropertyValue("general.properties", "clustered"));
}
public Long getNextSeqId(String seqName, long staggerMax, ModelEntity seqModelEntity) {
@@ -182,8 +186,8 @@ public class SequenceUtil {
this.seqName + "; start of loop val1=" + val1 + ", val2=" + val2 + ", bankSize=" + bankSize, module);
// not sure if this synchronized block is totally necessary, the method is synchronized but it does do a wait/sleep
- //outside of this block, and this is the really sensitive block, so making sure it is isolated; there is some overhead
- //to this, but very bad things can happen if we try to do too many of these at once for a single sequencer
+ // outside of this block, and this is the really sensitive block, so making sure it is isolated; there is some overhead
+ // to this, but very bad things can happen if we try to do too many of these at once for a single sequencer
synchronized (this) {
Transaction suspendedTransaction = null;
try {
@@ -218,8 +222,11 @@ public class SequenceUtil {
// we shouldn't need this, and some TX managers complain about it, so not including it: connection.setAutoCommit(false);
stmt = connection.createStatement();
-
- sql = "SELECT " + SequenceUtil.this.idColName + " FROM " + SequenceUtil.this.tableName + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'";
+ if (clustered) {
+ sql = "SELECT " + SequenceUtil.this.idColName + " FROM " + SequenceUtil.this.tableName + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'" + " FOR UPDATE";
+ } else {
+ sql = "SELECT " + SequenceUtil.this.idColName + " FROM " + SequenceUtil.this.tableName + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'";
+ }
rs = stmt.executeQuery(sql);
boolean gotVal1 = false;
if (rs.next()) {
@@ -241,8 +248,12 @@ public class SequenceUtil {
if (stmt.executeUpdate(sql) <= 0) {
throw new GenericEntityException("[SequenceUtil.SequenceBank.fillBank] update failed, no rows changes for seqName: " + seqName);
}
+ if (clustered) {
+ sql = "SELECT " + SequenceUtil.this.idColName + " FROM " + SequenceUtil.this.tableName + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'" + " FOR UPDATE";
- sql = "SELECT " + SequenceUtil.this.idColName + " FROM " + SequenceUtil.this.tableName + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'";
+ } else {
+ sql = "SELECT " + SequenceUtil.this.idColName + " FROM " + SequenceUtil.this.tableName + " WHERE " + SequenceUtil.this.nameColName + "='" + this.seqName + "'";
+ }
rs = stmt.executeQuery(sql);
boolean gotVal2 = false;
if (rs.next()) {
Modified: ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaRule.java Wed Aug 3 16:12:58 2011
@@ -37,7 +37,7 @@ import org.w3c.dom.Element;
* EntityEcaRule
*/
@SuppressWarnings("serial")
-public class EntityEcaRule implements java.io.Serializable {
+public final class EntityEcaRule implements java.io.Serializable {
public static final String module = EntityEcaRule.class.getName();
@@ -47,16 +47,14 @@ public class EntityEcaRule implements ja
nameSet.add("action");
}
- protected String entityName = null;
- protected String operationName = null;
- protected String eventName = null;
- protected boolean runOnError = false;
- protected List<EntityEcaCondition> conditions = FastList.newInstance();
- protected List<Object> actionsAndSets = FastList.newInstance();
+ protected final String entityName;
+ protected final String operationName;
+ protected final String eventName;
+ protected final boolean runOnError;
+ protected final List<EntityEcaCondition> conditions = FastList.newInstance();
+ protected final List<Object> actionsAndSets = FastList.newInstance();
protected boolean enabled = true;
- protected EntityEcaRule() {}
-
public EntityEcaRule(Element eca) {
this.entityName = eca.getAttribute("entity");
this.operationName = eca.getAttribute("operation");
@@ -71,7 +69,9 @@ public class EntityEcaRule implements ja
conditions.add(new EntityEcaCondition(element, false));
}
- if (Debug.verboseOn()) Debug.logVerbose("Conditions: " + conditions, module);
+ if (Debug.verboseOn()) {
+ Debug.logVerbose("Conditions: " + conditions, module);
+ }
for (Element actionOrSetElement: UtilXml.childElementList(eca, nameSet)) {
if ("action".equals(actionOrSetElement.getNodeName())) {
@@ -81,7 +81,25 @@ public class EntityEcaRule implements ja
}
}
- if (Debug.verboseOn()) Debug.logVerbose("actions and sets (intermixed): " + actionsAndSets, module);
+ if (Debug.verboseOn()) {
+ Debug.logVerbose("actions and sets (intermixed): " + actionsAndSets, module);
+ }
+ }
+
+ public String getEntityName() {
+ return this.entityName;
+ }
+
+ public String getOperationName() {
+ return this.operationName;
+ }
+
+ public String getEventName() {
+ return this.eventName;
+ }
+
+ public boolean getRunOnError() {
+ return this.runOnError;
}
public void eval(String currentOperation, DispatchContext dctx, GenericEntity value, boolean isError, Set<String> actionsRun) throws GenericEntityException {
@@ -117,7 +135,9 @@ public class EntityEcaRule implements ja
// in order to enable OR logic without multiple calls to the given service,
//only execute a given service name once per service call phase
if (actionsRun.add(ea.serviceName)) {
- if (Debug.infoOn()) Debug.logInfo("Running Entity ECA Service: " + ea.serviceName + ", triggered by rule on Entity: " + value.getEntityName(), module);
+ if (Debug.infoOn()) {
+ Debug.logInfo("Running Entity ECA Service: " + ea.serviceName + ", triggered by rule on Entity: " + value.getEntityName(), module);
+ }
ea.runAction(dctx, context, value);
}
} else {
Modified: ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaUtil.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaUtil.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaUtil.java Wed Aug 3 16:12:58 2011
@@ -21,11 +21,14 @@ package org.ofbiz.entityext.eca;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
import javolution.util.FastList;
import javolution.util.FastMap;
import org.ofbiz.base.component.ComponentConfig;
+import org.ofbiz.base.concurrent.ExecutionPool;
import org.ofbiz.base.config.GenericConfigException;
import org.ofbiz.base.config.MainResourceHandler;
import org.ofbiz.base.config.ResourceHandler;
@@ -78,55 +81,68 @@ public class EntityEcaUtil {
return;
}
+ List<Future<List<EntityEcaRule>>> futures = FastList.newInstance();
for (Element eecaResourceElement: entityEcaReaderInfo.resourceElements) {
ResourceHandler handler = new MainResourceHandler(EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME, eecaResourceElement);
- addEcaDefinitions(handler, ecaCache);
+ futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createEcaLoaderCallable(handler)));
}
// get all of the component resource eca stuff, ie specified in each ofbiz-component.xml file
for (ComponentConfig.EntityResourceInfo componentResourceInfo: ComponentConfig.getAllEntityResourceInfos("eca")) {
if (entityEcaReaderName.equals(componentResourceInfo.readerName)) {
- addEcaDefinitions(componentResourceInfo.createResourceHandler(), ecaCache);
+ futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createEcaLoaderCallable(componentResourceInfo.createResourceHandler())));
+ }
+ }
+
+ for (List<EntityEcaRule> oneFileRules: ExecutionPool.getAllFutures(futures)) {
+ for (EntityEcaRule rule: oneFileRules) {
+ String entityName = rule.getEntityName();
+ String eventName = rule.getEventName();
+ Map<String, List<EntityEcaRule>> eventMap = ecaCache.get(entityName);
+ List<EntityEcaRule> rules = null;
+ if (eventMap == null) {
+ eventMap = FastMap.newInstance();
+ rules = FastList.newInstance();
+ ecaCache.put(entityName, eventMap);
+ eventMap.put(eventName, rules);
+ } else {
+ rules = eventMap.get(eventName);
+ if (rules == null) {
+ rules = FastList.newInstance();
+ eventMap.put(eventName, rules);
+ }
+ }
+ rules.add(rule);
}
}
}
- protected static void addEcaDefinitions(ResourceHandler handler, Map<String, Map<String, List<EntityEcaRule>>> ecaCache) {
+ private static List<EntityEcaRule> getEcaDefinitions(ResourceHandler handler) {
+ List<EntityEcaRule> rules = FastList.newInstance();
Element rootElement = null;
try {
rootElement = handler.getDocument().getDocumentElement();
} catch (GenericConfigException e) {
Debug.logError(e, module);
- return;
+ return rules;
}
-
- int numDefs = 0;
for (Element e: UtilXml.childElementList(rootElement, "eca")) {
- String entityName = e.getAttribute("entity");
- String eventName = e.getAttribute("event");
- Map<String, List<EntityEcaRule>> eventMap = ecaCache.get(entityName);
- List<EntityEcaRule> rules = null;
- if (eventMap == null) {
- eventMap = FastMap.newInstance();
- rules = FastList.newInstance();
- ecaCache.put(entityName, eventMap);
- eventMap.put(eventName, rules);
- } else {
- rules = eventMap.get(eventName);
- if (rules == null) {
- rules = FastList.newInstance();
- eventMap.put(eventName, rules);
- }
- }
rules.add(new EntityEcaRule(e));
- numDefs++;
}
try {
- Debug.logImportant("Loaded [" + numDefs + "] Entity ECA definitions from " + handler.getFullLocation() + " in loader " + handler.getLoaderName(), module);
+ Debug.logImportant("Loaded [" + rules.size() + "] Entity ECA definitions from " + handler.getFullLocation() + " in loader " + handler.getLoaderName(), module);
} catch (GenericConfigException e) {
Debug.logError(e, module);
- return;
}
+ return rules;
+ }
+
+ protected static Callable<List<EntityEcaRule>> createEcaLoaderCallable(final ResourceHandler handler) {
+ return new Callable<List<EntityEcaRule>>() {
+ public List<EntityEcaRule> call() throws Exception {
+ return getEcaDefinitions(handler);
+ }
+ };
}
public static Collection<EntityEcaRule> getEntityEcaRules(Delegator delegator, String entityName, String event) {
Modified: ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java Wed Aug 3 16:12:58 2011
@@ -793,7 +793,7 @@ public class EntitySyncContext {
// if nothing moved over, remove the history record, otherwise store status
long totalRows = totalRowsToCreate + totalRowsToStore + totalRowsToRemove;
if (totalRows == 0) {
- String eshRemoveErrMsg = "Could not remove Entity Sync History (done becuase nothing was synced in this call), but all synchronization was successful";
+ String eshRemoveErrMsg = "Could not remove Entity Sync History (done because nothing was synced in this call), but all synchronization was successful";
try {
Map<String, Object> deleteEntitySyncHistRes = dispatcher.runSync("deleteEntitySyncHistory", UtilMisc.toMap("entitySyncId", entitySyncId, "startDate", startDate, "userLogin", userLogin));
if (ServiceUtil.isError(deleteEntitySyncHistRes)) {
Modified: ofbiz/branches/jackrabbit20100709/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java Wed Aug 3 16:12:58 2011
@@ -53,7 +53,7 @@ public class OrderValueList extends Meth
if (toListAcsr.isEmpty()) {
toListAcsr = listAcsr;
}
- orderByListAcsr = new ContextAccessor<List<String>>(element.getAttribute("order-by-list-name"));
+ orderByListAcsr = new ContextAccessor<List<String>>(element.getAttribute("order-by-list"), element.getAttribute("order-by-list-name"));
}
@Override
Propchange: ofbiz/branches/jackrabbit20100709/framework/security/data/PasswordSecurityData.xml
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug 3 16:12:58 2011
@@ -2,4 +2,4 @@
/ofbiz/branches/dojo1.4/applications/securityext/data/PasswordSecurityData.xml:951708-952957
/ofbiz/branches/jquery/applications/securityext/data/PasswordSecurityData.xml:952958-1044489
/ofbiz/branches/multitenant20100310/applications/securityext/data/PasswordSecurityData.xml:921280-927264
-/ofbiz/trunk/framework/security/data/PasswordSecurityData.xml:962442-1128853
+/ofbiz/trunk/framework/security/data/PasswordSecurityData.xml:962442-1153542
Modified: ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/DispatchContext.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/DispatchContext.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/DispatchContext.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/DispatchContext.java Wed Aug 3 16:12:58 2011
@@ -22,15 +22,20 @@ import java.io.Serializable;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
import javax.wsdl.WSDLException;
+import javolution.util.FastList;
import javolution.util.FastMap;
import org.ofbiz.base.component.ComponentConfig;
+import org.ofbiz.base.concurrent.ExecutionPool;
import org.ofbiz.base.config.GenericConfigException;
import org.ofbiz.base.config.MainResourceHandler;
import org.ofbiz.base.config.ResourceHandler;
@@ -290,6 +295,14 @@ public class DispatchContext implements
return serviceMap;
}
+ private Callable<Map<String, ModelService>> createServiceReaderCallable(final ResourceHandler handler) {
+ return new Callable<Map<String, ModelService>>() {
+ public Map<String, ModelService> call() throws Exception {
+ return ModelServiceReader.getModelServiceMap(handler, DispatchContext.this);
+ }
+ };
+ }
+
private Map<String, ModelService> getGlobalServiceMap() {
Map<String, ModelService> serviceMap = modelServiceMapByDispatcher.get(GLOBAL_KEY);
if (serviceMap == null) {
@@ -307,19 +320,19 @@ public class DispatchContext implements
return null;
}
+ List<Future<Map<String, ModelService>>> futures = FastList.newInstance();
for (Element globalServicesElement: UtilXml.childElementList(rootElement, "global-services")) {
ResourceHandler handler = new MainResourceHandler(
ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME, globalServicesElement);
- Map<String, ModelService> servicesMap = ModelServiceReader.getModelServiceMap(handler, this);
- if (servicesMap != null) {
- serviceMap.putAll(servicesMap);
- }
+ futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createServiceReaderCallable(handler)));
}
// get all of the component resource model stuff, ie specified in each ofbiz-component.xml file
for (ComponentConfig.ServiceResourceInfo componentResourceInfo: ComponentConfig.getAllServiceResourceInfos("model")) {
- Map<String, ModelService> servicesMap = ModelServiceReader.getModelServiceMap(componentResourceInfo.createResourceHandler(), this);
+ futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createServiceReaderCallable(componentResourceInfo.createResourceHandler())));
+ }
+ for (Map<String, ModelService> servicesMap: ExecutionPool.getAllFutures(futures)) {
if (servicesMap != null) {
serviceMap.putAll(servicesMap);
}
Modified: ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/GenericDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/GenericDispatcher.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/GenericDispatcher.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/GenericDispatcher.java Wed Aug 3 16:12:58 2011
@@ -78,19 +78,15 @@ public class GenericDispatcher extends G
}
ServiceDispatcher sd = serviceDispatcher != null ? serviceDispatcher : ServiceDispatcher.getInstance(dispatcherName, delegator);
- LocalDispatcher thisDispatcher = null;
+
if (sd != null) {
dispatcher = sd.getLocalDispatcher(dispatcherName);
}
- if (thisDispatcher == null) {
+ if (dispatcher == null) {
dispatcher = new GenericDispatcher(dispatcherName, delegator, readerURLs, loader, sd);
}
- if (dispatcher != null) {
- dispatcherCache.put(dispatcherName, dispatcher);
- } else {
- Debug.logError("Could not create dispatcher with name " + dispatcherName + ", constructor failed (got null value) not sure why/how.", module);
- }
+ dispatcherCache.put(dispatcherName, dispatcher);
}
}
}
Modified: ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Wed Aug 3 16:12:58 2011
@@ -116,7 +116,7 @@ public class ServiceDispatcher {
}
// make sure we haven't disabled these features from running
- if (enableJMS) {
+ if (enableJMS && this.delegator.getEnabledJMS()) {
this.jlf = new JmsListenerFactory(this);
}
@@ -1100,7 +1100,7 @@ public class ServiceDispatcher {
}
/**
- * Enabled/Disables the Job Manager/Scheduler globally
+ * Enables/Disables the Job Manager/Scheduler globally
* (this will not effect any dispatchers already running)
* @param enable
*/
@@ -1109,7 +1109,7 @@ public class ServiceDispatcher {
}
/**
- * Enabled/Disables the JMS listeners globally
+ * Enables/Disables the JMS listeners globally
* (this will not effect any dispatchers already running)
* @param enable
*/
@@ -1117,8 +1117,17 @@ public class ServiceDispatcher {
ServiceDispatcher.enableJMS = enable;
}
+
+ /**
+ * Get Enabled/Disabled JMS listeners status
+ * @return boolean true is JMS listeners are enabled
+ */
+ public static boolean getEnableJMS() {
+ return ServiceDispatcher.enableJMS;
+ }
+
/**
- * Enabled/Disables the startup services globally
+ * Enables/Disables the startup services globally
* (this will not effect any dispatchers already running)
* @param enable
*/
Modified: ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/eca/ServiceEcaRule.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/eca/ServiceEcaRule.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/eca/ServiceEcaRule.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/eca/ServiceEcaRule.java Wed Aug 3 16:12:58 2011
@@ -36,20 +36,18 @@ import org.w3c.dom.Element;
* ServiceEcaRule
*/
@SuppressWarnings("serial")
-public class ServiceEcaRule implements java.io.Serializable {
+public final class ServiceEcaRule implements java.io.Serializable {
public static final String module = ServiceEcaRule.class.getName();
- protected String serviceName = null;
- protected String eventName = null;
- protected boolean runOnFailure = false;
- protected boolean runOnError = false;
- protected List<ServiceEcaCondition> conditions = FastList.newInstance();
- protected List<Object> actionsAndSets = FastList.newInstance();
+ protected final String serviceName;
+ protected final String eventName;
+ protected final boolean runOnFailure;
+ protected final boolean runOnError;
+ protected final List<ServiceEcaCondition> conditions = FastList.newInstance();
+ protected final List<Object> actionsAndSets = FastList.newInstance();
protected boolean enabled = true;
- protected String definitionLocation = null;
-
- protected ServiceEcaRule() {}
+ protected final String definitionLocation;
public ServiceEcaRule(Element eca, String definitionLocation) {
this.definitionLocation = definitionLocation;
@@ -70,7 +68,9 @@ public class ServiceEcaRule implements j
conditions.add(new ServiceEcaCondition(element, false, true));
}
- if (Debug.verboseOn()) Debug.logVerbose("Conditions: " + conditions, module);
+ if (Debug.verboseOn()) {
+ Debug.logVerbose("Conditions: " + conditions, module);
+ }
Set<String> nameSet = UtilMisc.toSet("set", "action");
for (Element actionOrSetElement: UtilXml.childElementList(eca, nameSet)) {
@@ -81,7 +81,9 @@ public class ServiceEcaRule implements j
}
}
- if (Debug.verboseOn()) Debug.logVerbose("actions and sets (intermixed): " + actionsAndSets, module);
+ if (Debug.verboseOn()) {
+ Debug.logVerbose("actions and sets (intermixed): " + actionsAndSets, module);
+ }
}
public String getShortDisplayName() {
@@ -131,11 +133,15 @@ public class ServiceEcaRule implements j
boolean allCondTrue = true;
for (ServiceEcaCondition ec: conditions) {
if (!ec.eval(serviceName, dctx, context)) {
- if (Debug.infoOn()) Debug.logInfo("For Service ECA [" + this.serviceName + "] on [" + this.eventName + "] got false for condition: " + ec, module);
+ if (Debug.infoOn()) {
+ Debug.logInfo("For Service ECA [" + this.serviceName + "] on [" + this.eventName + "] got false for condition: " + ec, module);
+ }
allCondTrue = false;
break;
} else {
- if (Debug.verboseOn()) Debug.logVerbose("For Service ECA [" + this.serviceName + "] on [" + this.eventName + "] got true for condition: " + ec, module);
+ if (Debug.verboseOn()) {
+ Debug.logVerbose("For Service ECA [" + this.serviceName + "] on [" + this.eventName + "] got true for condition: " + ec, module);
+ }
}
}
@@ -147,7 +153,9 @@ public class ServiceEcaRule implements j
// in order to enable OR logic without multiple calls to the given service,
// only execute a given service name once per service call phase
if (!actionsRun.contains(ea.serviceName)) {
- if (Debug.infoOn()) Debug.logInfo("Running Service ECA Service: " + ea.serviceName + ", triggered by rule on Service: " + serviceName, module);
+ if (Debug.infoOn()) {
+ Debug.logInfo("Running Service ECA Service: " + ea.serviceName + ", triggered by rule on Service: " + serviceName, module);
+ }
if (ea.runAction(serviceName, dctx, context, result)) {
actionsRun.add(ea.serviceName);
}
@@ -172,14 +180,28 @@ public class ServiceEcaRule implements j
public boolean equals(Object obj) {
if (obj instanceof ServiceEcaRule) {
ServiceEcaRule other = (ServiceEcaRule) obj;
- if (!UtilValidate.areEqual(this.serviceName, other.serviceName)) return false;
- if (!UtilValidate.areEqual(this.eventName, other.eventName)) return false;
- if (!this.conditions.equals(other.conditions)) return false;
- if (!this.actionsAndSets.equals(other.actionsAndSets)) return false;
-
- if (this.runOnFailure != other.runOnFailure) return false;
- if (this.runOnError != other.runOnError) return false;
- if (this.enabled != other.enabled) return false;
+ if (!UtilValidate.areEqual(this.serviceName, other.serviceName)) {
+ return false;
+ }
+ if (!UtilValidate.areEqual(this.eventName, other.eventName)) {
+ return false;
+ }
+ if (!this.conditions.equals(other.conditions)) {
+ return false;
+ }
+ if (!this.actionsAndSets.equals(other.actionsAndSets)) {
+ return false;
+ }
+
+ if (this.runOnFailure != other.runOnFailure) {
+ return false;
+ }
+ if (this.runOnError != other.runOnError) {
+ return false;
+ }
+ if (this.enabled != other.enabled) {
+ return false;
+ }
return true;
} else {
Modified: ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/eca/ServiceEcaUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/eca/ServiceEcaUtil.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/eca/ServiceEcaUtil.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/eca/ServiceEcaUtil.java Wed Aug 3 16:12:58 2011
@@ -23,11 +23,14 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
import javolution.util.FastList;
import javolution.util.FastMap;
import org.ofbiz.base.component.ComponentConfig;
+import org.ofbiz.base.concurrent.ExecutionPool;
import org.ofbiz.base.config.GenericConfigException;
import org.ofbiz.base.config.MainResourceHandler;
import org.ofbiz.base.config.ResourceHandler;
@@ -69,24 +72,43 @@ public class ServiceEcaUtil {
return;
}
+ List<Future<List<ServiceEcaRule>>> futures = FastList.newInstance();
for (Element serviceEcasElement: UtilXml.childElementList(rootElement, "service-ecas")) {
ResourceHandler handler = new MainResourceHandler(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME, serviceEcasElement);
- addEcaDefinitions(handler);
+ futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createEcaLoaderCallable(handler)));
}
// get all of the component resource eca stuff, ie specified in each ofbiz-component.xml file
for (ComponentConfig.ServiceResourceInfo componentResourceInfo: ComponentConfig.getAllServiceResourceInfos("eca")) {
- addEcaDefinitions(componentResourceInfo.createResourceHandler());
+ futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createEcaLoaderCallable(componentResourceInfo.createResourceHandler())));
}
+
+ for (List<ServiceEcaRule> handlerRules: ExecutionPool.getAllFutures(futures)) {
+ mergeEcaDefinitions(handlerRules);
+ }
+ }
+
+ protected static Callable<List<ServiceEcaRule>> createEcaLoaderCallable(final ResourceHandler handler) {
+ return new Callable<List<ServiceEcaRule>>() {
+ public List<ServiceEcaRule> call() throws Exception {
+ return getEcaDefinitions(handler);
+ }
+ };
}
public static void addEcaDefinitions(ResourceHandler handler) {
+ List<ServiceEcaRule> handlerRules = getEcaDefinitions(handler);
+ mergeEcaDefinitions(handlerRules);
+ }
+
+ private static List<ServiceEcaRule> getEcaDefinitions(ResourceHandler handler) {
+ List<ServiceEcaRule> handlerRules = FastList.newInstance();
Element rootElement = null;
try {
rootElement = handler.getDocument().getDocumentElement();
} catch (GenericConfigException e) {
Debug.logError(e, module);
- return;
+ return handlerRules;
}
String resourceLocation = handler.getLocation();
@@ -95,11 +117,19 @@ public class ServiceEcaUtil {
} catch (GenericConfigException e) {
Debug.logError(e, "Could not get resource URL", module);
}
-
- int numDefs = 0;
for (Element e: UtilXml.childElementList(rootElement, "eca")) {
- String serviceName = e.getAttribute("service");
- String eventName = e.getAttribute("event");
+ handlerRules.add(new ServiceEcaRule(e, resourceLocation));
+ }
+ if (Debug.importantOn()) {
+ Debug.logImportant("Loaded [" + StringUtil.leftPad(Integer.toString(handlerRules.size()), 2) + "] Service ECA Rules from " + resourceLocation, module);
+ }
+ return handlerRules;
+ }
+
+ private static void mergeEcaDefinitions(List<ServiceEcaRule> handlerRules) {
+ for (ServiceEcaRule rule: handlerRules) {
+ String serviceName = rule.getServiceName();
+ String eventName = rule.getEventName();
Map<String, List<ServiceEcaRule>> eventMap = ecaCache.get(serviceName);
List<ServiceEcaRule> rules = null;
@@ -115,11 +145,7 @@ public class ServiceEcaUtil {
eventMap.put(eventName, rules);
}
}
- rules.add(new ServiceEcaRule(e, resourceLocation));
- numDefs++;
- }
- if (Debug.importantOn()) {
- Debug.logImportant("Loaded [" + StringUtil.leftPad(Integer.toString(numDefs), 2) + "] Service ECA Rules from " + resourceLocation, module);
+ rules.add(rule);
}
}
Modified: ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java Wed Aug 3 16:12:58 2011
@@ -177,7 +177,7 @@ public class PersistedServiceJob extends
} catch (GenericEntityException e) {
throw new RuntimeException(e.getMessage());
}
- if (Debug.infoOn()) Debug.logInfo(this.toString() + "[" + getJobId() + "] -- Next runtime: " + new Date(nextRecurrence), module);
+ if (Debug.infoOn()) Debug.logInfo("Job [" + getJobName() + "] Id [" + getJobId() + "] -- Next runtime: " + new Date(nextRecurrence), module);
}
private void createRecurrence(GenericValue job, long next) throws GenericEntityException {
Modified: ofbiz/branches/jackrabbit20100709/framework/sql/src/org/ofbiz/sql/SelectGroup.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/sql/src/org/ofbiz/sql/SelectGroup.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/sql/src/org/ofbiz/sql/SelectGroup.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/sql/src/org/ofbiz/sql/SelectGroup.java Wed Aug 3 16:12:58 2011
@@ -52,7 +52,7 @@ public final class SelectGroup extends A
}
public Collection<FieldDef> getFieldDefs() {
- return fieldDefs.values();
+ return fieldDefs != null ? fieldDefs.values() : null;
}
public Table getTable() {
Modified: ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Classpath.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Classpath.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Classpath.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Classpath.java Wed Aug 3 16:12:58 2011
@@ -59,6 +59,8 @@ public class Classpath {
_elements.add(key);
return true;
}
+ } else {
+ System.out.println("Warning : Module classpath component '" + component + "' is not valid and will be ignored...");
}
} catch (IOException e) {}
}
Modified: ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Config.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Config.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Config.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Config.java Wed Aug 3 16:12:58 2011
@@ -1,434 +1,437 @@
-/*******************************************************************************
- * 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;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
-import java.util.TimeZone;
-
-public class Config {
- public static final double REQUIRED_JDK = 1.6;
-
- private static String getConfigFileName(String command) {
- // default command is "start"
- if (command == null || command.trim().length() == 0) {
- command = "start";
- }
- // strip off the leading dash
- if (command.startsWith("-")) {
- command = command.substring(1);
- }
- // shutdown & status hack
- if (command.equalsIgnoreCase("shutdown")) {
- command = "start";
- } else if (command.equalsIgnoreCase("status")) {
- command = "start";
- }
- return "org/ofbiz/base/start/" + command + ".properties";
- }
-
- public static Config getInstance(String[] args) throws IOException {
- String firstArg = args.length > 0 ? args[0] : "";
- String configFileName = getConfigFileName(firstArg);
- Config result = new Config();
- result.readConfig(configFileName);
- return result;
- }
-
- public InetAddress adminAddress;
- public String adminKey;
- public int adminPort;
- public String awtHeadless;
- public String baseConfig;
- public String baseDtd;
- public String baseJar;
- public String baseLib;
- public String commJar;
- public String containerConfig;
- public String instrumenterClassName;
- public String instrumenterFile;
- public List<String> loaders;
- public String logDir;
- public String ofbizHome;
- public boolean requireCommJar = false;
- public boolean requireToolsJar = false;
- public boolean shutdownAfterLoad = false;
- public String splashLogo;
- public String testConfig;
- public String toolsJar;
- public boolean useShutdownHook = true;
-
- private String findSystemJar(Properties props, String javaVendor, String javaVersion, String jarName, boolean required) {
- String fileSep = System.getProperty("file.separator");
- String javaHome = System.getProperty("java.home");
- String errorMsg = "Unable to locate " + jarName + " - ";
- // String foundMsg = "Found " + jarName + " - ";
- String jarLoc = "lib" + fileSep + jarName;
- File tj = null;
-
- if ("tools.jar".equals(jarName) && javaVendor.startsWith("Apple")) {
- // tools.jar is always available in Apple's JDK implementation
- return null;
- }
-
- // check to see if it is in the OFBIZ_HOME directory
- tj = new File(ofbizHome + fileSep + jarName);
- if (tj.exists()) {
- return null;
- }
-
- // check to see if it is in the base/lib directory
- tj = new File(baseLib + fileSep + jarName);
- if (tj.exists()) {
- return null;
- }
-
- // try to locate tools.jar from the properties file
- String jarProps = props.getProperty("java." + jarName, null);
- if (jarProps != null) {
- tj = new File(jarProps);
- if (!tj.exists()) {
- if (required) {
- System.err.println(errorMsg + tj.getAbsolutePath());
- }
- } else {
- // System.out.println(foundMsg + tj.getAbsolutePath());
- return jarProps;
- }
- }
-
- // next check the JAVA_HOME lib dir
- tj = new File(javaHome + fileSep + jarLoc);
- if (!tj.exists()) {
- if (required) {
- System.err.println(errorMsg + tj.getAbsolutePath());
- }
- } else {
- // System.out.println(foundMsg + tj.getAbsolutePath());
- return tj.getAbsolutePath();
- }
-
- // next if we are a JRE dir check the parent dir
- String jreExt = fileSep + "jre";
- if (javaHome.toLowerCase().endsWith(jreExt)) {
- javaHome = javaHome.substring(0, javaHome.lastIndexOf(fileSep));
- tj = new File(javaHome + fileSep + jarLoc);
- if (!tj.exists()) {
- if (required) {
- System.err.println(errorMsg + tj.getAbsolutePath());
- }
- } else {
- // System.out.println(foundMsg + tj.getAbsolutePath());
- return tj.getAbsolutePath();
- }
- }
-
- // special windows checking
- if (javaHome.toLowerCase().charAt(1) == ':') {
- String driveLetter = javaHome.substring(0, 2);
- String windowsPath = driveLetter + fileSep + "j2sdk" + javaVersion;
- tj = new File(windowsPath + fileSep + jarLoc);
- if (!tj.exists()) {
- if (required) {
- System.err.println(errorMsg + tj.getAbsolutePath());
- }
- } else {
- // System.out.println(foundMsg + tj.getAbsolutePath());
- return tj.getAbsolutePath();
- }
- }
-
- if (required) {
- System.err.println("");
- System.err.println("Required library " + jarName + " could not be located.");
- System.err.println("Make sure you using Java2 SDK " + REQUIRED_JDK + "+ and NOT the JRE.");
- System.err.println("You may need to copy " + jarName + " into a loadable lib directory");
- System.err.println("(i.e. OFBIZ_HOME or OFBIZ_HOME/base/lib)");
- System.err.println("");
- System.exit(-1);
- }
-
- return null;
- }
-
- private String getOfbizHomeProp(Properties props, String key, String def) {
- String value = System.getProperty(key);
- if (value != null)
- return value;
- return ofbizHome + "/" + props.getProperty(key, def);
- }
-
- private String getProp(Properties props, String key, String def) {
- String value = System.getProperty(key);
- if (value != null)
- return value;
- return props.getProperty(key, def);
- }
-
- private Properties getPropertiesFile(String config) throws IOException {
- InputStream propsStream = null;
- Properties props = new Properties();
- try {
- // first try classpath
- propsStream = getClass().getClassLoader().getResourceAsStream(config);
- if (propsStream != null) {
- props.load(propsStream);
- } else {
- throw new IOException();
- }
- } catch (IOException e) {
- // next try file location
- File propsFile = new File(config);
- if (propsFile != null) {
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(propsFile);
- if (fis != null) {
- props.load(fis);
- } else {
- throw new FileNotFoundException();
- }
- } catch (FileNotFoundException e2) {
- // do nothing; we will see empty props below
- } finally {
- if (fis != null) {
- fis.close();
- }
- }
- }
- } finally {
- if (propsStream != null) {
- propsStream.close();
- }
- }
-
- // check for empty properties
- if (props.isEmpty()) {
- throw new IOException("Cannot load configuration properties : " + config);
- }
- return props;
- }
-
- public void initClasspath(Classpath classPath) throws IOException {
- // load tools.jar
- if (this.toolsJar != null) {
- classPath.addComponent(this.toolsJar);
- }
- // load comm.jar
- if (this.commJar != null) {
- classPath.addComponent(this.commJar);
- }
- // add OFBIZ_HOME to class path & load libs
- classPath.addClasspath(this.ofbizHome);
- loadLibs(classPath, this.ofbizHome, false);
- // load the lib directory
- if (this.baseLib != null) {
- loadLibs(classPath, this.baseLib, true);
- }
- // load the ofbiz-base.jar
- if (this.baseJar != null) {
- classPath.addComponent(this.baseJar);
- }
- // load the base schema directory
- if (this.baseDtd != null) {
- classPath.addComponent(this.baseDtd);
- }
- // load the config directory
- if (this.baseConfig != null) {
- classPath.addComponent(this.baseConfig);
- }
- classPath.instrument(this.instrumenterFile, this.instrumenterClassName);
- }
-
- private void loadLibs(Classpath classPath, String path, boolean recurse) throws IOException {
- File libDir = new File(path);
- if (libDir.exists()) {
- File files[] = libDir.listFiles();
- for (File file: files) {
- String fileName = file.getName();
- // FIXME: filter out other files?
- if (file.isDirectory() && !"CVS".equals(fileName) && !".svn".equals(fileName) && recurse) {
- loadLibs(classPath, file.getCanonicalPath(), recurse);
- } else if (fileName.endsWith(".jar") || fileName.endsWith(".zip")) {
- classPath.addComponent(file);
- }
- }
- }
- }
-
- public void readConfig(String config) throws IOException {
- // check the java_version
- String javaVersion = System.getProperty("java.version");
- String javaVendor = System.getProperty("java.vendor");
- double version = Double.parseDouble(javaVersion.substring(0, javaVersion.indexOf(".") + 2));
- if (REQUIRED_JDK > version) {
- System.err.println("");
- System.err.println("Java Version - " + javaVendor + " " + javaVersion + " - is not supported by OFBiz.");
- System.err.println("Please install Java2 SDK " + REQUIRED_JDK + "+");
- System.err.println("");
- System.exit(-1);
- }
-
- Properties props = this.getPropertiesFile(config);
- System.out.println("Start.java using configuration file " + config);
-
- // set the ofbiz.home
- if (ofbizHome == null) {
- ofbizHome = props.getProperty("ofbiz.home", ".");
- // get a full path
- if (ofbizHome.equals(".")) {
- ofbizHome = System.getProperty("user.dir");
- ofbizHome = ofbizHome.replace('\\', '/');
- System.out.println("Set OFBIZ_HOME to - " + ofbizHome);
- }
- }
- System.setProperty("ofbiz.home", ofbizHome);
-
- // base config directory
- baseConfig = getOfbizHomeProp(props, "ofbiz.base.config", "framework/base/config");
-
- // base schema directory
- baseDtd = getOfbizHomeProp(props, "ofbiz.base.schema", "framework/base/dtd");
-
- // base lib directory
- baseLib = getOfbizHomeProp(props, "ofbiz.base.lib", "framework/base/lib");
-
- // base jar file
- baseJar = getOfbizHomeProp(props, "ofbiz.base.jar", "framework/base/build/lib/ofbiz-base.jar");
-
- // tools jar
- String reqTJ = getProp(props, "java.tools.jar.required", "false");
- requireToolsJar = "true".equalsIgnoreCase(reqTJ);
- toolsJar = this.findSystemJar(props, javaVendor, javaVersion, "tools.jar", requireToolsJar);
-
- // comm jar
- String reqCJ = getProp(props, "java.comm.jar.required", "false");
- requireCommJar = "true".equalsIgnoreCase(reqCJ);
- commJar = this.findSystemJar(props, javaVendor, javaVersion, "comm.jar", requireCommJar);
-
- // log directory
- logDir = getOfbizHomeProp(props, "ofbiz.log.dir", "runtime/logs");
-
- // container configuration
- containerConfig = getOfbizHomeProp(props, "ofbiz.container.config", "framework/base/config/ofbiz-containers.xml");
-
- // get the admin server info
- String serverHost = getProp(props, "ofbiz.admin.host", "127.0.0.1");
-
- String adminPortStr = getProp(props, "ofbiz.admin.port", "0");
-
- // set the admin key
- adminKey = getProp(props, "ofbiz.admin.key", "NA");
-
- // create the host InetAddress
- adminAddress = InetAddress.getByName(serverHost);
-
- // parse the port number
- try {
- adminPort = Integer.parseInt(adminPortStr);
- } catch (Exception e) {
- adminPort = 0;
- }
-
- // set the Derby system home
- String derbyPath = getProp(props, "derby.system.home", "runtime/data/derby");
- System.setProperty("derby.system.home", derbyPath);
-
- // set the property to tell Log4J to use log4j.xml
- String log4jConfig = getProp(props, "log4j.configuration", "log4j.xml");
-
- // set the log4j configuration property so we don't pick up one inside jars by
- // mistake
- System.setProperty("log4j.configuration", log4jConfig);
-
- // check for shutdown hook
- if (System.getProperty("ofbiz.enable.hook") != null && System.getProperty("ofbiz.enable.hook").length() > 0) {
- useShutdownHook = "true".equalsIgnoreCase(System.getProperty("ofbiz.enable.hook"));
- } else if (props.getProperty("ofbiz.enable.hook") != null && props.getProperty("ofbiz.enable.hook").length() > 0) {
- useShutdownHook = "true".equalsIgnoreCase(props.getProperty("ofbiz.enable.hook"));
- }
-
- // check for auto-shutdown
- if (System.getProperty("ofbiz.auto.shutdown") != null && System.getProperty("ofbiz.auto.shutdown").length() > 0) {
- shutdownAfterLoad = "true".equalsIgnoreCase(System.getProperty("ofbiz.auto.shutdown"));
- } else if (props.getProperty("ofbiz.auto.shutdown") != null && props.getProperty("ofbiz.auto.shutdown").length() > 0) {
- shutdownAfterLoad = "true".equalsIgnoreCase(props.getProperty("ofbiz.auto.shutdown"));
- }
-
- // set AWT headless mode
- awtHeadless = getProp(props, "java.awt.headless", null);
- if (awtHeadless != null) {
- System.setProperty("java.awt.headless", awtHeadless);
- }
-
- // get the splash logo
- splashLogo = props.getProperty("ofbiz.start.splash.logo", null);
-
- // set the property to tell Jetty to use 2.4 SessionListeners
- System.setProperty("org.mortbay.jetty.servlet.AbstractSessionManager.24SessionDestroyed", "true");
-
- // set the default locale
- String localeString = props.getProperty("ofbiz.locale.default");
- if (localeString != null && localeString.length() > 0) {
- String args[] = localeString.split("_");
- switch (args.length) {
- case 1:
- Locale.setDefault(new Locale(args[0]));
- break;
- case 2:
- Locale.setDefault(new Locale(args[0], args[1]));
- break;
- case 3:
- Locale.setDefault(new Locale(args[0], args[1], args[2]));
- }
- System.setProperty("user.language", localeString);
- }
-
- // set the default time zone
- String tzString = props.getProperty("ofbiz.timeZone.default");
- if (tzString != null && tzString.length() > 0) {
- TimeZone.setDefault(TimeZone.getTimeZone(tzString));
- }
-
- instrumenterClassName = getProp(props, "ofbiz.instrumenterClassName", null);
- instrumenterFile = getProp(props, "ofbiz.instrumenterFile", null);
-
- // loader classes
- loaders = new ArrayList<String>();
- int currentPosition = 1;
- while (true) {
- String loaderClass = props.getProperty("ofbiz.start.loader" + currentPosition);
- if (loaderClass == null || loaderClass.length() == 0) {
- break;
- } else {
- loaders.add(loaderClass);
- currentPosition++;
- }
- }
- }
-
-}
+/*******************************************************************************
+ * 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;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.TimeZone;
+
+public class Config {
+ public static final double REQUIRED_JDK = 1.6;
+
+ private static String getConfigFileName(String command) {
+ // default command is "start"
+ if (command == null || command.trim().length() == 0) {
+ command = "start";
+ }
+ // strip off the leading dash
+ if (command.startsWith("-")) {
+ command = command.substring(1);
+ }
+ // shutdown & status hack
+ if (command.equalsIgnoreCase("shutdown")) {
+ command = "start";
+ } else if (command.equalsIgnoreCase("status")) {
+ command = "start";
+ }
+ return "org/ofbiz/base/start/" + command + ".properties";
+ }
+
+ public static Config getInstance(String[] args) throws IOException {
+ String firstArg = args.length > 0 ? args[0] : "";
+ String configFileName = getConfigFileName(firstArg);
+ Config result = new Config();
+ result.readConfig(configFileName);
+ return result;
+ }
+
+ public InetAddress adminAddress;
+ public String adminKey;
+ public int adminPort;
+ public String awtHeadless;
+ public String baseConfig;
+ public String baseDtd;
+ public String baseJar;
+ public String baseLib;
+ public String commJar;
+ public String containerConfig;
+ public String instrumenterClassName;
+ public String instrumenterFile;
+ public List<String> loaders;
+ public String logDir;
+ public String ofbizHome;
+ public boolean requireCommJar = false;
+ public boolean requireToolsJar = false;
+ public boolean shutdownAfterLoad = false;
+ public String splashLogo;
+ public String testConfig;
+ public String toolsJar;
+ public boolean useShutdownHook = true;
+
+ private String findSystemJar(Properties props, String javaVendor, String javaVersion, String jarName, boolean required) {
+ String fileSep = System.getProperty("file.separator");
+ String javaHome = System.getProperty("java.home");
+ String errorMsg = "Unable to locate " + jarName + " - ";
+ // String foundMsg = "Found " + jarName + " - ";
+ String jarLoc = "lib" + fileSep + jarName;
+ File tj = null;
+
+ if ("tools.jar".equals(jarName) && javaVendor.startsWith("Apple")) {
+ // tools.jar is always available in Apple's JDK implementation
+ return null;
+ }
+
+ // check to see if it is in the OFBIZ_HOME directory
+ tj = new File(ofbizHome + fileSep + jarName);
+ if (tj.exists()) {
+ return null;
+ }
+
+ // check to see if it is in the base/lib directory
+ tj = new File(baseLib + fileSep + jarName);
+ if (tj.exists()) {
+ return null;
+ }
+
+ // try to locate tools.jar from the properties file
+ String jarProps = props.getProperty("java." + jarName, null);
+ if (jarProps != null) {
+ tj = new File(jarProps);
+ if (!tj.exists()) {
+ if (required) {
+ System.err.println(errorMsg + tj.getAbsolutePath());
+ }
+ } else {
+ // System.out.println(foundMsg + tj.getAbsolutePath());
+ return jarProps;
+ }
+ }
+
+ // next check the JAVA_HOME lib dir
+ tj = new File(javaHome + fileSep + jarLoc);
+ if (!tj.exists()) {
+ if (required) {
+ System.err.println(errorMsg + tj.getAbsolutePath());
+ }
+ } else {
+ // System.out.println(foundMsg + tj.getAbsolutePath());
+ return tj.getAbsolutePath();
+ }
+
+ // next if we are a JRE dir check the parent dir
+ String jreExt = fileSep + "jre";
+ if (javaHome.toLowerCase().endsWith(jreExt)) {
+ javaHome = javaHome.substring(0, javaHome.lastIndexOf(fileSep));
+ tj = new File(javaHome + fileSep + jarLoc);
+ if (!tj.exists()) {
+ if (required) {
+ System.err.println(errorMsg + tj.getAbsolutePath());
+ }
+ } else {
+ // System.out.println(foundMsg + tj.getAbsolutePath());
+ return tj.getAbsolutePath();
+ }
+ }
+
+ // special windows checking
+ if (javaHome.toLowerCase().charAt(1) == ':') {
+ String driveLetter = javaHome.substring(0, 2);
+ String windowsPath = driveLetter + fileSep + "j2sdk" + javaVersion;
+ tj = new File(windowsPath + fileSep + jarLoc);
+ if (!tj.exists()) {
+ if (required) {
+ System.err.println(errorMsg + tj.getAbsolutePath());
+ }
+ } else {
+ // System.out.println(foundMsg + tj.getAbsolutePath());
+ return tj.getAbsolutePath();
+ }
+ }
+
+ if (required) {
+ System.err.println("");
+ System.err.println("Required library " + jarName + " could not be located.");
+ System.err.println("Make sure you using Java2 SDK " + REQUIRED_JDK + "+ and NOT the JRE.");
+ System.err.println("You may need to copy " + jarName + " into a loadable lib directory");
+ System.err.println("(i.e. OFBIZ_HOME or OFBIZ_HOME/base/lib)");
+ System.err.println("");
+ System.exit(-1);
+ }
+
+ return null;
+ }
+
+ private String getOfbizHomeProp(Properties props, String key, String def) {
+ String value = System.getProperty(key);
+ if (value != null)
+ return value;
+ return ofbizHome + "/" + props.getProperty(key, def);
+ }
+
+ private String getProp(Properties props, String key, String def) {
+ String value = System.getProperty(key);
+ if (value != null)
+ return value;
+ return props.getProperty(key, def);
+ }
+
+ private Properties getPropertiesFile(String config) throws IOException {
+ InputStream propsStream = null;
+ Properties props = new Properties();
+ try {
+ // first try classpath
+ propsStream = getClass().getClassLoader().getResourceAsStream(config);
+ if (propsStream != null) {
+ props.load(propsStream);
+ } else {
+ throw new IOException();
+ }
+ } catch (IOException e) {
+ // next try file location
+ File propsFile = new File(config);
+ if (propsFile != null) {
+ FileInputStream fis = null;
+ try {
+ fis = new FileInputStream(propsFile);
+ if (fis != null) {
+ props.load(fis);
+ } else {
+ throw new FileNotFoundException();
+ }
+ } catch (FileNotFoundException e2) {
+ // do nothing; we will see empty props below
+ } finally {
+ if (fis != null) {
+ fis.close();
+ }
+ }
+ }
+ } finally {
+ if (propsStream != null) {
+ propsStream.close();
+ }
+ }
+
+ // check for empty properties
+ if (props.isEmpty()) {
+ throw new IOException("Cannot load configuration properties : " + config);
+ }
+ return props;
+ }
+
+ public void initClasspath(Classpath classPath) throws IOException {
+ // load tools.jar
+ if (this.toolsJar != null) {
+ classPath.addComponent(this.toolsJar);
+ }
+ // load comm.jar
+ if (this.commJar != null) {
+ classPath.addComponent(this.commJar);
+ }
+ // add OFBIZ_HOME to class path & load libs
+ classPath.addClasspath(this.ofbizHome);
+ loadLibs(classPath, this.ofbizHome, false);
+ // load the lib directory
+ if (this.baseLib != null) {
+ loadLibs(classPath, this.baseLib, true);
+ }
+ // load the ofbiz-base.jar
+ if (this.baseJar != null) {
+ classPath.addComponent(this.baseJar);
+ }
+ // load the base schema directory
+ if (this.baseDtd != null) {
+ classPath.addComponent(this.baseDtd);
+ }
+ // load the config directory
+ if (this.baseConfig != null) {
+ classPath.addComponent(this.baseConfig);
+ }
+ classPath.instrument(this.instrumenterFile, this.instrumenterClassName);
+ }
+
+ private void loadLibs(Classpath classPath, String path, boolean recurse) throws IOException {
+ File libDir = new File(path);
+ if (libDir.exists()) {
+ File files[] = libDir.listFiles();
+ for (File file: files) {
+ String fileName = file.getName();
+ if (file.isHidden()) {
+ continue;
+ }
+ // FIXME: filter out other files?
+ if (file.isDirectory() && !"CVS".equals(fileName) && !".svn".equals(fileName) && recurse) {
+ loadLibs(classPath, file.getCanonicalPath(), recurse);
+ } else if (fileName.endsWith(".jar") || fileName.endsWith(".zip")) {
+ classPath.addComponent(file);
+ }
+ }
+ }
+ }
+
+ public void readConfig(String config) throws IOException {
+ // check the java_version
+ String javaVersion = System.getProperty("java.version");
+ String javaVendor = System.getProperty("java.vendor");
+ double version = Double.parseDouble(javaVersion.substring(0, javaVersion.indexOf(".") + 2));
+ if (REQUIRED_JDK > version) {
+ System.err.println("");
+ System.err.println("Java Version - " + javaVendor + " " + javaVersion + " - is not supported by OFBiz.");
+ System.err.println("Please install Java2 SDK " + REQUIRED_JDK + "+");
+ System.err.println("");
+ System.exit(-1);
+ }
+
+ Properties props = this.getPropertiesFile(config);
+ System.out.println("Start.java using configuration file " + config);
+
+ // set the ofbiz.home
+ if (ofbizHome == null) {
+ ofbizHome = props.getProperty("ofbiz.home", ".");
+ // get a full path
+ if (ofbizHome.equals(".")) {
+ ofbizHome = System.getProperty("user.dir");
+ ofbizHome = ofbizHome.replace('\\', '/');
+ System.out.println("Set OFBIZ_HOME to - " + ofbizHome);
+ }
+ }
+ System.setProperty("ofbiz.home", ofbizHome);
+
+ // base config directory
+ baseConfig = getOfbizHomeProp(props, "ofbiz.base.config", "framework/base/config");
+
+ // base schema directory
+ baseDtd = getOfbizHomeProp(props, "ofbiz.base.schema", "framework/base/dtd");
+
+ // base lib directory
+ baseLib = getOfbizHomeProp(props, "ofbiz.base.lib", "framework/base/lib");
+
+ // base jar file
+ baseJar = getOfbizHomeProp(props, "ofbiz.base.jar", "framework/base/build/lib/ofbiz-base.jar");
+
+ // tools jar
+ String reqTJ = getProp(props, "java.tools.jar.required", "false");
+ requireToolsJar = "true".equalsIgnoreCase(reqTJ);
+ toolsJar = this.findSystemJar(props, javaVendor, javaVersion, "tools.jar", requireToolsJar);
+
+ // comm jar
+ String reqCJ = getProp(props, "java.comm.jar.required", "false");
+ requireCommJar = "true".equalsIgnoreCase(reqCJ);
+ commJar = this.findSystemJar(props, javaVendor, javaVersion, "comm.jar", requireCommJar);
+
+ // log directory
+ logDir = getOfbizHomeProp(props, "ofbiz.log.dir", "runtime/logs");
+
+ // container configuration
+ containerConfig = getOfbizHomeProp(props, "ofbiz.container.config", "framework/base/config/ofbiz-containers.xml");
+
+ // get the admin server info
+ String serverHost = getProp(props, "ofbiz.admin.host", "127.0.0.1");
+
+ String adminPortStr = getProp(props, "ofbiz.admin.port", "0");
+
+ // set the admin key
+ adminKey = getProp(props, "ofbiz.admin.key", "NA");
+
+ // create the host InetAddress
+ adminAddress = InetAddress.getByName(serverHost);
+
+ // parse the port number
+ try {
+ adminPort = Integer.parseInt(adminPortStr);
+ } catch (Exception e) {
+ adminPort = 0;
+ }
+
+ // set the Derby system home
+ String derbyPath = getProp(props, "derby.system.home", "runtime/data/derby");
+ System.setProperty("derby.system.home", derbyPath);
+
+ // set the property to tell Log4J to use log4j.xml
+ String log4jConfig = getProp(props, "log4j.configuration", "log4j.xml");
+
+ // set the log4j configuration property so we don't pick up one inside jars by
+ // mistake
+ System.setProperty("log4j.configuration", log4jConfig);
+
+ // check for shutdown hook
+ if (System.getProperty("ofbiz.enable.hook") != null && System.getProperty("ofbiz.enable.hook").length() > 0) {
+ useShutdownHook = "true".equalsIgnoreCase(System.getProperty("ofbiz.enable.hook"));
+ } else if (props.getProperty("ofbiz.enable.hook") != null && props.getProperty("ofbiz.enable.hook").length() > 0) {
+ useShutdownHook = "true".equalsIgnoreCase(props.getProperty("ofbiz.enable.hook"));
+ }
+
+ // check for auto-shutdown
+ if (System.getProperty("ofbiz.auto.shutdown") != null && System.getProperty("ofbiz.auto.shutdown").length() > 0) {
+ shutdownAfterLoad = "true".equalsIgnoreCase(System.getProperty("ofbiz.auto.shutdown"));
+ } else if (props.getProperty("ofbiz.auto.shutdown") != null && props.getProperty("ofbiz.auto.shutdown").length() > 0) {
+ shutdownAfterLoad = "true".equalsIgnoreCase(props.getProperty("ofbiz.auto.shutdown"));
+ }
+
+ // set AWT headless mode
+ awtHeadless = getProp(props, "java.awt.headless", null);
+ if (awtHeadless != null) {
+ System.setProperty("java.awt.headless", awtHeadless);
+ }
+
+ // get the splash logo
+ splashLogo = props.getProperty("ofbiz.start.splash.logo", null);
+
+ // set the property to tell Jetty to use 2.4 SessionListeners
+ System.setProperty("org.mortbay.jetty.servlet.AbstractSessionManager.24SessionDestroyed", "true");
+
+ // set the default locale
+ String localeString = props.getProperty("ofbiz.locale.default");
+ if (localeString != null && localeString.length() > 0) {
+ String args[] = localeString.split("_");
+ switch (args.length) {
+ case 1:
+ Locale.setDefault(new Locale(args[0]));
+ break;
+ case 2:
+ Locale.setDefault(new Locale(args[0], args[1]));
+ break;
+ case 3:
+ Locale.setDefault(new Locale(args[0], args[1], args[2]));
+ }
+ System.setProperty("user.language", localeString);
+ }
+
+ // set the default time zone
+ String tzString = props.getProperty("ofbiz.timeZone.default");
+ if (tzString != null && tzString.length() > 0) {
+ TimeZone.setDefault(TimeZone.getTimeZone(tzString));
+ }
+
+ instrumenterClassName = getProp(props, "ofbiz.instrumenterClassName", null);
+ instrumenterFile = getProp(props, "ofbiz.instrumenterFile", null);
+
+ // loader classes
+ loaders = new ArrayList<String>();
+ int currentPosition = 1;
+ while (true) {
+ String loaderClass = props.getProperty("ofbiz.start.loader" + currentPosition);
+ if (loaderClass == null || loaderClass.length() == 0) {
+ break;
+ } else {
+ loaders.add(loaderClass);
+ currentPosition++;
+ }
+ }
+ }
+
+}
Modified: ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Start.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Start.java?rev=1153560&r1=1153559&r2=1153560&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Start.java (original)
+++ ofbiz/branches/jackrabbit20100709/framework/start/src/org/ofbiz/base/start/Start.java Wed Aug 3 16:12:58 2011
@@ -23,11 +23,14 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.ConnectException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
/**
* Start - OFBiz Container(s) Startup Class
@@ -38,42 +41,87 @@ public class Start {
private static final String SHUTDOWN_COMMAND = "SHUTDOWN";
private static final String STATUS_COMMAND = "STATUS";
- public static void main(String[] args) throws IOException {
- String firstArg = args.length > 0 ? args[0] : "";
- Start start = new Start();
-
- if (firstArg.equals("-help") || firstArg.equals("-?")) {
- System.out.println("");
- System.out.println("Usage: java -jar ofbiz.jar [command] [arguments]");
- System.out.println("-both -----> Run simultaneously the POS (Point of Sales) application and OFBiz standard");
- System.out.println("-help, -? ----> This screen");
- System.out.println("-install -----> Run install (create tables/load data)");
- System.out.println("-pos -----> Run the POS (Point of Sales) application");
- System.out.println("-setup -------> Run external application server setup");
- System.out.println("-start -------> Start the server");
- System.out.println("-status ------> Status of the server");
- System.out.println("-shutdown ----> Shutdown the server");
- System.out.println("-test --------> Run the JUnit test script");
- System.out.println("[no config] --> Use default config");
- System.out.println("[no command] -> Start the server w/ default config");
+ private static void help(PrintStream out) {
+ out.println("");
+ out.println("Usage: java -jar ofbiz.jar [command] [arguments]");
+ out.println("-both -----> Run simultaneously the POS (Point of Sales) application and OFBiz standard");
+ out.println("-help, -? ----> This screen");
+ out.println("-install -----> Run install (create tables/load data)");
+ out.println("-pos -----> Run the POS (Point of Sales) application");
+ out.println("-setup -------> Run external application server setup");
+ out.println("-start -------> Start the server");
+ out.println("-status ------> Status of the server");
+ out.println("-shutdown ----> Shutdown the server");
+ out.println("-test --------> Run the JUnit test script");
+ out.println("[no config] --> Use default config");
+ out.println("[no command] -> Start the server w/ default config");
+ }
+
+ private enum Command {
+ HELP, HELP_ERROR, STATUS, SHUTDOWN, COMMAND
+ }
+
+ private static Command checkCommand(Command command, Command wanted) {
+ if (wanted == Command.HELP || wanted.equals(command)) {
+ return wanted;
+ } else if (command == null) {
+ return wanted;
} else {
- // hack for the status and shutdown commands
- if (firstArg.equals("-status")) {
- start.init(args, false);
- System.out.println("Current Status : " + start.status());
- } else if (firstArg.equals("-shutdown")) {
- start.init(args, false);
- System.out.println("Shutting down server : " + start.shutdown());
+ System.err.println("Duplicate command detected(was " + command + ", wanted " + wanted);
+ return Command.HELP_ERROR;
+ }
+ }
+
+ public static void main(String[] args) throws IOException {
+ Command command = null;
+ List<String> loaderArgs = new ArrayList<String>(args.length);
+ System.err.println("debug: args=" + java.util.Arrays.asList(args));
+ for (String arg: args) {
+ if (arg.equals("-help") || arg.equals("-?")) {
+ command = checkCommand(command, Command.HELP);
+ } else if (arg.equals("-status")) {
+ command = checkCommand(command, Command.STATUS);
+ } else if (arg.equals("-shutdown")) {
+ command = checkCommand(command, Command.SHUTDOWN);
+ } else if (arg.startsWith("-")) {
+ command = checkCommand(command, Command.COMMAND);
+ loaderArgs.add(arg.substring(1));
} else {
- // general start
- start.init(args, true);
- start.start();
+ command = checkCommand(command, Command.COMMAND);
+ if (command == Command.COMMAND) {
+ loaderArgs.add(arg);
+ } else {
+ command = Command.HELP_ERROR;
+ }
}
}
+ System.err.println("debug: command=" + command);
+ System.err.println("debug: loaderArgs=" + loaderArgs);
+ if (command == null) {
+ command = Command.COMMAND;
+ loaderArgs.add("start");
+ }
+ if (command == Command.HELP) {
+ help(System.out);
+ return;
+ } else if (command == Command.HELP_ERROR) {
+ help(System.err);
+ System.exit(1);
+ }
+ Start start = new Start();
+ start.init(args, command == Command.COMMAND);
+ if (command == Command.STATUS) {
+ System.out.println("Current Status : " + start.status());
+ } else if (command == Command.SHUTDOWN) {
+ System.out.println("Shutting down server : " + start.shutdown());
+ } else {
+ // general start
+ start.start();
+ }
}
private Config config = null;
- private String[] loaderArgs = null;
+ private List<String> loaderArgs = new ArrayList<String>();
private final ArrayList<StartupLoader> loaders = new ArrayList<StartupLoader>();
private boolean serverStarted = false;
private boolean serverStopping = false;
@@ -111,34 +159,33 @@ public class Start {
}
}
this.config = Config.getInstance(args);
-
// parse the startup arguments
- if (args.length > 0) {
- this.loaderArgs = new String[args.length];
- System.arraycopy(args, 0, this.loaderArgs, 0, this.loaderArgs.length);
+ if (args.length > 1) {
+ this.loaderArgs.addAll(Arrays.asList(args).subList(1, args.length));
}
- if (fullInit) {
- // initialize the classpath
- initClasspath();
+ if (!fullInit) {
+ return;
+ }
+ // initialize the classpath
+ initClasspath();
- // create the log directory
- createLogDirectory();
+ // create the log directory
+ createLogDirectory();
- // create the listener thread
- createListenerThread();
+ // create the listener thread
+ createListenerThread();
- // set the shutdown hook
- if (config.useShutdownHook) {
- Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { shutdownServer(); } });
- } else {
- System.out.println("Shutdown hook disabled");
- }
+ // set the shutdown hook
+ if (config.useShutdownHook) {
+ Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { shutdownServer(); } });
+ } else {
+ System.out.println("Shutdown hook disabled");
+ }
- // initialize the startup loaders
- if (!initStartLoaders()) {
- System.exit(99);
- }
+ // initialize the startup loaders
+ if (!initStartLoaders()) {
+ System.exit(99);
}
}
@@ -166,8 +213,8 @@ public class Start {
try {
Class<?> loaderClass = classloader.loadClass(loaderClassName);
StartupLoader loader = (StartupLoader) loaderClass.newInstance();
- loader.load(config, loaderArgs);
- this.loaders.add(loader);
+ loader.load(config, loaderArgs.toArray(new String[loaderArgs.size()]));
+ loaders.add(loader);
} catch (Exception e) {
e.printStackTrace();
return false;
@@ -256,15 +303,13 @@ public class Start {
}
public String status() throws IOException {
- String status = null;
try {
- status = sendSocketCommand(Start.STATUS_COMMAND);
+ return sendSocketCommand(Start.STATUS_COMMAND);
} catch (ConnectException e) {
return "Not Running";
} catch (IOException e) {
throw e;
}
- return status;
}
public void stopServer() {