[jboss-svn-commits] JBL Code SVN: r18315 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP: product/samples/quickstarts/bpm_orchestration4/processDefinition and 7 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Feb 5 11:15:47 EST 2008


Author: kevin.conner at jboss.com
Date: 2008-02-05 11:15:47 -0500 (Tue, 05 Feb 2008)
New Revision: 18315

Added:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/AsyncProcessSignal.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/EchoSuspendAction.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmAsyncActionHandler.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmAsyncUnitTest.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmServer.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmServerMBean.java
Removed:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/AsyncTest.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/Wait2SecondsAction.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/.gpd.testAsync.xml
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/.gpd.testSync.xml
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testAsync.jpg
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testAsync.xml
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testSync.jpg
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testSync.xml
Modified:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/docs/services/jBPMIntegrationGuide.odt
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/docs/services/jBPMIntegrationGuide.pdf
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/bpm_orchestration4/processDefinition/processdefinition.xml
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/resources/META-INF/jboss-esb.xml
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/build.xml
Log:
Make jBPM callback async, support suspended processes: JBESB-1483, JBESB-1511

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/docs/services/jBPMIntegrationGuide.odt
===================================================================
(Binary files differ)

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/docs/services/jBPMIntegrationGuide.pdf
===================================================================
(Binary files differ)

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/bpm_orchestration4/processDefinition/processdefinition.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/bpm_orchestration4/processDefinition/processdefinition.xml	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/samples/quickstarts/bpm_orchestration4/processDefinition/processdefinition.xml	2008-02-05 16:15:47 UTC (rev 18315)
@@ -6,7 +6,7 @@
       <transition name="" to="Intake Order"></transition>
    </start-state>
 
-   <node name="Intake Order" async="true">
+   <node name="Intake Order">
          
          <action name="esbAction" class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
             <esbCategoryName>BPM_Orchestration4</esbCategoryName>
@@ -31,7 +31,7 @@
       <transition name="" to="Review Order"></transition>
    </node>
    
-   <task-node name="Review Order" async="true">
+   <task-node name="Review Order">
       <task name="Order Review">
          <assignment actor-id="user"></assignment>
 			<controller>
@@ -48,7 +48,7 @@
       <transition name="" to="Calculate Discount"></transition>
    </task-node>
    
-   <node name="Calculate Discount" async="true">         
+   <node name="Calculate Discount">         
           
          <action name="esbAction" class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler">
             <esbCategoryName>BPM_Orchestration4</esbCategoryName>
@@ -67,14 +67,14 @@
       <transition name="" to="Review Discount"></transition>
    </node>
 
-   <task-node name="Review Discount" async="true">
+   <task-node name="Review Discount">
       <task name="Discount Review">
 			<assignment actor-id="manager"></assignment>
 		</task>
       <transition name="" to="Ship It"></transition>
    </task-node>
 
-   <node name="Ship It" async="true">
+   <node name="Ship It">
       <transition name="" to="end">
       	<action name="esbAction" class="org.jboss.soa.esb.services.jbpm.actionhandlers.EsbNotifier">
            <esbCategoryName>BPM_Orchestration4</esbCategoryName>

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/AsyncProcessSignal.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/AsyncProcessSignal.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/AsyncProcessSignal.java	2008-02-05 16:15:47 UTC (rev 18315)
@@ -0,0 +1,194 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.services.jbpm.cmd;
+
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+import org.jbpm.JbpmException;
+import org.jbpm.command.SignalCommand;
+import org.jbpm.context.exe.ContextInstance;
+import org.jbpm.graph.def.Action;
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ExecutionContext;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+import org.jbpm.instantiation.Delegation;
+import org.jbpm.job.ExecuteActionJob;
+import org.jbpm.msg.MessageService;
+import org.jbpm.svc.Services;
+
+/**
+ * Handle the asynchronous signalling of a process instance task.
+ * 
+ * @author <a href='kevin.conner at jboss.com'>Kevin Conner</a>
+ */
+class AsyncProcessSignal
+{
+    /**
+     * The logger for this class.
+     */
+    private static Logger logger = Logger.getLogger(AsyncProcessSignal.class);
+    
+    /**
+     * The name of the ESB asynchronous signal action.
+     */
+    private static final String ESB_ASYNC_SIGNAL_ACTION_NAME = "ESB_ASYNC_SIGNAL_ACTION" ;
+    /**
+     * The base name of the ESB asynchronous signal context variable.
+     */
+    private static final String ESB_ASYNC_SIGNAL_VARIABLE_NAME = "ESB_ASYNC_SIGNAL_VARIABLE_" ;
+    
+    /**
+     * Create an asynchronous signal job for the specified token and transition.
+     * @param token The token to signal.
+     * @param transitionName The transition to signal or null if the default transition is to be used.
+     */
+    static void createSignalJob(final Token token, final String transitionName)
+    {
+        final boolean isDebugEnabled = logger.isDebugEnabled() ;
+        final long tokenId = token.getId() ;
+        final ProcessInstance processInstance = token.getProcessInstance() ;
+        final long processInstanceId = processInstance.getId() ;
+        final ContextInstance contextInstance = processInstance.getContextInstance() ;
+        
+        if (isDebugEnabled)
+        {
+            logger.debug("Locking token id " + tokenId + " from process instance " + processInstanceId) ;
+        }
+        token.lock(ESB_ASYNC_SIGNAL_ACTION_NAME);
+        
+        final String transitionVariableName = ESB_ASYNC_SIGNAL_VARIABLE_NAME + tokenId ;
+        if (transitionName != null)
+        {
+            contextInstance.setVariable(transitionVariableName, transitionName) ;
+        }
+        else
+        {
+            contextInstance.deleteVariable(transitionVariableName) ;
+        }
+        final ExecuteActionJob signalJob = new ExecuteActionJob(token) ;
+        signalJob.setAction(getAsyncSignalAction(token)) ;
+        signalJob.setDueDate(new Date()) ;
+        signalJob.setSuspended(token.isSuspended()) ;
+        
+        if (isDebugEnabled)
+        {
+            logger.debug("Sending signal task to message service for token id " + tokenId + " from process instance " + processInstanceId) ;
+        }
+        final MessageService messageService = (MessageService)Services.getCurrentService(Services.SERVICENAME_MESSAGE, true) ;
+        messageService.send(signalJob) ;
+        if (isDebugEnabled)
+        {
+            logger.debug("Sent signal task to message service for token id " + tokenId + " from process instance " + processInstanceId) ;
+        }
+    }
+    
+    /**
+     * Locate the asynchronous signal action associated with the process instance.
+     * @param token The token to signal.
+     * @return The action used for asynchronous signalling.
+     * @throws JbpmException For errors creating or locating the action.
+     */
+    private static Action getAsyncSignalAction(final Token token)
+        throws JbpmException
+    {
+        final ProcessInstance processInstance = token.getProcessInstance() ;
+        final ProcessDefinition processDefinition = token.getProcessInstance().getProcessDefinition() ;
+        if (processDefinition == null)
+        {
+            throw new JbpmException("Could not locate process definition for process instance: " + processInstance.getId()) ;
+        }
+        final Action currentAction = token.getProcessInstance().getProcessDefinition().getAction(ESB_ASYNC_SIGNAL_ACTION_NAME) ;
+        if (currentAction!= null)
+        {
+            return currentAction ;
+        }
+        
+        if (logger.isDebugEnabled())
+        {
+            logger.debug("Creating Callback action for process definition: " + processDefinition.getName() + ", id: " + processDefinition.getId()) ;
+        }
+        final Delegation delegation = new Delegation(AsyncSignalAction.class.getName()) ;
+        delegation.setConfigType("constructor") ;
+        final Action newAction = new Action(delegation) ;
+        newAction.setName(ESB_ASYNC_SIGNAL_ACTION_NAME) ;
+        processDefinition.addAction(newAction) ;
+        
+        return newAction ;
+    }
+    
+    /**
+     * The task for asynchronously signalling the token.
+     * @author <a href='kevin.conner at jboss.com'>Kevin Conner</a>
+     */
+    private static class AsyncSignalAction implements ActionHandler
+    {
+        /**
+         * Serial version UID for this action.
+         */
+        private static final long serialVersionUID = -1462271955979788905L;
+        
+        /**
+         * Construct the signal job.
+         * @param configuration The configuration.
+         */
+        AsyncSignalAction(final String configuration)
+            throws JbpmException
+        {
+        }
+        
+        /**
+         * Process the background signal task.
+         * @param executionContext The current execution context.
+         */
+        public void execute(final ExecutionContext executionContext)
+            throws Exception
+        {
+            final boolean isDebugEnabled = logger.isDebugEnabled() ;
+            final Token token = executionContext.getToken() ;
+            final long tokenId = token.getId() ;
+            if (isDebugEnabled)
+            {
+                logger.debug("Unlocking token id " + tokenId + " from process instance " +
+                    token.getProcessInstance().getId()) ;
+            }
+            token.unlock(ESB_ASYNC_SIGNAL_ACTION_NAME) ;
+            if (isDebugEnabled)
+            {
+                logger.debug("Signaling task " + tokenId + " from process instance " +
+                    token.getProcessInstance().getId()) ;
+            }
+            final ProcessInstance processInstance = token.getProcessInstance() ;
+            final ContextInstance contextInstance = processInstance.getContextInstance() ;
+            final String transitionName = (String)contextInstance.getVariable(ESB_ASYNC_SIGNAL_VARIABLE_NAME + tokenId) ;
+            final SignalCommand signalCommand = new SignalCommand(tokenId, transitionName) ;
+            signalCommand.execute(executionContext.getJbpmContext()) ;
+            if (isDebugEnabled)
+            {
+                logger.debug("Signalled task " + tokenId + " from process instance " +
+                    token.getProcessInstance().getId()) ;
+            }
+        }
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/AsyncProcessSignal.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java	2008-02-05 16:15:47 UTC (rev 18315)
@@ -1,15 +1,34 @@
-/**
- * 
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.soa.esb.services.jbpm.cmd;
 
-import java.util.List;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.addressing.EPR;
 import org.jboss.soa.esb.services.jbpm.Constants;
 import org.jbpm.JbpmContext;
-import org.jbpm.command.SignalCommand;
+import org.jbpm.command.Command;
+import org.jbpm.context.exe.ContextInstance;
 import org.jbpm.graph.exe.ProcessInstance;
 import org.jbpm.graph.exe.Token;
 
@@ -17,29 +36,29 @@
  * @author kstam
  *
  */
-public class CallbackCommand extends SignalCommand {
+public class CallbackCommand implements Command {
 
-    private Logger logger = Logger.getLogger(this.getClass());
+    private static Logger logger = Logger.getLogger(CallbackCommand.class);
     /**
      * 
      */
     private static final long serialVersionUID = 1L;
+    
+    /**
+     * The named transition or null if the default is to be used.
+     */
+    private String transitionName ;
+    /**
+     * The variable map.
+     */
+    private Map variables ;
+    
     private EPR callbackEpr;
     
     public CallbackCommand() {
         super();
     }
     
-    public CallbackCommand(long tokenId, String transitionName) {
-        super(tokenId, transitionName);
-    }
-    
-    public CallbackCommand(long tokenId, String transitionName, EPR callbackEpr)
-    {
-        super(tokenId, transitionName);
-        this.callbackEpr = callbackEpr;
-    }
-    
     public EPR getCallbackEpr() {
         return callbackEpr;
     }
@@ -47,71 +66,69 @@
         this.callbackEpr = callbackEpr;
     }
     
+    public void setTransitionName(final String transitionName) {
+        this.transitionName = transitionName ;
+    }
+    
+    public void setVariables(final Map variables) {
+        this.variables = variables ;
+    }
+    
     public Object execute(JbpmContext jbpmContext) 
     {
+        final boolean isDebugEnabled = logger.isDebugEnabled() ;
         try {
-            long tokenId = checkCurrentState(jbpmContext, callbackEpr);
-            //if the state is ok, then goahead with the signalling the transition
-            this.setTokenId(tokenId);
-            return super.execute(jbpmContext);
+            long nodeId  = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.NODE_ID));
+            long tokenId = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.TOKEN_ID));
+            long processInstanceId = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.PROCESS_INSTANCE_ID));
+            String counterName = Constants.PROCESS_NODE_VERSION_COUNTER + nodeId + '_' + tokenId;
+            long processNodeVersion = Long.parseLong(callbackEpr.getAddr().getExtensionValue(counterName));
+            if (isDebugEnabled) logger.debug("Expected nodeId=" + nodeId + 
+                    ", tokenId=" + tokenId + ", processNodeVersion=" + processNodeVersion);
+            //get update on current state of things.
+            final Token token = jbpmContext.getToken(tokenId) ;
+            if (token == null) {
+                throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " is no longer active") ;
+            }
+            final ProcessInstance instance = token.getProcessInstance() ;
+            if (instance == null) {
+                throw new CallbackException("Process instance " + processInstanceId + " is no longer active") ;
+            }
+            if (instance.getId() != processInstanceId) {
+                throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " now attached to process instance " + instance.getId()) ;
+            }
+            
+            if (nodeId != token.getNode().getId()) {
+                throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " is no longer on expected node, expected " + nodeId + " but discovered " + token.getNode().getId()) ;
+            }
+            if (token.hasEnded()) {
+                throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " has already terminated") ;
+            }
+            
+            if (token.isLocked()) {
+                throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " is already locked, another thread is active") ;
+            }
+            
+            final ContextInstance contextInstance = instance.getContextInstance() ;
+            final long currentProcessNodeVersion = Long.parseLong(String.valueOf(
+                    contextInstance.getVariable(counterName)));
+            if (isDebugEnabled) logger.debug("ProcessNodeVersion=" + currentProcessNodeVersion);
+            if (processNodeVersion!=currentProcessNodeVersion) {
+                throw new CallbackException("The current processNodeVersion (id=" + currentProcessNodeVersion +
+                        ") is not the expected version (version=" + processNodeVersion + ").");
+            }
+            
+            if (variables != null && variables.size() > 0) {
+                if (isDebugEnabled) {
+                    logger.debug("Initialising variables for token id " + tokenId + " from process instance " + processInstanceId) ;
+                }
+                contextInstance.addVariables(variables);
+            }
+            
+            AsyncProcessSignal.createSignalJob(token, transitionName) ;
         } catch (CallbackException jbpmCe) {
             logger.warn(jbpmCe.getMessage());
-            return null;
         }
+        return null;
     }
-    
-    /**
-     * Checks whether the current state in jBPM is the expected state. If so it returns the tokenId
-     * on which we can invoke a signal.
-     * 
-     * @param replyTo
-     * @return
-     * @throws CallbackException
-     */
-    protected long checkCurrentState(JbpmContext jbpmContext, EPR callbackEpr)
-    throws CallbackException
-    {
-        long nodeId  = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.NODE_ID));
-        long tokenId = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.TOKEN_ID));
-        long processInstanceId = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.PROCESS_INSTANCE_ID));
-        String counterName = Constants.PROCESS_NODE_VERSION_COUNTER + nodeId + '_' + tokenId;
-        long processNodeVersion = Long.parseLong(callbackEpr.getAddr().getExtensionValue(counterName));
-        if (logger.isDebugEnabled()) logger.debug("Expected nodeId=" + nodeId + 
-                ", tokenId=" + tokenId + ", processNodeVersion=" + processNodeVersion);
-        //get update on current state of things.
-        ProcessInstance instance = jbpmContext.getProcessInstance(processInstanceId);
-        if (instance == null) {
-            throw new CallbackException("Process instance " + processInstanceId + " is no longer active") ;
-        }
-        List tokens = instance.findAllTokens();
-        boolean discovered = false ;
-        for (Object object : tokens) {
-            Token token = (Token) object;
-            if (token.getId()==tokenId) {
-                if (nodeId != token.getNode().getId()) {
-                    throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " is no longer on expected node") ;
-                }
-                if (token.hasEnded()) {
-                    throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " has already terminated") ;
-                }
-                discovered = true ;
-                break;
-            }
-        }
-        if (!discovered) {
-            throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " is no longer active") ;
-        }
-        //Compare current with expected
-        //get the current processNode Version
-        Long currentProcessNodeVersion = Long.parseLong(String.valueOf(
-                instance.getContextInstance().getVariable(counterName)));
-        if (logger.isDebugEnabled()) logger.debug("ProcessNodeVersion=" + currentProcessNodeVersion);
-        if (processNodeVersion!=currentProcessNodeVersion) {
-            throw new CallbackException("The current processNodeVersion (id=" + currentProcessNodeVersion +
-                    ") is not the expected version (version=" + processNodeVersion + ").");
-        }
-        return tokenId;
-    }
-
-    
 }

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java	2008-02-05 16:15:47 UTC (rev 18315)
@@ -34,13 +34,13 @@
 import org.jboss.soa.esb.services.jbpm.Constants;
 import org.jboss.soa.esb.services.jbpm.JBpmObjectMapper;
 import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
 import org.jbpm.JbpmException;
 import org.jbpm.command.CancelProcessInstanceCommand;
 import org.jbpm.command.CommandService;
 import org.jbpm.command.GetProcessInstanceCommand;
 import org.jbpm.command.NewProcessInstanceCommand;
 import org.jbpm.command.SignalCommand;
-import org.jbpm.command.StartProcessInstanceCommand;
 import org.jbpm.command.impl.CommandServiceImpl;
 import org.jbpm.graph.exe.ProcessInstance;
 
@@ -177,13 +177,10 @@
 		private void perform(Message request, boolean start)
 		{
             ObjectMapper objectMapper = new ObjectMapper();
-            NewProcessInstanceCommand command = null;
+            final NewProcessInstanceCommand command ;
             if (start) {
-                StartProcessInstanceCommand startCmd = new StartProcessInstanceCommand();
-                String transition = MessageHelper.getStringValue(request, Constants.TRANSITION_NAME);
-                if (null!=transition)
-                    startCmd.setStartTransitionName(transition);
-                command = startCmd;
+                final String transition = MessageHelper.getStringValue(request, Constants.TRANSITION_NAME);
+                command = new AsyncStartProcessInstanceCommand(transition);
             } else {
                 command = new NewProcessInstanceCommand(); 
             }
@@ -241,6 +238,48 @@
         return jbpmService;
     }
     
-    
-
+    /**
+     * Command responsible for creating a process instance and firing an asynchronous signal to the root node.
+     * 
+     * @author <a href='kevin.conner at jboss.com'>Kevin Conner</a>
+     */
+    private static class AsyncStartProcessInstanceCommand extends NewProcessInstanceCommand
+    {
+        /**
+         * The serial version UID for this class.
+         */
+        private static final long serialVersionUID = 7917063133912138584L;
+        
+        /**
+         * The name of the transition to signal.
+         */
+        private final String transitionName ;
+        
+        /**
+         * Create the asynchronous process instance command with the specified transition.
+         * @param transitionName The transition to signal or null if the default transition should be used.
+         */
+        AsyncStartProcessInstanceCommand(final String transitionName)
+        {
+            this.transitionName = transitionName ;
+        }
+        
+        /**
+         * Execute the command.
+         * @param jbpmContext The current jBPM context.
+         * @throws Exception for any errors.
+         */
+        @Override
+        public Object execute(final JbpmContext jbpmContext)
+            throws Exception
+        {
+            final Object result = super.execute(jbpmContext) ;
+            if (result instanceof ProcessInstance)
+            {
+                final ProcessInstance processInstance = (ProcessInstance)result ;
+                AsyncProcessSignal.createSignalJob(processInstance.getRootToken(), transitionName) ;
+            }
+            return result ;
+        }
+    }
 }

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/resources/META-INF/jboss-esb.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/resources/META-INF/jboss-esb.xml	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/resources/META-INF/jboss-esb.xml	2008-02-05 16:15:47 UTC (rev 18315)
@@ -5,14 +5,14 @@
      -->
      <providers>
      	  <!-- change the following element to jms-jca-provider to enable transactional context  -->
-          <jms-provider name="CallbackQueue-JMS-Provider" connection-factory="ConnectionFactory">          
+          <jms-jca-provider name="CallbackQueue-JMS-Provider" connection-factory="ConnectionFactory">          
               <jms-bus busid="jBPMCallbackBus">
                   <jms-message-filter
                       dest-type="QUEUE"
                       dest-name="queue/CallbackQueue"
                   />
               </jms-bus>
-          </jms-provider>
+          </jms-jca-provider>
       </providers>
       
 	<services>   

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/AsyncTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/AsyncTest.java	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/AsyncTest.java	2008-02-05 16:15:47 UTC (rev 18315)
@@ -1,167 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.soa.esb.services.jbpm.actionhandlers;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import junit.framework.JUnit4TestAdapter;
-
-import org.apache.log4j.Logger;
-import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmContext;
-import org.jbpm.graph.def.Node;
-import org.jbpm.graph.def.ProcessDefinition;
-import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.graph.exe.Token;
-import org.junit.Before;
-import org.junit.Test;
-/**
- * Tests the capabilities of jBPM async, which we are using.
- * 
- * @author kstam
- *
- */
-public class AsyncTest 
-{
-    private static String PROCESS_DEF_XML_ASYNC = "testAsync.xml";
-    private static String PROCESS_DEF_XML_SYNC = "testSync.xml";
-	private static Logger logger = Logger.getLogger(AsyncTest.class);
-
-     /**
-     * If the node *after* myNode is set to async="true", then the signal
-     * command will return immediately, and run in a different transaction.
-     * 
-     * @throws Exception
-     */
-    @Test
-    public void sync() throws Exception
-    { 
-        logger.info("Setting up jBPM");
-        JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
-        
-        jbpmConfiguration.getJobExecutor().start();
-        JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-        //Extract a process definition from the processdefinition.xml file.
-        ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource(PROCESS_DEF_XML_SYNC);
-        assertNotNull(processDefinition);
-        //Create an instance of the process definition.
-        jbpmContext.deployProcessDefinition(processDefinition);
-        ProcessInstance processInstance = jbpmContext.newProcessInstance("testSync");
-        long processInstanceId = processInstance.getId();
-        assertTrue(
-                "Instance is in start state", 
-                "start".equals(processInstance.getRootToken().getNode().getName()));
-        jbpmContext.close(); 
-        
-        jbpmConfiguration = JbpmConfiguration.getInstance();
-        jbpmContext = jbpmConfiguration.createJbpmContext();
-        processInstance = jbpmContext.loadProcessInstance(processInstanceId);
-        
-        Token token = processInstance.getRootToken(); 
-        processInstance.signal();
-        assertEquals("mynode",token.getNode().getName());
-        jbpmContext.close();
-        
-        long startTime = System.currentTimeMillis();  
-//      Send mynode a signal such that it goes to wait2seconds
-        jbpmContext = jbpmConfiguration.createJbpmContext();
-        processInstance = jbpmContext.loadProcessInstance(processInstanceId);
-        processInstance.signal();
-        jbpmContext.save(processInstance);
-        jbpmContext.close();
-        
-        jbpmContext = jbpmConfiguration.createJbpmContext();
-        processInstance = jbpmContext.loadProcessInstance(processInstanceId);
-        token = processInstance.getRootToken();
-//      Check that we are now in the end node.
-        String currentNode = token.getNode().getName();
-        long endTime = System.currentTimeMillis();
-        assertEquals("end",currentNode);
-        jbpmContext.close();
-        long elapsedMillies = endTime - startTime;
-        System.out.println("async elapsedMillies=" + elapsedMillies);
-        assertTrue(elapsedMillies > 2000);
-    }
-    
-    /**
-     * If the node *after* myNode is set to async="true", then the signal
-     * command will return immediately, and run in a different transaction.
-     * 
-     * @throws Exception
-     */
-    @Test
-    public void async() throws Exception
-    { 
-        logger.info("Setting up jBPM");
-        JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
-        
-        jbpmConfiguration.getJobExecutor().start();
-        JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-        //Extract a process definition from the processdefinition.xml file.
-        ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource(PROCESS_DEF_XML_ASYNC);
-        assertNotNull(processDefinition);
-        //Create an instance of the process definition.
-        jbpmContext.deployProcessDefinition(processDefinition);
-        ProcessInstance processInstance = jbpmContext.newProcessInstance("testAsync");
-        long processInstanceId = processInstance.getId();
-        assertTrue(
-                "Instance is in start state", 
-                "start".equals(processInstance.getRootToken().getNode().getName()));
-        jbpmContext.close(); 
-        
-        jbpmConfiguration = JbpmConfiguration.getInstance();
-        jbpmContext = jbpmConfiguration.createJbpmContext();
-        processInstance = jbpmContext.loadProcessInstance(processInstanceId);
-        
-        Token token = processInstance.getRootToken(); 
-        processInstance.signal();
-        assertEquals("mynode",token.getNode().getName());
-        jbpmContext.close();
-        
-        long startTime = System.currentTimeMillis();  
-//      Send mynode a signal such that it goes to wait2seconds
-        jbpmContext = jbpmConfiguration.createJbpmContext();
-        processInstance = jbpmContext.loadProcessInstance(processInstanceId);
-        processInstance.signal();
-        jbpmContext.save(processInstance);
-        jbpmContext.close();
-        
-        jbpmContext = jbpmConfiguration.createJbpmContext();
-        processInstance = jbpmContext.loadProcessInstance(processInstanceId);
-        token = processInstance.getRootToken();
-//      Check that we are now in the end node.
-        String currentNode = token.getNode().getName();
-        long endTime = System.currentTimeMillis();
-        assertEquals("wait2seconds",currentNode);
-        jbpmContext.close();
-        long elapsedMillies = endTime - startTime;
-        System.out.println("async elapsedMillies=" + elapsedMillies);
-        assertTrue(elapsedMillies < 2000);
-    }
-    
-    public static junit.framework.Test suite(){
-        return new JUnit4TestAdapter(AsyncTest.class);
-    }
-
-}

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/Wait2SecondsAction.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/Wait2SecondsAction.java	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/Wait2SecondsAction.java	2008-02-05 16:15:47 UTC (rev 18315)
@@ -1,31 +0,0 @@
-/**
- * 
- */
-package org.jboss.soa.esb.services.jbpm.actionhandlers;
-
-import org.jbpm.graph.def.ActionHandler;
-import org.jbpm.graph.exe.ExecutionContext;
-
-/**
- * @author kstam
- *
- */
-
-public class Wait2SecondsAction implements ActionHandler{
-    
-    private static final long serialVersionUID = 1L;
-
-    public void execute (ExecutionContext executionContext) throws Exception
-    {
-        for (int i=0; i<2; i++){
-            try {
-                Thread.sleep(1000);
-                System.out.println("Waited " + (i+1) + " seconds");
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            }
-        }
-        System.out.println("Done Waiting");
-    }
-
-}

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/.gpd.testAsync.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/.gpd.testAsync.xml	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/.gpd.testAsync.xml	2008-02-05 16:15:47 UTC (rev 18315)
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<process-diagram name="testAsync" width="647" height="644">
-  <node name="start" x="78" y="32" width="140" height="40">
-    <transition name="toExtraNode">
-      <label x="5" y="-10"/>
-    </transition>
-  </node>
-  <node name="extranode" x="0" y="0" width="140" height="40">
-    <transition name="toMyNode">
-      <label x="5" y="-10"/>
-    </transition>
-  </node>
-  <node name="mynode" x="80" y="191" width="140" height="40">
-    <transition name="toWait2Seconds">
-      <label x="5" y="-10"/>
-    </transition>
-  </node>
-  <node name="wait2seconds" x="74" y="275" width="140" height="40">
-    <transition name="toEnd">
-      <label x="5" y="-10"/>
-    </transition>
-  </node>
-  <node name="end" x="79" y="402" width="140" height="40"/>
-</process-diagram>

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/.gpd.testSync.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/.gpd.testSync.xml	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/.gpd.testSync.xml	2008-02-05 16:15:47 UTC (rev 18315)
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<process-diagram name="testSync" width="645" height="584">
-  <node name="start" x="0" y="0" width="140" height="40">
-    <transition name="toExtraNode">
-      <label x="5" y="-10"/>
-    </transition>
-  </node>
-  <node name="extranode" x="0" y="0" width="140" height="40">
-    <transition name="toMyNode">
-      <label x="5" y="-10"/>
-    </transition>
-  </node>
-  <node name="mynode" x="0" y="0" width="140" height="40">
-    <transition name="toWait2Seconds">
-      <label x="5" y="-10"/>
-    </transition>
-  </node>
-  <node name="wait2seconds" x="0" y="0" width="140" height="40">
-    <transition name="toEnd">
-      <label x="5" y="-10"/>
-    </transition>
-  </node>
-  <node name="end" x="0" y="0" width="140" height="40"/>
-</process-diagram>

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testAsync.jpg
===================================================================
(Binary files differ)

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testAsync.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testAsync.xml	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testAsync.xml	2008-02-05 16:15:47 UTC (rev 18315)
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<process-definition 
-  xmlns="urn:jbpm.org:jpdl-3.2"
-  name="testAsync">
-   <start-state name="start">
-      <transition name="toExtraNode" to="extranode"></transition>
-   </start-state>
-   <node name="extranode">
-       <transition name="toMyNode" to="mynode"></transition>
-   </node>
-   <node name="mynode" >
-       <action name="dummy" class="org.jboss.soa.esb.services.jbpm.actionhandlers.DummyAction"/>
-       <transition name="toWait2Seconds" to="wait2seconds" />
-   </node>
-   <node name="wait2seconds" async="true">
-       <transition name="toEnd" to="end">
-       	<action name="wait2seconds" class="org.jboss.soa.esb.services.jbpm.actionhandlers.Wait2SecondsAction"/>
-       </transition>
-   </node>
-   <end-state name="end"></end-state>
-</process-definition>
\ No newline at end of file

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testSync.jpg
===================================================================
(Binary files differ)

Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testSync.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testSync.xml	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/resources/testSync.xml	2008-02-05 16:15:47 UTC (rev 18315)
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<process-definition 
-  xmlns="urn:jbpm.org:jpdl-3.2"
-  name="testSync">
-   <start-state name="start">
-      <transition name="toExtraNode" to="extranode"></transition>
-   </start-state>
-   <node name="extranode">
-       <transition name="toMyNode" to="mynode"></transition>
-   </node>
-   <node name="mynode" >
-       <action name="dummy" class="org.jboss.soa.esb.services.jbpm.actionhandlers.DummyAction"/>
-       <transition name="toWait2Seconds" to="wait2seconds" />
-   </node>
-   <node name="wait2seconds">
-       <transition name="toEnd" to="end">
-       	<action name="wait2seconds" class="org.jboss.soa.esb.services.jbpm.actionhandlers.Wait2SecondsAction"/>
-       </transition>
-   </node>
-   <end-state name="end"></end-state>
-</process-definition>
\ No newline at end of file

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/build.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/build.xml	2008-02-05 15:12:33 UTC (rev 18314)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/build.xml	2008-02-05 16:15:47 UTC (rev 18315)
@@ -27,6 +27,7 @@
                excludes="*.jar" includes="jaxr-api*.jar,scout*.jar,juddi*.jar"/>
       <fileset dir="${qa.lib}/ext" includes="*.jar"/>
       <fileset dir="${product.lib}/ext" includes="*.jar"/>
+      <fileset dir="${product.lib}/jbpm.esb" includes="*.jar"/>
       <pathelement location="../"/>
    </path>
 
@@ -136,6 +137,17 @@
             <include name="META-INF/*.xml"/>
          </fileset>
       </jar>
+      <jar jarfile="${qa.build.lib}/jbpm-async-test.esb">
+         <fileset dir="${qa.junit.classes}">
+            <include name="org/jboss/soa/esb/server/jbpmAsync/*.class"/>
+         </fileset>
+         <fileset dir="${qa.junit.resources}/server/jbpmAsync">
+            <include name="esb-${org.jboss.soa.esb.qa.jmsprovider}-service.xml"/>
+            <include name="test-jbpm-service.xml"/>
+            <include name="jbpmAsyncTest.xml"/>
+            <include name="META-INF/*.xml"/>
+         </fileset>
+      </jar>
    </target>
 
    <target name="one-test" if="test" depends="jars"

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/EchoSuspendAction.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/EchoSuspendAction.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/EchoSuspendAction.java	2008-02-05 16:15:47 UTC (rev 18315)
@@ -0,0 +1,71 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.server.jbpmAsync;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+import org.jboss.soa.esb.actions.ActionPipelineProcessor;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Action class to attempt a suspend of a running jBPM process.
+ * 
+ * @author <a href='mailto:Kevin.Conner at jboss.com'>Kevin Conner</a>
+ */
+public class EchoSuspendAction extends AbstractActionLifecycle implements ActionPipelineProcessor
+{
+    public EchoSuspendAction(final ConfigTree config)
+    {
+    }
+
+    public Message process(final Message message)
+        throws ActionProcessingException
+    {
+        final MBeanServer server = MBeanServerLocator.locateJBoss();
+        
+        final JbpmServerMBean jbpmServer ;
+        try
+        {
+            jbpmServer = (JbpmServerMBean) MBeanProxyExt.create(JbpmServerMBean.class, JbpmServerMBean.OBJECT_NAME, server);
+        }
+        catch (final MalformedObjectNameException mone)
+        {
+            throw new ActionProcessingException("Error creating MBean proxy", mone) ;
+        }
+        jbpmServer.suspendProcessInstance() ;
+        return message;
+    }
+    
+    public void processException(final Message message, final Throwable th)
+    {
+    }
+    
+    public void processSuccess(final Message message)
+    {
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/EchoSuspendAction.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmAsyncActionHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmAsyncActionHandler.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmAsyncActionHandler.java	2008-02-05 16:15:47 UTC (rev 18315)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.server.jbpmAsync;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.exe.ExecutionContext;
+
+/**
+ * Action Handler for jBPM Async test.
+ */
+public class JbpmAsyncActionHandler implements ActionHandler
+{
+    /**
+     * Serial version UID for this class.
+     */
+    private static final long serialVersionUID = 6205275164157280372L;
+
+    /**
+     * The notification lock.
+     */
+    private static final Lock NOTIFICATION_LOCK = new ReentrantLock() ;
+    
+    /**
+     * The notification condition.
+     */
+    private static Condition NOTIFICATION_CONDITION = NOTIFICATION_LOCK.newCondition() ;
+    
+    /**
+     * The waiting flag.
+     */
+    private static boolean waiting ;
+    /**
+     * The notified flag.
+     */
+    private static boolean notified ;
+    
+    /**
+     * Wait for a notification from the test.
+     */
+    public void execute(final ExecutionContext executionContext)
+        throws Exception
+    {
+        if (!waitForNotification(60000L))
+        {
+            throw new Exception("Notification failed") ;
+        }
+    }
+    
+    /**
+     * Notify the action.
+     * @param delay The maximum delay waiting for the action.
+     * @return true if waiting, false otherwise.
+     */
+    public static boolean notifyAction(final long delay)
+    {
+        NOTIFICATION_LOCK.lock() ;
+        try
+        {
+            if (!waiting)
+            {
+                try
+                {
+                    NOTIFICATION_CONDITION.await(delay, TimeUnit.MILLISECONDS) ;
+                }
+                catch (final InterruptedException ie) {}
+            }
+            
+            if (waiting)
+            {
+                notified = true ;
+                NOTIFICATION_CONDITION.signal() ;
+            }
+            return waiting ;
+        }
+        finally
+        {
+            NOTIFICATION_LOCK.unlock() ;
+        }
+    }
+    
+    /**
+     * Wait for a notification from the test.
+     * @param delay The maximum delay waiting for notification.
+     * @return true if notified, false otherwise.
+     */
+    private static boolean waitForNotification(final long delay)
+    {
+        NOTIFICATION_LOCK.lock() ;
+        waiting = true ;
+        try
+        {
+            NOTIFICATION_CONDITION.signal() ;
+            try
+            {
+                NOTIFICATION_CONDITION.await(delay, TimeUnit.MILLISECONDS) ;
+            }
+            catch (final InterruptedException ie) {}
+            return notified ;
+        }
+        finally
+        {
+            waiting = false ;
+            notified = false ;
+            NOTIFICATION_LOCK.unlock() ;
+        }
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmAsyncActionHandler.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmAsyncUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmAsyncUnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmAsyncUnitTest.java	2008-02-05 16:15:47 UTC (rev 18315)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.server.jbpmAsync;
+
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Test asynchronous callbacks for jBPM processes.
+ * 
+ * @author <a href='mailto:kevin.conner at jboss.com'>Kevin Conner</a>
+ */
+public class JbpmAsyncUnitTest extends JBossTestCase
+{
+    /**
+     * The name of the deployment archive.
+     */
+    private static final String ESB_ARCHIVE = "jbpm-async-test.esb" ;
+    
+    /**
+     * Construct the test case with the specified name.
+     * @param name The name of the test case.
+     */
+    public JbpmAsyncUnitTest(final String name)
+    {
+        super(name) ;
+    }
+    
+    /**
+     * Test for normal asynchronous callback.
+     * @throws Exception For any failures.
+     */
+    public void testAsyncCallback()
+        throws Exception
+    {
+        execute("setSuspendProcess", new Object[] {Boolean.FALSE}, new String[] {Boolean.TYPE.getName()}) ;
+        execute("startProcess", null, null) ;
+        
+        final Boolean result = (Boolean)execute("checkWaitingAction", new Object[] {new Long(10000L)}, new String[] {Long.TYPE.getName()}) ;
+        assertEquals("checkWaitingAction", Boolean.TRUE, result) ;
+    }
+    /**
+     * Test for asynchronous callback on a suspended process.
+     * @throws Exception For any failures.
+     */
+    public void testSuspendedAsyncCallback()
+        throws Exception
+    {
+        execute("setSuspendProcess", new Object[] {Boolean.TRUE}, new String[] {Boolean.TYPE.getName()}) ;
+        execute("startProcess", null, null) ;
+        
+        final Boolean suspendedResult = (Boolean)execute("checkWaitingAction", new Object[] {new Long(10000L)}, new String[] {Long.TYPE.getName()}) ;
+        assertEquals("checkWaitingAction", Boolean.FALSE, suspendedResult) ;
+        
+        execute("resumeProcessInstance", null, null) ;
+        
+        final Boolean resumedResult = (Boolean)execute("checkWaitingAction", new Object[] {new Long(30000L)}, new String[] {Long.TYPE.getName()}) ;
+        assertEquals("checkWaitingAction", Boolean.TRUE, resumedResult) ;
+    }
+    
+    /**
+     * Execute the specified method on the mbean.
+     * @param method The method name.
+     * @param values The parmeter values.
+     * @param types The parameter types.
+     * @return The method return value.
+     * @throws Exception For errors during invocation.
+     */
+    private Object execute(final String method, final Object[] values, final String[] types)
+        throws Exception
+    {
+        return getServer().invoke(new ObjectName(JbpmServerMBean.OBJECT_NAME), method, values, types) ;
+    }
+    
+    /**
+     * Create the test suite.
+     * @return The suite representing this test case.
+     */
+    public static Test suite()
+        throws Exception
+    {
+        return getDeploySetup(JbpmAsyncUnitTest.class, ESB_ARCHIVE);
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmAsyncUnitTest.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmServer.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmServer.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmServer.java	2008-02-05 16:15:47 UTC (rev 18315)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.server.jbpmAsync;
+
+import java.io.InputStream;
+
+import org.jboss.soa.esb.util.ClassUtil;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+
+/**
+ * MBean to manage jBPM Asynchronous callback tests.
+ * 
+ * @author <a href='mailto:kevin.conner at jboss.com'>Kevin Conner</a>
+ */
+public class JbpmServer implements JbpmServerMBean
+{
+    private static final String PROCESS_DEFINITION = "/jbpmAsyncTest.xml" ;
+    
+    private boolean suspendProcess ;
+    
+    private long processInstanceId ;
+    
+    public synchronized void startProcess()
+    {
+        final JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance() ;
+        final JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext() ;
+        
+        // Create process definition
+        final InputStream is = ClassUtil.getResourceAsStream(PROCESS_DEFINITION, getClass()) ;
+        final ProcessDefinition processDefinition = ProcessDefinition.parseXmlInputStream(is) ;
+        jbpmContext.deployProcessDefinition(processDefinition) ;
+        
+        // Create process instance
+        final ProcessInstance processInstance = jbpmContext.newProcessInstance(processDefinition.getName()) ;
+        processInstanceId = processInstance.getId() ;
+        
+        // Start process instance
+        processInstance.signal() ;
+        
+        jbpmContext.close() ;
+    }
+    
+    public synchronized void suspendProcessInstance()
+    {
+        if (suspendProcess)
+        {
+            final JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance() ;
+            final JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext() ;
+            
+            final ProcessInstance processInstance = jbpmContext.loadProcessInstance(processInstanceId) ;
+            processInstance.suspend() ;
+            
+            jbpmContext.close() ;
+        }
+    }
+    
+    public synchronized void resumeProcessInstance()
+    {
+        if (suspendProcess)
+        {
+            final JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance() ;
+            final JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext() ;
+            
+            final ProcessInstance processInstance = jbpmContext.loadProcessInstance(processInstanceId) ;
+            processInstance.resume() ;
+            
+            jbpmContext.close() ;
+        }
+    }
+    
+    public synchronized void setSuspendProcess(final boolean suspendProcess)
+    {
+        this.suspendProcess = suspendProcess ;
+    }
+    
+    public boolean checkWaitingAction(final long delay)
+    {
+        return JbpmAsyncActionHandler.notifyAction(delay) ;
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmServer.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmServerMBean.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmServerMBean.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmServerMBean.java	2008-02-05 16:15:47 UTC (rev 18315)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.server.jbpmAsync;
+
+/**
+ * MBean to manage jBPM Asynchronous callback tests.
+ * 
+ * @author <a href='mailto:kevin.conner at jboss.com'>Kevin Conner</a>
+ */
+public interface JbpmServerMBean
+{
+    public static final String OBJECT_NAME="jboss.esb:test=JbpmServer" ;
+    
+    public void startProcess() ;
+    
+    public void suspendProcessInstance() ;
+    
+    public void resumeProcessInstance() ;
+    
+    public void setSuspendProcess(final boolean suspend) ;
+    
+    public boolean checkWaitingAction(final long delay) ;
+}


Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/qa/junit/src/org/jboss/soa/esb/server/jbpmAsync/JbpmServerMBean.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list