Author: adrianc
Date: Mon Jul 16 09:05:14 2012
New Revision: 1361944
URL: http://svn.apache.org/viewvc?rev=1361944&view=rev
Log:
Fixed semaphore handling issues in ServiceDispatcher.java.
https://issues.apache.org/jira/browse/OFBIZ-4967
Modified:
ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
Modified:
ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=1361944&r1=1361943&r2=1361944&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
(original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
Mon Jul 16 09:05:14 2012
@@ -21,6 +21,7 @@ package org.ofbiz.service;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+
import javax.transaction.Transaction;
import javolution.util.FastList;
@@ -30,7 +31,6 @@ import org.ofbiz.base.config.GenericConf
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralRuntimeException;
import org.ofbiz.base.util.UtilMisc;
-import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilTimer;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilXml;
@@ -58,7 +58,6 @@ import org.ofbiz.service.semaphore.Servi
import org.w3c.dom.Element;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
-import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder;
/**
* Global Service Dispatcher
@@ -247,53 +246,47 @@ public class ServiceDispatcher {
* @throws GenericServiceException
*/
public Map<String, Object> runSync(String localName, ModelService
modelService, Map<String, ? extends Object> params, boolean validateOut) throws
ServiceAuthException, ServiceValidationException, GenericServiceException {
- // check for semaphore and aquire a lock
- ServiceSemaphore lock = null;
- if ("wait".equals(modelService.semaphore) ||
"fail".equals(modelService.semaphore)) {
- lock = new ServiceSemaphore(delegator, modelService);
- lock.acquire();
- }
-
long serviceStartTime = System.currentTimeMillis();
- if (Debug.verboseOn() || modelService.debug) {
- Debug.logVerbose("[ServiceDispatcher.runSync] : invoking service "
+ modelService.name + " [" + modelService.location +
- "/" + modelService.invoke + "] (" + modelService.engineName +
")", module);
- }
-
- Map<String, Object> context = FastMap.newInstance();
- if (params != null) {
- context.putAll(params);
- }
-
- // setup the result map and other initial settings
Map<String, Object> result = FastMap.newInstance();
+ ServiceSemaphore lock = null;
+ Map<String, List<ServiceEcaRule>> eventMap = null;
+ Map<String, Object> ecaContext = null;
+ RunningService rs = null;
+ DispatchContext ctx = localContext.get(localName);
+ GenericEngine engine = null;
+ Transaction parentTransaction = null;
boolean isFailure = false;
boolean isError = false;
+ boolean beganTrans = false;
+ try {
+ // check for semaphore and aquire a lock
+ if ("wait".equals(modelService.semaphore) ||
"fail".equals(modelService.semaphore)) {
+ lock = new ServiceSemaphore(delegator, modelService);
+ lock.acquire();
+ }
- // set up the running service log
- RunningService rs = this.logService(localName, modelService,
GenericEngine.SYNC_MODE);
-
- // get eventMap once for all calls for speed, don't do event calls if
it is null
- Map<String, List<ServiceEcaRule>> eventMap =
ServiceEcaUtil.getServiceEventMap(modelService.name);
-
- // check the locale
- Locale locale = this.checkLocale(context);
+ if (Debug.verboseOn() || modelService.debug) {
+ Debug.logVerbose("[ServiceDispatcher.runSync] : invoking
service " + modelService.name + " [" + modelService.location +
+ "/" + modelService.invoke + "] (" +
modelService.engineName + ")", module);
+ }
- // setup the engine and context
- DispatchContext ctx = localContext.get(localName);
- GenericEngine engine = this.getGenericEngine(modelService.engineName);
+ Map<String, Object> context = FastMap.newInstance();
+ if (params != null) {
+ context.putAll(params);
+ }
+ // check the locale
+ Locale locale = this.checkLocale(context);
- // set IN attributes with default-value as applicable
- modelService.updateDefaultValues(context, ModelService.IN_PARAM);
+ // set up the running service log
+ rs = this.logService(localName, modelService,
GenericEngine.SYNC_MODE);
- Map<String, Object> ecaContext = null;
+ // get eventMap once for all calls for speed, don't do event calls
if it is null
+ eventMap = ServiceEcaUtil.getServiceEventMap(modelService.name);
+ engine = this.getGenericEngine(modelService.engineName);
- // for isolated transactions
- Transaction parentTransaction = null;
- // start the transaction
- boolean beganTrans = false;
- try {
+ // set IN attributes with default-value as applicable
+ modelService.updateDefaultValues(context, ModelService.IN_PARAM);
//Debug.logInfo("=========================== " + modelService.name
+ " 1 tx status =" + TransactionUtil.getStatusString() + ",
modelService.requireNewTransaction=" + modelService.requireNewTransaction + ",
modelService.useTransaction=" + modelService.useTransaction + ",
TransactionUtil.isTransactionInPlace()=" +
TransactionUtil.isTransactionInPlace(), module);
if (modelService.useTransaction) {
if (TransactionUtil.isTransactionInPlace()) {
@@ -557,9 +550,13 @@ public class ServiceDispatcher {
Debug.logError(te, "Problems with the transaction", module);
throw new GenericServiceException("Problems with the
transaction.", te.getNested());
} finally {
- // release the semaphore lock
if (lock != null) {
- lock.release();
+ // release the semaphore lock
+ try {
+ lock.release();
+ } catch (GenericServiceException e) {
+ Debug.logWarning(e, "Exception thrown while unlocking
semaphore: ", module);
+ }
}
// resume the parent transaction