Author: mszefler
Date: Thu Dec 14 12:58:15 2006
New Revision: 487349

URL: http://svn.apache.org/viewvc?view=rev&rev=487349
Log:
Fixed bugs that were causing ActivityRecoverTest to fail. 
There were:
* Problems with quartz scheduler shutdown routine. Quartz was not getting 
unregistered from 
its internal scheduler repository
* Bug in the logic for when a ProcessDAO is deleted/recreted
* Test case counter variables were not getting reset in tearDown()


Modified:
    
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelServerImpl.java
    
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
    
incubator/ode/trunk/bpel-scheduler-quartz/src/main/java/org/apache/ode/bpel/scheduler/quartz/QuartzSchedulerImpl.java

Modified: 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelServerImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelServerImpl.java?view=diff&rev=487349&r1=487348&r2=487349
==============================================================================
--- 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelServerImpl.java
 (original)
+++ 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelServerImpl.java
 Thu Dec 14 12:58:15 2006
@@ -41,15 +41,16 @@
 
 /**
  * <p>
- * The BPEL server implementation. 
+ * The BPEL server implementation.
  * </p>
  * 
- * <p>This implementation is intended to be thread
- * safe. The key concurrency mechanism is a "management" read/write lock that
- * synchronizes all management operations (they require "write" access) and
- * prevents concurrent management operations and processing (processing 
requires
- * "read" access). Write access to the lock is scoped to the method, while read
- * access is scoped to a transaction.
+ * <p>
+ * This implementation is intended to be thread safe. The key concurrency
+ * mechanism is a "management" read/write lock that synchronizes all management
+ * operations (they require "write" access) and prevents concurrent management
+ * operations and processing (processing requires "read" access). Write access
+ * to the lock is scoped to the method, while read access is scoped to a
+ * transaction.
  * </p>
  * 
  * @author Maciej Szefler <mszefler at gmail dot com>
@@ -69,11 +70,9 @@
     private ReadWriteLock _mngmtLock = new ReentrantReadWriteLock();
 
     private enum State {
-        SHUTDOWN, 
-        INIT, 
-        RUNNING
+        SHUTDOWN, INIT, RUNNING
     }
-    
+
     private State _state = State.SHUTDOWN;
 
     private Contexts _contexts = new Contexts();
@@ -129,7 +128,7 @@
                 __log.debug("stop() ignored -- already stopped");
                 return;
             }
-            
+
             __log.debug("BPEL SERVER STOPPING");
 
             _contexts.scheduler.stop();
@@ -172,7 +171,6 @@
         _contexts.bindingContext = bc;
     }
 
-
     public void init() throws BpelEngineException {
         _mngmtLock.writeLock().lock();
         try {
@@ -180,7 +178,7 @@
                 return;
 
             __log.debug("BPEL SERVER initializing ");
-            
+
             _db = new BpelDatabase(_contexts.dao, _contexts.scheduler);
             _state = State.INIT;
             _engine = new BpelEngineImpl(_contexts);
@@ -205,16 +203,15 @@
     }
 
     public BpelEngine getEngine() {
-        // TODO: acquire read lock and tie the release to the current 
transaction.
+        // TODO: acquire read lock and tie the release to the current
+        // transaction.
         return _engine;
     }
 
-  
-    
     public void register(ProcessConf conf) {
         if (conf == null)
             throw new NullPointerException("must specify non-null process 
configuration.");
-        
+
         __log.debug("register: " + conf.getProcessId());
 
         // Load the compiled process.
@@ -226,7 +223,6 @@
             __log.error(errmsg, e);
             throw new BpelEngineException(errmsg, e);
         }
-        
 
         // Ok, IO out of the way, we will mod the server state, so need to get 
a
         // lock.
@@ -258,11 +254,10 @@
                 }
             }
 
-
             // Create the processDAO if necessary.
             createProcessDAO(conf.getProcessId(), compiledProcess);
 
-            BpelProcess process = new BpelProcess(conf, compiledProcess, 
null,elangRegistry);
+            BpelProcess process = new BpelProcess(conf, compiledProcess, null, 
elangRegistry);
 
             _engine.registerProcess(process);
 
@@ -309,31 +304,70 @@
     private void createProcessDAO(final QName pid, final OProcess oprocess) {
         __log.debug("Creating process DAO for " + pid + " (guid=" + 
oprocess.guid + ")");
         try {
-            _db.exec(new BpelDatabase.Callable<Object>() {
-                public Object run(BpelDAOConnection conn) throws Exception {
+            boolean create = _db.exec(new BpelDatabase.Callable<Boolean>() {
+                public Boolean run(BpelDAOConnection conn) throws Exception {
                     ProcessDAO old = conn.getProcess(pid);
-                    if (old != null) {
-                        __log.debug("Found ProcessDAO for " + pid + " with 
GUID " + old.getGuid());
+                    if (old == null) {
+                        // we couldnt find the process, clearly we need to
+                        // create it
+                        return true;
+                    }
 
-                        if (oprocess.guid != null)
-                            if (!old.getGuid().equals(oprocess.guid)) {
-                                // TODO: Versioning will need to handle this 
differently.
-                                String errmsg = "ProcessDAO GUID " + 
old.getGuid() + " does not match " + oprocess.guid
-                                        + "; replacing.";
-                                __log.warn(errmsg);
-                                old.delete();
-                            } else
-                                return null;
-                        return null;
+                    __log.debug("Found ProcessDAO for " + pid + " with GUID " 
+ old.getGuid());
+
+                    if (oprocess.guid == null) {
+                        // No guid, old version assume its good
+                        return false;
                     }
 
-                    ProcessDAO newDao = conn.createProcess(pid, 
oprocess.getQName(), oprocess.guid);
-                    for (String correlator : oprocess.getCorrelators()) {
-                        newDao.addCorrelator(correlator);
+                    if (old.getGuid().equals(oprocess.guid)) {
+                        // Guids match, no need to create
+                        return false;
                     }
-                    return null;
+
+                    // GUIDS dont match, delete and create new
+                    // TODO: Versioning will need to handle this differently.
+                    String errmsg = "ProcessDAO GUID " + old.getGuid() + " 
does not match " + oprocess.guid
+                            + "; replacing.";
+                    __log.warn(errmsg);
+                    old.delete();
+
+                    return true;
+
                 }
             });
+
+            if (create)
+                _db.exec(new BpelDatabase.Callable<Object>() {
+                    public Object run(BpelDAOConnection conn) throws Exception 
{
+                        ProcessDAO old = conn.getProcess(pid);
+                        if (old != null) {
+                            __log.debug("Found ProcessDAO for " + pid + " with 
GUID " + old.getGuid());
+
+                            if (oprocess.guid != null) {
+                                if (!old.getGuid().equals(oprocess.guid)) {
+                                    // TODO: Versioning will need to handle 
this
+                                    // differently.
+                                    String errmsg = "ProcessDAO GUID " + 
old.getGuid() + " does not match "
+                                            + oprocess.guid + "; replacing.";
+                                    __log.warn(errmsg);
+                                    old.delete();
+                                } else {
+                                    return null;
+                                }
+                            } else {
+                                // no guid, consider compatible.
+                                return null;
+                            }
+                        }
+
+                        ProcessDAO newDao = conn.createProcess(pid, 
oprocess.getQName(), oprocess.guid);
+                        for (String correlator : oprocess.getCorrelators()) {
+                            newDao.addCorrelator(correlator);
+                        }
+                        return null;
+                    }
+                });
         } catch (BpelEngineException ex) {
             throw ex;
         } catch (Exception dce) {
@@ -393,7 +427,7 @@
         return compiledProcess;
     }
 
-    /* TODO: We need to have a method of cleaning up old deployment data. */ 
+    /* TODO: We need to have a method of cleaning up old deployment data. */
     private boolean deleteProcessDAO(final QName pid) {
 
         try {
@@ -413,7 +447,7 @@
             String errmsg = "DbError";
             __log.error(errmsg, ex);
             throw new BpelEngineException(errmsg, ex);
-        } 
+        }
 
     }
 }

Modified: 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java?view=diff&rev=487349&r1=487348&r2=487349
==============================================================================
--- 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
 (original)
+++ 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
 Thu Dec 14 12:58:15 2006
@@ -144,7 +144,9 @@
 
     protected void tearDown() throws Exception {
         _management.delete(null);
+        
         _server.shutdown();
+
         _server = null;
         _failFor = 0;
         _invoked = 0;

Modified: 
incubator/ode/trunk/bpel-scheduler-quartz/src/main/java/org/apache/ode/bpel/scheduler/quartz/QuartzSchedulerImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-scheduler-quartz/src/main/java/org/apache/ode/bpel/scheduler/quartz/QuartzSchedulerImpl.java?view=diff&rev=487349&r1=487348&r2=487349
==============================================================================
--- 
incubator/ode/trunk/bpel-scheduler-quartz/src/main/java/org/apache/ode/bpel/scheduler/quartz/QuartzSchedulerImpl.java
 (original)
+++ 
incubator/ode/trunk/bpel-scheduler-quartz/src/main/java/org/apache/ode/bpel/scheduler/quartz/QuartzSchedulerImpl.java
 Thu Dec 14 12:58:15 2006
@@ -108,7 +108,7 @@
         jobStore.setDataSource("managed");
 
         try {
-            _quartz = createScheduler("ODEScheduler", _id, new 
QuartzThreadPoolExecutorServiceImpl(_executorSvc,
+            _quartz = createScheduler(_id, _id, new 
QuartzThreadPoolExecutorServiceImpl(_executorSvc,
                     _threads), jobStore);
             _quartz.getSchedulerInstanceId();
             __instanceMap.put(_id, this);
@@ -131,11 +131,11 @@
     public void shutdown() {
         try {
             _quartz.shutdown();
+            SchedulerRepository.getInstance().remove(_id);
         } catch (Exception except) {
             throw new RuntimeException(except);
         } finally {
             __instanceMap.remove(_id);
-            SchedulerRepository.getInstance().remove(_id);
         }
     }
 


Reply via email to