Author: assaf
Date: Thu Sep 28 11:33:18 2006
New Revision: 450962

URL: http://svn.apache.org/viewvc?view=rev&rev=450962
Log:
Activity recovery retry action working and tested

Modified:
    
incubator/ode/trunk/bpel-api/src/main/java/org/apache/ode/bpel/pmapi/InstanceManagement.java
    
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
    
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java
    
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementImpl.java
    
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/MockBpelServer.java
    incubator/ode/trunk/bpel-test/pom.xml
    incubator/ode/trunk/pom.xml

Modified: 
incubator/ode/trunk/bpel-api/src/main/java/org/apache/ode/bpel/pmapi/InstanceManagement.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-api/src/main/java/org/apache/ode/bpel/pmapi/InstanceManagement.java?view=diff&rev=450962&r1=450961&r2=450962
==============================================================================
--- 
incubator/ode/trunk/bpel-api/src/main/java/org/apache/ode/bpel/pmapi/InstanceManagement.java
 (original)
+++ 
incubator/ode/trunk/bpel-api/src/main/java/org/apache/ode/bpel/pmapi/InstanceManagement.java
 Thu Sep 28 11:33:18 2006
@@ -248,4 +248,13 @@
      */
     Collection<Long> delete(String filter);
 
+    /**
+     * Performs an activity recovery action.
+     * @param iid instance id (process)
+     * @param aiid instance id (activity)
+     * @param action recovery action (e.g. retry, fault)
+     * @return post-change instance information
+    */
+    InstanceInfoDocument recoverActivity(Long iid, Long aid, String action);
+
 }

Modified: 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java?view=diff&rev=450962&r1=450961&r2=450962
==============================================================================
--- 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
 (original)
+++ 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
 Thu Sep 28 11:33:18 2006
@@ -54,6 +54,7 @@
 import org.apache.ode.bpel.runtime.InvalidProcessException;
 import org.apache.ode.bpel.runtime.PROCESS;
 import org.apache.ode.bpel.runtime.PropertyAliasEvaluationContext;
+import org.apache.ode.bpel.runtime.channels.FaultData;
 import org.apache.ode.jacob.soup.ReplacementMap;
 import org.apache.ode.utils.ArrayUtils;
 import org.apache.ode.utils.ObjectPrinter;
@@ -146,6 +147,14 @@
 
     public String toString() {
         return "BpelProcess[" + _pid + " in " + _du + "]";
+    }
+
+    public void recoverActivity(ProcessInstanceDAO instanceDAO, String 
channel, String action, FaultData fault) {
+      if (__log.isDebugEnabled())
+        __log.debug("Recovering activity in process " + 
instanceDAO.getInstanceId() + " with action " + action );
+
+      BpelRuntimeContextImpl processInstance = 
createRuntimeContext(instanceDAO, null, null);
+      processInstance.recoverActivity(channel, action, fault);
     }
 
     static String generateMessageExchangeIdentifier(String partnerlinkName, 
String operationName) {

Modified: 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java?view=diff&rev=450962&r1=450961&r2=450962
==============================================================================
--- 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java
 (original)
+++ 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java
 Thu Sep 28 11:33:18 2006
@@ -1155,18 +1155,17 @@
             private static final long serialVersionUID = 3168964409165899533L;
 
             public void run() {
-                // ActivityRecoveryChannel channel = importChannel(channel,
-                // ActivityRecoveryChannel.class);
-                ActivityRecoveryChannel channel = null;
+                ActivityRecoveryChannel recovery = importChannel(channel, 
ActivityRecoveryChannel.class);
                 if ("cancel".equals(action))
-                    channel.cancel();
+                    recovery.cancel();
                 else if ("retry".equals(action))
-                    channel.retry();
+                    recovery.retry();
                 else if ("fault".equals(action))
-                    channel.fault(fault);
+                    recovery.fault(fault);
             }
         });
-        _dao.deleteActivityRecovery(channel);
+        //_dao.deleteActivityRecovery(channel);
+        execute();
     }
 
     /**

Modified: 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementImpl.java?view=diff&rev=450962&r1=450961&r2=450962
==============================================================================
--- 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementImpl.java
 (original)
+++ 
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementImpl.java
 Thu Sep 28 11:33:18 2006
@@ -315,29 +315,30 @@
         return genInstanceInfoDocument(iid);
     }
 
-    public InstanceInfoDocument recoverActivity(final Long iid, final long 
aid, final String action) {
-        try {
-            QName processId = _db.exec(new BpelDatabase.Callable<QName>() {
-                public QName run(BpelDAOConnection conn) throws Exception {
-                    ProcessInstanceDAO instance = conn.getInstance(iid);
-/*
-                    if (instance == null)
-                      return null;
-                    for (ActivityRecoveryDAO recovery: 
instance.getActivityRecoveries()) {
-                      if (recovery.getActivityId() == aid) {
-                        runtime.recoverActivity(recovery.getChannel(), action);
-                        break;
-                      }
-                    }
-*/
-                    return instance.getProcess().getProcessId();
+    public InstanceInfoDocument recoverActivity(final Long iid, final Long 
aid, final String action) {
+      try {
+        QName processId = _db.exec(new BpelDatabase.Callable<QName>() {
+          public QName run(BpelDAOConnection conn) throws Exception {
+            ProcessInstanceDAO instance = conn.getInstance(iid);
+            if (instance == null)
+              return null;
+            for (ActivityRecoveryDAO recovery: 
instance.getActivityRecoveries()) {
+              if (recovery.getActivityId() == aid) {
+                BpelProcess process = 
_engine._activeProcesses.get(instance.getProcess().getProcessId());
+                if (process != null) {
+                  process.recoverActivity(instance, recovery.getChannel(), 
action, null);
+                  break;
                 }
-            });
-        } catch (Exception e) {
-            __log.error("DbError",e);
-            throw new ProcessingException("DbError", e);
-        }
-        return genInstanceInfoDocument(iid);
+              }
+            }
+            return instance.getProcess().getProcessId();
+          }
+        });
+      } catch (Exception e) {
+        __log.error("DbError",e);
+        throw new ProcessingException("DbError", e);
+      }
+      return genInstanceInfoDocument(iid);
     }
 
     public Collection<Long> delete(String filter) {

Modified: 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/MockBpelServer.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/MockBpelServer.java?view=diff&rev=450962&r1=450961&r2=450962
==============================================================================
--- 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/MockBpelServer.java
 (original)
+++ 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/MockBpelServer.java
 Thu Sep 28 11:33:18 2006
@@ -81,9 +81,8 @@
   Jotm                      _jotm;
   MinervaPool               _minervaPool;
   DataSource                _dataSource;
-  Scheduler                 _scheduler;
+  SchedulerWrapper          _scheduler;
   BpelDAOConnectionFactory  _daoCF;
-  int                       _scheduled;
   EndpointReferenceContext  _eprContext;
   MessageExchangeContext    _mexContext;
   BindingContext            _bindContext;
@@ -108,6 +107,7 @@
       _server.setEndpointReferenceContext(createEndpointReferenceContext());
       _server.setMessageExchangeContext(createMessageExchangeContext());
       _server.setBindingContext(createBindingContext());
+      _server.setDeployDir("processes");
       _server.init();
       _server.start();
     } catch (Exception except) {
@@ -171,11 +171,13 @@
 
   public void waitForBlocking() {
     try {
-      // TODO: change this to lock on an object.
-      while (_scheduled > 0) {
-        Thread.sleep(5);
-        if (_scheduled == 0)
+      long delay = 1000;
+      while (true) {
+        // Be warned: ugly hack and not safe for slow CPUs.
+        long cutoff = System.currentTimeMillis() - delay;
+        if (_scheduler._nextSchedule < cutoff)
           break;
+        Thread.sleep(delay);
       }
     } catch (InterruptedException except) { }
   }
@@ -343,9 +345,10 @@
     }
   }
 
-    QuartzSchedulerImpl _quartz;
   private class SchedulerWrapper implements Scheduler {
 
+    QuartzSchedulerImpl _quartz;
+    long                _nextSchedule;
 
     SchedulerWrapper(BpelServer server, TransactionManager txManager, 
DataSource dataSource) {
       ExecutorService executorService = new ExecutorServiceWrapper();
@@ -359,19 +362,18 @@
 
     public String schedulePersistedJob(Map<String,Object>jobDetail,Date when) 
throws ContextException {
       String jobId = _quartz.schedulePersistedJob(jobDetail, when);
-      ++_scheduled;
+      _nextSchedule = when == null ?  System.currentTimeMillis() : 
when.getTime();
       return jobId;
     }
   
     public String scheduleVolatileJob(boolean transacted, Map<String,Object> 
jobDetail, Date when) throws ContextException {
       String jobId = _quartz.scheduleVolatileJob(transacted, jobDetail, when);
-      ++_scheduled;
+      _nextSchedule = when == null ?  System.currentTimeMillis() : 
when.getTime();
       return jobId;
     }
   
     public void cancelJob(String jobId) throws ContextException {
       _quartz.cancelJob(jobId);
-      --_scheduled;
     }
   
     public <T> T execTransaction(Callable<T> transaction) throws Exception, 
ContextException {
@@ -386,7 +388,6 @@
     private ExecutorService _service = Executors.newCachedThreadPool();
     public void execute(Runnable command) {
       _service.execute(command);
-      --_scheduled;
     }
     public boolean awaitTermination(long timeout, TimeUnit unit) throws 
InterruptedException {
       return _service.awaitTermination(timeout, unit);

Modified: incubator/ode/trunk/bpel-test/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/pom.xml?view=diff&rev=450962&r1=450961&r2=450962
==============================================================================
--- incubator/ode/trunk/bpel-test/pom.xml (original)
+++ incubator/ode/trunk/bpel-test/pom.xml Thu Sep 28 11:33:18 2006
@@ -28,9 +28,6 @@
     <version>2.0-SNAPSHOT</version>
   </parent>
   <version>2.0-SNAPSHOT</version>
-  <properties>
-   <maven.test.skip>false</maven.test.skip>
-  </properties>
   <dependencies>
    <dependency>
     <groupId>junit</groupId>

Modified: incubator/ode/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/pom.xml?view=diff&rev=450962&r1=450961&r2=450962
==============================================================================
--- incubator/ode/trunk/pom.xml (original)
+++ incubator/ode/trunk/pom.xml Thu Sep 28 11:33:18 2006
@@ -33,7 +33,6 @@
 
 
     <properties>
-        <maven.test.skip>true</maven.test.skip>
         <vendor.name>Apache Software Foundation</vendor.name>
         <!--
           Default ODE properties, these properties may be referenced in 
resources and the


Reply via email to