You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by bo...@apache.org on 2007/07/19 03:56:08 UTC
svn commit: r557448 - in
/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao:
BpelDAOConnectionImpl.java ProcessDaoImpl.java
Author: boisvert
Date: Wed Jul 18 18:56:07 2007
New Revision: 557448
URL: http://svn.apache.org/viewvc?view=rev&rev=557448
Log:
Optimize MEX and instance timeout mechanism and avoid a rare case of innofensive NPE during cleanup
Modified:
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/BpelDAOConnectionImpl.java
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java
Modified: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/BpelDAOConnectionImpl.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/BpelDAOConnectionImpl.java?view=diff&rev=557448&r1=557447&r2=557448
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/BpelDAOConnectionImpl.java (original)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/BpelDAOConnectionImpl.java Wed Jul 18 18:56:07 2007
@@ -62,6 +62,7 @@
private static Map<String,MessageExchangeDAO> _mexStore = Collections.synchronizedMap(new HashMap<String,MessageExchangeDAO>());
protected static Map<String, Long> _mexAge = new ConcurrentHashMap<String, Long>();
private static AtomicLong counter = new AtomicLong(Long.MAX_VALUE / 2);
+ private static volatile long _lastRemoval = 0;
BpelDAOConnectionImpl(Map<QName, ProcessDaoImpl> store, Scheduler scheduler) {
_store = store;
@@ -177,17 +178,22 @@
public MessageExchangeDAO createMessageExchange(char dir) {
final String id = Long.toString(counter.getAndIncrement());
MessageExchangeDAO mex = new MessageExchangeDAOImpl(dir,id);
+ long now = System.currentTimeMillis();
_mexStore.put(id,mex);
- _mexAge.put(id, System.currentTimeMillis());
+ _mexAge.put(id, now);
- ArrayList<String> removals = new ArrayList<String>();
- for (Map.Entry<String, Long> entry : _mexAge.entrySet()) {
- if (System.currentTimeMillis() - entry.getValue() > TIME_TO_LIVE) {
- removeMessageExchange(entry.getKey());
- removals.add(entry.getKey());
+ if (now > _lastRemoval + (TIME_TO_LIVE/10)) {
+ _lastRemoval = now;
+ Object[] oldMexs = _mexAge.keySet().toArray();
+ for (int i=oldMexs.length-1; i>0; i--) {
+ String oldMex = (String) oldMexs[i];
+ Long age = _mexAge.get(oldMex);
+ if (age != null && now-age > TIME_TO_LIVE) {
+ removeMessageExchange(oldMex);
+ _mexAge.remove(oldMex);
+ }
}
}
- for (String removal : removals) _mexAge.remove(removal);
// Removing right away on rollback
onRollback(new Runnable() {
@@ -316,10 +322,11 @@
static void removeMessageExchange(String mexId) {
// Cleaning up mex
- __log.debug("Removing mex " + mexId + " from memory store.");
+ if (__log.isDebugEnabled()) __log.debug("Removing mex " + mexId + " from memory store.");
MessageExchangeDAO mex = _mexStore.remove(mexId);
if (mex == null)
- __log.debug("Couldn't find mex " + mexId + " for cleanup.");
+ __log.warn("Couldn't find mex " + mexId + " for cleanup.");
+ _mexAge.remove(mexId);
}
public void defer(final Runnable runnable) {
Modified: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java?view=diff&rev=557448&r1=557447&r2=557448
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java (original)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java Wed Jul 18 18:56:07 2007
@@ -18,6 +18,16 @@
*/
package org.apache.ode.bpel.memdao;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import javax.xml.namespace.QName;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ode.bpel.common.CorrelationKey;
@@ -27,15 +37,6 @@
import org.apache.ode.bpel.dao.ProcessDAO;
import org.apache.ode.bpel.dao.ProcessInstanceDAO;
-import javax.xml.namespace.QName;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
/**
* A very simple, in-memory implementation of the {@link ProcessDAO} interface.
*/
@@ -53,6 +54,7 @@
private BpelDAOConnectionImpl _conn;
private int _executionCount = 0;
private Collection<Long> _instancesToRemove = new ConcurrentLinkedQueue<Long>();
+ private static volatile long _lastRemoval = 0;
private String _guid;
@@ -108,18 +110,22 @@
_instances.put(newInstance.getInstanceId(), newInstance);
}
});
- _instancesAge.put(newInstance.getInstanceId(), System.currentTimeMillis());
+ long now = System.currentTimeMillis();
// Checking for old instances that could still be around because of a failure
// or completion problem
- ArrayList<Long> removals = new ArrayList<Long>();
- for (Map.Entry<Long, Long> entry : _instancesAge.entrySet()) {
- if (System.currentTimeMillis() - entry.getValue() > BpelDAOConnectionImpl.TIME_TO_LIVE) {
- ProcessInstanceDAO idao = _instances.remove(entry.getKey());
- removals.add(entry.getKey());
+ if (now > _lastRemoval + (BpelDAOConnectionImpl.TIME_TO_LIVE/10)) {
+ _lastRemoval = now;
+ Object[] oldInstances = _instancesAge.keySet().toArray();
+ for (int i=oldInstances.length-1; i>0; i--) {
+ Long old = (Long) oldInstances[i];
+ Long age = _instancesAge.get(old);
+ if (age != null && now-age > BpelDAOConnectionImpl.TIME_TO_LIVE) {
+ _instances.remove(old);
+ _instancesAge.remove(old);
+ }
}
}
- for (Long removal : removals) _instancesAge.remove(removal);
// Removing right away on rollback
final Long iid = newInstance.getInstanceId();
@@ -150,7 +156,9 @@
public void instanceCompleted(ProcessInstanceDAO instance) {
// Cleaning up
+ if (__log.isDebugEnabled())
__log.debug("Removing completed process instance " + instance.getInstanceId() + " from in-memory store.");
+ _instancesAge.remove(instance.getInstanceId());
ProcessInstanceDAO removed = _instances.remove(instance.getInstanceId());
if (removed == null) {
// Checking for leftover instances that should be removed