You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/09/19 06:04:12 UTC
svn commit: r577141 - in /ofbiz/trunk/framework/service: dtd/
src/org/ofbiz/service/ src/org/ofbiz/service/semaphore/
Author: jaz
Date: Tue Sep 18 21:04:08 2007
New Revision: 577141
URL: http://svn.apache.org/viewvc?rev=577141&view=rev
Log:
changed where semaphores are released (in finally block to make sure it is run even in the case of an exception) implemented per-service configurable settings for wait/sleep (sleep in milliseconds; wait in seconds) semaphore-wait-seconds="300" (default) is 5 minutes. The max time a service will wait before failing to run.
Modified:
ofbiz/trunk/framework/service/dtd/services.xsd
ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java
Modified: ofbiz/trunk/framework/service/dtd/services.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/dtd/services.xsd?rev=577141&r1=577140&r2=577141&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/dtd/services.xsd (original)
+++ ofbiz/trunk/framework/service/dtd/services.xsd Tue Sep 18 21:04:08 2007
@@ -101,8 +101,8 @@
</xs:restriction>
</xs:simpleType>
</xs:attribute>
- <xs:attribute type="xs:string" name="transaction-timeout"/>
- <xs:attribute type="xs:string" name="max-retry" default="-1"/>
+ <xs:attribute type="xs:int" name="transaction-timeout" default="0"/>
+ <xs:attribute type="xs:int" name="max-retry" default="-1"/>
<xs:attribute name="debug" default="false">
<xs:simpleType>
<xs:restriction base="xs:token">
@@ -121,6 +121,8 @@
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
+ <xs:attribute type="xs:int" name="semaphore-wait-seconds" default="300"/>
+ <xs:attribute type="xs:int" name="semaphore-sleep" default="500"/>
<xs:element name="notification">
<xs:complexType>
<xs:attributeGroup ref="attlist.notification"/>
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java?rev=577141&r1=577140&r2=577141&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java Tue Sep 18 21:04:08 2007
@@ -136,6 +136,12 @@
/** Semaphore setting (wait, fail, none) */
public String semaphore;
+
+ /** Semaphore wait time (in milliseconds) */
+ public int semaphoreWait;
+
+ /** Semaphore sleep time (in milliseconds) */
+ public int semaphoreSleep;
/** Set of services this service implements */
public Set implServices = new ListOrderedSet();
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java?rev=577141&r1=577140&r2=577141&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java Tue Sep 18 21:04:08 2007
@@ -273,6 +273,31 @@
service.useTransaction = !"false".equalsIgnoreCase(serviceElement.getAttribute("use-transaction"));
service.requireNewTransaction = !"false".equalsIgnoreCase(serviceElement.getAttribute("require-new-transaction"));
+ // set the semaphore sleep/wait times
+ String semaphoreWaitStr = UtilXml.checkEmpty(serviceElement.getAttribute("semaphore-wait-seconds"));
+ int semaphoreWait = 300;
+ if (!UtilValidate.isEmpty(semaphoreWaitStr)) {
+ try {
+ semaphoreWait = Integer.parseInt(semaphoreWaitStr);
+ } catch (NumberFormatException e) {
+ Debug.logWarning(e, "Setting semaphore-wait to 5 minutes (default)", module);
+ semaphoreWait = 300;
+ }
+ }
+ service.semaphoreWait = semaphoreWait;
+
+ String semaphoreSleepStr = UtilXml.checkEmpty(serviceElement.getAttribute("semaphore-sleep"));
+ int semaphoreSleep = 500;
+ if (!UtilValidate.isEmpty(semaphoreSleepStr)) {
+ try {
+ semaphoreSleep = Integer.parseInt(semaphoreSleepStr);
+ } catch (NumberFormatException e) {
+ Debug.logWarning(e, "Setting semaphore-sleep to 1/2 second (default)", module);
+ semaphoreSleep = 500;
+ }
+ }
+ service.semaphoreSleep = semaphoreSleep;
+
// set the max retry field
String maxRetryStr = UtilXml.checkEmpty(serviceElement.getAttribute("max-retry"));
int maxRetry = -1;
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=577141&r1=577140&r2=577141&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Tue Sep 18 21:04:08 2007
@@ -536,6 +536,11 @@
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();
+ }
+
// resume the parent transaction
if (parentTransaction != null) {
try {
@@ -560,11 +565,6 @@
Debug.logInfo("Sync service [" + localName + "/" + modelService.name + "] finished in [" + timeToRun + "] milliseconds", module);
}
- // release the semaphore lock
- if (lock != null) {
- lock.release();
- }
-
return result;
}
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java?rev=577141&r1=577140&r2=577141&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java Tue Sep 18 21:04:08 2007
@@ -17,8 +17,7 @@
/**
* ServiceSemaphore
*/
-public class ServiceSemaphore {
- // TODO: make sleep and max wait settings configurable per service
+public class ServiceSemaphore {
// TODO: add something to make sure semaphores are cleaned up on failures and when the thread somehow goes away without cleaning it up
// TODO: write service engine test cases to make sure semaphore both blocking and timing out (use config to set sleep and wait to low values so it times out quickly)
@@ -26,8 +25,6 @@
public static final int SEMAPHORE_MODE_FAIL = 0;
public static final int SEMAPHORE_MODE_WAIT = 1;
public static final int SEMAPHORE_MODE_NONE = 2;
- public static final long MAX_WAIT = 600;
- public static final long SLEEP = 500;
protected GenericDelegator delegator;
protected GenericValue lock;
@@ -66,11 +63,15 @@
// fail
throw new SemaphoreFailException("Service [" + model.name + "] is locked");
} else if (SEMAPHORE_MODE_WAIT == mode) {
+ // get the wait and sleep values
+ long maxWaitCount = ((model.semaphoreWait * 1000) / model.semaphoreSleep);
+ long sleep = model.semaphoreSleep;
+
boolean timedOut = true;
- while (wait < MAX_WAIT) {
+ while (wait < maxWaitCount) {
wait++;
try {
- Thread.sleep(SLEEP);
+ Thread.sleep(sleep);
} catch (InterruptedException e) {
Debug.logInfo(e, "Sleep interrupted: ServiceSemaphone.waitOrFail()", module);
}