[jbpm-commits] JBoss JBPM SVN: r4917 - in jbpm4/branches/tbaeyens/modules: pvm/src/main/java/org/jbpm/pvm/internal/model/op and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed May 27 12:43:05 EDT 2009


Author: tom.baeyens at jboss.com
Date: 2009-05-27 12:43:05 -0400 (Wed, 27 May 2009)
New Revision: 4917

Modified:
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/AtomicOperation.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteActivity.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteActivityMessage.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteEventListener.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteEventListenerMessage.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/MoveToChildActivity.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/MoveToParentActivity.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/Signal.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivity.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionStartActivity.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionStartActivityMessage.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionTake.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
   jbpm4/branches/tbaeyens/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventTest.java
Log:
execution refactoring

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -33,6 +33,7 @@
 import org.jbpm.api.listener.EventListener;
 import org.jbpm.api.model.OpenProcessDefinition;
 import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.model.op.AtomicOperation;
 import org.jbpm.pvm.internal.model.op.MoveToChildActivity;
 import org.jbpm.pvm.internal.wire.Descriptor;
 
@@ -196,7 +197,7 @@
         if (transition!=null) {
           log.trace(toString()+" takes transition "+transitionName);
           execution.setTransition(transition);
-          execution.performAtomicOperationSync(ExecutionImpl.TRANSITION_END_ACTIVITY);
+          execution.performAtomicOperationSync(AtomicOperation.TRANSITION_END_ACTIVITY);
         } else {
           log.info("WARNING: "+toString()+" couldn't find transition "+transitionName+" on "+activity);
         }

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -65,14 +65,8 @@
 import org.jbpm.pvm.internal.history.events.ProcessInstanceStart;
 import org.jbpm.pvm.internal.job.MessageImpl;
 import org.jbpm.pvm.internal.model.op.AtomicOperation;
-import org.jbpm.pvm.internal.model.op.ExecuteActivity;
-import org.jbpm.pvm.internal.model.op.ExecuteEventListener;
 import org.jbpm.pvm.internal.model.op.MoveToChildActivity;
-import org.jbpm.pvm.internal.model.op.MoveToParentActivity;
 import org.jbpm.pvm.internal.model.op.Signal;
-import org.jbpm.pvm.internal.model.op.TransitionEndActivity;
-import org.jbpm.pvm.internal.model.op.TransitionStartActivity;
-import org.jbpm.pvm.internal.model.op.TransitionTake;
 import org.jbpm.pvm.internal.util.EqualsUtil;
 import org.jbpm.pvm.internal.util.Priority;
 
@@ -89,18 +83,6 @@
 
   private static final Log log = Log.getLog(Execution.class.getName());
   
-  // atomic operations 
-  public static final AtomicOperation EXECUTE_ACTIVITY = new ExecuteActivity();
-  public static final AtomicOperation PROPAGATE_TO_PARENT = new MoveToParentActivity();
-
-  public static final AtomicOperation TRANSITION_TAKE = new TransitionTake();
-  public static final AtomicOperation TRANSITION_START_ACTIVITY = new TransitionStartActivity();
-  
-  public static final AtomicOperation EXECUTE_EVENT_LISTENER = new ExecuteEventListener();
-  public static final AtomicOperation TRANSITION_END_ACTIVITY = new TransitionEndActivity();
-
-  // persistent member fields /////////////////////////////////////////////////
-  
   /** an optional name for this execution.  can be used to 
    * differentiate concurrent paths of execution like e.g. 
    * the 'shipping' and 'billing' paths. */
@@ -209,7 +191,7 @@
     fireHistoryEvent(new ProcessInstanceStart());
     fire(Event.START, getProcessDefinition());
     if (getActivity()!=null) {
-      scopedExecution.performAtomicOperation(EXECUTE_ACTIVITY);
+      scopedExecution.performAtomicOperation(AtomicOperation.EXECUTE_ACTIVITY);
     }
   }
 
@@ -399,7 +381,7 @@
     if (getActivity()!=null) {
       performAtomicOperation(new Signal(signal, parameters, getActivity()));
     } else if (transition!=null) {
-      performAtomicOperation(ExecutionImpl.TRANSITION_START_ACTIVITY);
+      performAtomicOperation(AtomicOperation.TRANSITION_START_ACTIVITY);
     } else {
       throw new JbpmException("execution is not in a activity or in a transition");
     }
@@ -452,9 +434,7 @@
 
     setTransition((TransitionImpl) transition);
     
-    ObservableElementImpl observableElement = getActivity();
-    
-    fire(Event.END, observableElement, TRANSITION_END_ACTIVITY);
+    fire(Event.END, getActivity(), AtomicOperation.TRANSITION_END_ACTIVITY);
   }
 
   public void take(Transition transition, Execution execution) {
@@ -512,7 +492,7 @@
       // if there is a parent activity
       if (parentActivity!=null) {
         // propagate to the parent
-        performAtomicOperation(PROPAGATE_TO_PARENT);
+        performAtomicOperation(AtomicOperation.PROPAGATE_TO_PARENT);
         
       }  else {
         // When we don't know how to proceed, i don't know if it's best to 
@@ -545,7 +525,7 @@
       setEventSource(observableElement);
       setEventListenerIndex(0);
       setEventCompletedOperation(eventCompletedOperation);
-      performAtomicOperation(EXECUTE_EVENT_LISTENER);
+      performAtomicOperation(AtomicOperation.EXECUTE_EVENT_LISTENER);
     } else {
       if (eventCompletedOperation!=null) {
         performAtomicOperationSync(eventCompletedOperation);
@@ -559,10 +539,7 @@
     }
     
     EventImpl event = observableElement.getEvent(eventName);
-    if ( (event!=null)
-         && (event.getListenerReferences()!=null)
-         && (!event.getListenerReferences().isEmpty())
-       ) {
+    if (event!=null) {
       return event;
     }
     
@@ -595,6 +572,8 @@
     return propagatingExecution;
   }
 
+  // asynchronous continuations ////////////////////////////////////////////////  
+
   public synchronized void performAtomicOperation(AtomicOperation operation) {
     if (operation.isAsync(this)) {
       sendContinuationMessage(operation);
@@ -603,8 +582,6 @@
     }
   }
   
-  // asynchronous continuations ////////////////////////////////////////////////  
-
   public void sendContinuationMessage(AtomicOperation operation) {
     Environment environment = Environment.getCurrent();
     MessageSession messageSession = environment.get(MessageSession.class);
@@ -1079,7 +1056,7 @@
   public EventImpl getEvent() {
     return event;
   }
-  public ObservableElement getEventSource() {
+  public ObservableElementImpl getEventSource() {
     return eventSource;
   }
   public Collection<Execution> getExecutions() {

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/AtomicOperation.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/AtomicOperation.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/AtomicOperation.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -21,16 +21,38 @@
  */
 package org.jbpm.pvm.internal.model.op;
 
+import org.jbpm.api.JbpmException;
 import org.jbpm.pvm.internal.job.MessageImpl;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 
 /**
  * @author Tom Baeyens
  */
-public interface AtomicOperation {
+public abstract class AtomicOperation {
+
+  public static final AtomicOperation EXECUTE_ACTIVITY = new ExecuteActivity();
+  public static final AtomicOperation PROPAGATE_TO_PARENT = new MoveToParentActivity();
+  public static final AtomicOperation TRANSITION_TAKE = new TransitionTake();
+  public static final AtomicOperation TRANSITION_START_ACTIVITY = new TransitionStartActivity();
+  public static final AtomicOperation EXECUTE_EVENT_LISTENER = new ExecuteEventListener();
+  public static final AtomicOperation TRANSITION_END_ACTIVITY = new TransitionEndActivity();
+
+  public abstract boolean isAsync(ExecutionImpl execution);
+  public abstract MessageImpl<?> createAsyncMessage(ExecutionImpl execution);
+  public abstract void perform(ExecutionImpl execution);
   
-  boolean isAsync(ExecutionImpl execution);
-  MessageImpl<?> createAsyncMessage(ExecutionImpl execution);
+  public static AtomicOperation parseAtomicOperation(String text) {
+    if (text==null) {
+      return null;
+    }
 
-  void perform(ExecutionImpl execution);
+    if (TRANSITION_END_ACTIVITY.toString().equals(text)) return TRANSITION_END_ACTIVITY; 
+    if (EXECUTE_EVENT_LISTENER.toString().equals(text)) return EXECUTE_EVENT_LISTENER; 
+    if (EXECUTE_ACTIVITY.toString().equals(text)) return EXECUTE_ACTIVITY; 
+    if (TRANSITION_TAKE.toString().equals(text)) return TRANSITION_TAKE; 
+    if (TRANSITION_START_ACTIVITY.toString().equals(text)) return TRANSITION_START_ACTIVITY; 
+    if (PROPAGATE_TO_PARENT.toString().equals(text)) return PROPAGATE_TO_PARENT;
+
+    throw new JbpmException("invalid atomic operation text: "+text);
+  }
 }

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteActivity.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteActivity.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteActivity.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -30,7 +30,7 @@
 import org.jbpm.pvm.internal.model.ExecutionImpl.Propagation;
 import org.jbpm.pvm.internal.util.Clock;
 
-public class ExecuteActivity implements AtomicOperation {
+public class ExecuteActivity extends AtomicOperation {
   
   private static Log log = Log.getLog(ExecuteActivity.class.getName());
   

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteActivityMessage.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteActivityMessage.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteActivityMessage.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -43,7 +43,7 @@
   public Object execute(Environment environment) throws Exception {
     AsyncContinuations.restoreState(execution);
     
-    execution.performAtomicOperationSync(ExecutionImpl.EXECUTE_ACTIVITY);
+    execution.performAtomicOperationSync(AtomicOperation.EXECUTE_ACTIVITY);
 
     JobDbSession jobDbSession = environment.get(JobDbSession.class);
     jobDbSession.delete(this);

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteEventListener.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteEventListener.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteEventListener.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -36,62 +36,77 @@
 /**
  * @author Tom Baeyens
  */
-public class ExecuteEventListener implements AtomicOperation {
+public class ExecuteEventListener extends AtomicOperation {
   
   private static Log log = Log.getLog(ExecuteEventListener.class.getName());
   
   public boolean isAsync(ExecutionImpl execution) {
     int eventListenerIndex = execution.getEventListenerIndex();
     EventImpl event = execution.getEvent();
+    
+    if ( (eventListenerIndex==0)
+         && (event.isAsync())
+       ) {
+      return true;
+    }
+    
     List<EventListenerReference> eventListenerReferences = event.getListenerReferences();
+    if ( (eventListenerReferences==null)
+         || (eventListenerReferences.isEmpty())
+       ) {
+      return false;
+    }
+
     EventListenerReference eventListenerReference = eventListenerReferences.get(eventListenerIndex);
     return eventListenerReference.isAsync();
   }
 
   public void perform(ExecutionImpl execution) {
     EventImpl event = execution.getEvent();
+    ObservableElementImpl observableElement = event.getObservableElement();
     int eventListenerIndex = execution.getEventListenerIndex();
     List<EventListenerReference> eventListenerReferences = event.getListenerReferences();
-    EventListenerReference eventListenerReference = eventListenerReferences.get(eventListenerIndex);
-    ObservableElement eventSource = execution.getEventSource();
-    ObservableElementImpl observableElement = event.getObservableElement();
-
-    if ( (eventSource==observableElement)
-         || (eventListenerReference.isPropagationEnabled())
+    if ( (eventListenerReferences!=null)
+         && (!eventListenerReferences.isEmpty())
        ) {
-      EventListener eventListener = eventListenerReference.get();
-      log.trace("executing "+eventListener+" for "+event);
-      try {
-        // TODO can/should this invocation be unified with the exception handler invocation of the event notification method?
-        eventListener.notify(execution);
-      } catch (Exception e) {
-        log.trace("exception during action: "+e);
-        execution.handleException((ObservableElementImpl) observableElement, event, eventListenerReference, e, "couldn't run action "+eventListener);
+      EventListenerReference eventListenerReference = eventListenerReferences.get(eventListenerIndex);
+      ObservableElement eventSource = execution.getEventSource();
+      if ((eventSource == observableElement) || (eventListenerReference.isPropagationEnabled())) {
+        EventListener eventListener = eventListenerReference.get();
+        log.trace("executing " + eventListener + " for " + event);
+        try {
+          // TODO can/should this invocation be unified with the exception handler invocation of the event notification method?
+          eventListener.notify(execution);
+        } catch (Exception e) {
+          log.trace("exception during action: " + e);
+          execution.handleException((ObservableElementImpl) observableElement, event, eventListenerReference, e, "couldn't run action " + eventListener);
+        }
       }
+      // increment the event listener index
+      eventListenerIndex++;
+      execution.setEventListenerIndex(eventListenerIndex);
     }
     
-    // increment the event listener index
-    eventListenerIndex++;
-    execution.setEventListenerIndex(eventListenerIndex);
-    
     // if there are more listeners in this event
-    if (eventListenerIndex<eventListenerReferences.size()) {
+    if ( (eventListenerReferences!=null)
+         && (eventListenerIndex < eventListenerReferences.size())
+       ) {
       // execute the next listener
-      execution.performAtomicOperation(ExecutionImpl.EXECUTE_EVENT_LISTENER);
-      
+      execution.performAtomicOperation(AtomicOperation.EXECUTE_EVENT_LISTENER);
+
     } else {
-      // there are no more listeners in this even
-      
+      // there are no more listeners in this event
+
       ObservableElementImpl parent = observableElement.getParent();
       // find the next event with listeners
       EventImpl propagatedEvent = ExecutionImpl.findEvent(parent, event.getName());
-      
+
       // if there is an propagated event with listeners 
-      if (propagatedEvent!=null) {
+      if (propagatedEvent != null) {
         // propagate to the that event
         execution.setEvent(propagatedEvent);
         execution.setEventListenerIndex(0);
-        execution.performAtomicOperation(ExecutionImpl.EXECUTE_EVENT_LISTENER);
+        execution.performAtomicOperation(AtomicOperation.EXECUTE_EVENT_LISTENER);
 
       } else {
         // event is completed, perform the eventCompletedOperation 
@@ -101,8 +116,8 @@
         execution.setEventSource(null);
         execution.setEventListenerIndex(0);
         execution.setEventCompletedOperation(null);
-        
-        if (eventCompletedOperation!=null) {
+
+        if (eventCompletedOperation != null) {
           execution.performAtomicOperation(eventCompletedOperation);
         }
       }
@@ -110,7 +125,7 @@
   }
 
   public MessageImpl< ? > createAsyncMessage(ExecutionImpl execution) {
-    throw new UnsupportedOperationException("please implement me");
+    return new ExecuteEventListenerMessage(execution);
   }
 
   public String toString() {

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteEventListenerMessage.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteEventListenerMessage.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteEventListenerMessage.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -21,79 +21,141 @@
  */
 package org.jbpm.pvm.internal.model.op;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.jbpm.api.env.Environment;
-import org.jbpm.api.listener.EventListener;
-import org.jbpm.api.model.ObservableElement;
-import org.jbpm.api.session.RepositorySession;
 import org.jbpm.pvm.internal.job.MessageImpl;
+import org.jbpm.pvm.internal.jobexecutor.JobDbSession;
 import org.jbpm.pvm.internal.model.ActivityImpl;
 import org.jbpm.pvm.internal.model.EventImpl;
-import org.jbpm.pvm.internal.model.EventListenerReference;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.pvm.internal.model.ObservableElementImpl;
 import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
 import org.jbpm.pvm.internal.model.TransitionImpl;
 
-
 /**
  * @author Tom Baeyens
  */
 public class ExecuteEventListenerMessage extends MessageImpl<Object> {
 
+  private static final String KEY_EVENT_COMPLETED_OPERATION = "ECO";
+  private static final String KEY_EVENT_LISTENER_INDEX = "ELI";
+  private static final String KEY_EVENT_NAME = "EN";
+  private static final String KEY_EVENT_OBSERVABLE_PARENT_LEVEL = "EOPL";
+  private static final String KEY_TRANSITION_SOURCE_INDEX = "TSI";
+  private static final String KEY_TRANSITION_SOURCE = "TS";
+  private static final String KEY_EVENT_SOURCE_TRANSITION = "EST";
+  private static final String KEY_EVENT_SOURCE_ACTIVITY = "ESA";
+  private static final String KEY_EVENT_SOURCE_PROCESS_DEFINITION = "ESPD";
+  private static final String KEY_STATE = "S";
+  
   private static final long serialVersionUID = 1L;
 
-  protected String processDefinitionId;
-  protected String activityName;
-  protected Integer transitionIndex;
-  protected String eventName;
-  protected Integer eventListenerIndex;
-  
   public ExecuteEventListenerMessage() {
   }
 
-  public ExecuteEventListenerMessage(ExecutionImpl execution, ObservableElement observableElement, EventImpl event, EventListenerReference eventListenerReference) {
+  public ExecuteEventListenerMessage(ExecutionImpl execution) {
     super(execution);
-    if (observableElement instanceof ProcessDefinitionImpl) {
-      ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl) observableElement;
-      processDefinitionId = processDefinition.getId(); 
-    } else if (observableElement instanceof ActivityImpl) {
-      ActivityImpl activity = (ActivityImpl) observableElement;
-      processDefinitionId = activity.getProcessDefinition().getId();
-      activityName = activity.getName();
-    } else if (observableElement instanceof TransitionImpl) {
-      TransitionImpl transition = (TransitionImpl) observableElement;
-      processDefinitionId = transition.getProcessDefinition().getId();
-      activityName = transition.getSource().getName();
-      transitionIndex = transition.getSource().getOutgoingTransitions().indexOf(transition);
+    
+    Map<String, Object> asyncExecutionInfo = new HashMap<String, Object>();
+    
+    TransitionImpl transition = execution.getTransition();
+    if (transition!=null) {
+      ActivityImpl source = transition.getSource();
+      asyncExecutionInfo.put(KEY_TRANSITION_SOURCE, source.getName());
+      asyncExecutionInfo.put(KEY_TRANSITION_SOURCE_INDEX, source.getOutgoingTransitions().indexOf(transition));
     }
+
+    asyncExecutionInfo.put(KEY_STATE, execution.getState());
+
+    ObservableElementImpl eventSource = (ObservableElementImpl) execution.getEventSource();
+    if (eventSource instanceof ProcessDefinitionImpl) {
+      asyncExecutionInfo.put(KEY_EVENT_SOURCE_PROCESS_DEFINITION, null);
+      
+    } else if (eventSource instanceof ActivityImpl) {
+      asyncExecutionInfo.put(KEY_EVENT_SOURCE_ACTIVITY, eventSource.getName());
+      
+    } else if (eventSource instanceof TransitionImpl) {
+      asyncExecutionInfo.put(KEY_EVENT_SOURCE_TRANSITION, null);
+    }
+
+    EventImpl event = execution.getEvent();
+    asyncExecutionInfo.put(KEY_EVENT_OBSERVABLE_PARENT_LEVEL, getEventObservableParentLevel(eventSource, event.getObservableElement()));
+    asyncExecutionInfo.put(KEY_EVENT_NAME, event.getName());
     
-    eventName = event.getName();
-    eventListenerIndex = event.getListenerReferences().indexOf(eventListenerReference);
+    asyncExecutionInfo.put(KEY_EVENT_LISTENER_INDEX, execution.getEventListenerIndex());
+    
+    AtomicOperation eventCompletedOperation = execution.getEventCompletedOperation();
+    String eventCompletedOperationText = null;
+    if (eventCompletedOperation!=null) {
+      eventCompletedOperationText = eventCompletedOperation.toString();
+    }
+    asyncExecutionInfo.put(KEY_EVENT_COMPLETED_OPERATION, eventCompletedOperationText);
+    
+    setConfiguration(asyncExecutionInfo);
   }
 
+  public Integer getEventObservableParentLevel(ObservableElementImpl eventSource, ObservableElementImpl observableElement) {
+    int parentLevel = 0;
+    while (eventSource!=observableElement) {
+      parentLevel++;
+      eventSource = eventSource.getParent();
+    }
+    return parentLevel;
+  }
+
   public Object execute(Environment environment) throws Exception {
-    ObservableElementImpl observableElement = null;
+    Map<String, Object> asyncExecutionInfo = (Map) getConfiguration();
+
+    String transitionSourceName = (String) asyncExecutionInfo.get(KEY_TRANSITION_SOURCE);
+    TransitionImpl transition = null;
+    if (transitionSourceName!=null) {
+      ProcessDefinitionImpl processDefinition = execution.getProcessDefinition();
+      ActivityImpl transitionSource = processDefinition.findActivity(transitionSourceName);
+      Integer transitionIndex = (Integer) asyncExecutionInfo.get(KEY_TRANSITION_SOURCE_INDEX);
+      transition = (TransitionImpl) transitionSource.getOutgoingTransitions().get(transitionIndex);
+      execution.setTransition(transition);
+    }
+
+    if (asyncExecutionInfo.containsKey(KEY_EVENT_SOURCE_PROCESS_DEFINITION)){
+      ProcessDefinitionImpl processDefinition = execution.getProcessDefinition();
+      execution.setEventSource(processDefinition);
+
+    } else if (asyncExecutionInfo.containsKey(KEY_EVENT_SOURCE_ACTIVITY)){
+      ProcessDefinitionImpl processDefinition = execution.getProcessDefinition();
+      String activityName = (String) asyncExecutionInfo.get(KEY_EVENT_SOURCE_ACTIVITY);
+      ActivityImpl activity = processDefinition.findActivity(activityName);
+      execution.setEventSource(activity);
     
-    RepositorySession repositorySession = environment.get(RepositorySession.class);
-    ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl) repositorySession.findProcessDefinitionById(processDefinitionId);
-    if (activityName!=null) {
-      ActivityImpl activity = processDefinition.findActivity(activityName);
-      if (transitionIndex!=null) {
-        TransitionImpl transition = (TransitionImpl) activity.getOutgoingTransitions().get(transitionIndex);
-        observableElement = transition;
-      } else {
-        observableElement = activity;
-      }
-    } else {
-      observableElement = processDefinition;
+    } else if (asyncExecutionInfo.containsKey(KEY_EVENT_SOURCE_TRANSITION)){
+      execution.setEventSource(transition);
     }
     
+    ObservableElementImpl observableElement = (ObservableElementImpl) execution.getEventSource();
+    int parentLevel = (Integer) asyncExecutionInfo.get(KEY_EVENT_OBSERVABLE_PARENT_LEVEL);
+    for (int i=0; i<parentLevel; parentLevel++) {
+      observableElement = observableElement.getParent();
+    }
+    
+    String eventName = (String) asyncExecutionInfo.get(KEY_EVENT_NAME);
     EventImpl event = observableElement.getEvent(eventName);
-    EventListenerReference eventListenerReference = event.getListenerReferences().get(eventListenerIndex);
-    EventListener eventListener = eventListenerReference.get();
+    execution.setEvent(event);
     
-    eventListener.notify(execution);
+    Integer eventListenerIndex = (Integer) asyncExecutionInfo.get(KEY_EVENT_LISTENER_INDEX);
+    execution.setEventListenerIndex(eventListenerIndex);
+
+    String eventCompletedOperationText = (String) asyncExecutionInfo.get(KEY_EVENT_COMPLETED_OPERATION);
+    AtomicOperation eventCompletedOperation = AtomicOperation.parseAtomicOperation(eventCompletedOperationText);
+    execution.setEventCompletedOperation(eventCompletedOperation);
     
+    execution.setState((String) asyncExecutionInfo.get(KEY_STATE));
+
+    execution.performAtomicOperationSync(AtomicOperation.EXECUTE_EVENT_LISTENER);
+    
+    JobDbSession jobDbSession = environment.get(JobDbSession.class);
+    jobDbSession.delete(this);
+
     return null;
   }
 }

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/MoveToChildActivity.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/MoveToChildActivity.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/MoveToChildActivity.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -29,7 +29,7 @@
 /**
  * @author Tom Baeyens
  */
-public class MoveToChildActivity implements AtomicOperation {
+public class MoveToChildActivity extends AtomicOperation {
   
   ActivityImpl activity;
 
@@ -40,7 +40,7 @@
   public void perform(ExecutionImpl execution) {
     execution.setActivity(activity);
     ExecutionImpl propagatingExecution = execution.startActivity(activity);
-    propagatingExecution.performAtomicOperation(ExecutionImpl.EXECUTE_ACTIVITY);
+    propagatingExecution.performAtomicOperation(AtomicOperation.EXECUTE_ACTIVITY);
   }
 
   public boolean isAsync(ExecutionImpl execution) {

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/MoveToParentActivity.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/MoveToParentActivity.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/MoveToParentActivity.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -28,7 +28,7 @@
 /**
  * @author Tom Baeyens
  */
-public class MoveToParentActivity implements AtomicOperation {
+public class MoveToParentActivity extends AtomicOperation {
 
   public void perform(ExecutionImpl execution) {
     ActivityImpl activity = execution.getActivity();
@@ -46,4 +46,8 @@
   public boolean isAsync(ExecutionImpl execution) {
     return false;
   }
+  
+  public String toString() {
+    return "MoveToParentActivity";
+  }
 }

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/Signal.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/Signal.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/Signal.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -34,7 +34,7 @@
 /**
  * @author Tom Baeyens
  */
-public class Signal implements AtomicOperation {
+public class Signal extends AtomicOperation {
 
   private static final Log log = Log.getLog(Signal.class.getName());
 

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivity.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivity.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivity.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -25,12 +25,13 @@
 import org.jbpm.pvm.internal.job.MessageImpl;
 import org.jbpm.pvm.internal.model.ActivityImpl;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ObservableElementImpl;
 
 
 /**
  * @author Tom Baeyens
  */
-public class TransitionEndActivity implements AtomicOperation {
+public class TransitionEndActivity extends AtomicOperation {
 
   public boolean isAsync(ExecutionImpl execution) {
     return false;
@@ -38,7 +39,7 @@
 
   public void perform(ExecutionImpl execution) {
     ActivityImpl activity = execution.getActivity();
-
+    
     ExecutionImpl propagatingExecution = execution;
     if (activity.isLocalScope()) {
       propagatingExecution = execution.destroyScope(activity);
@@ -46,18 +47,16 @@
 
     ActivityImpl parentActivity = activity.getParentActivity();
     ActivityImpl destination = execution.getTransition().getDestination();
-    if (isLeft(parentActivity, activity, destination)) {
+    if ( (parentActivity!=null)
+         && (!parentActivity.contains(destination))
+       ) {
       propagatingExecution.setActivity(parentActivity);
-      propagatingExecution.fire(Event.END, parentActivity, ExecutionImpl.TRANSITION_END_ACTIVITY);
+      propagatingExecution.fire(Event.END, parentActivity, AtomicOperation.TRANSITION_END_ACTIVITY);
     } else {
-      propagatingExecution.performAtomicOperation(ExecutionImpl.TRANSITION_TAKE);
+      propagatingExecution.performAtomicOperation(AtomicOperation.TRANSITION_TAKE);
     }
   }
 
-  protected boolean isLeft(ActivityImpl activity, ActivityImpl from, ActivityImpl to) {
-    return false;
-  }
-
   public MessageImpl< ? > createAsyncMessage(ExecutionImpl execution) {
     throw new UnsupportedOperationException("please implement me");
   }

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionStartActivity.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionStartActivity.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionStartActivity.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -31,7 +31,7 @@
 /**
  * @author Tom Baeyens
  */
-public class TransitionStartActivity implements AtomicOperation {
+public class TransitionStartActivity extends AtomicOperation {
   
   public boolean isAsync(ExecutionImpl execution) {
     return false;
@@ -70,7 +70,7 @@
 
     if (activity==null) {
       execution.setTransition(null);
-      execution.performAtomicOperation(ExecutionImpl.EXECUTE_ACTIVITY);
+      execution.performAtomicOperation(AtomicOperation.EXECUTE_ACTIVITY);
    
     } else {
       execution.setActivity(activity);
@@ -80,7 +80,7 @@
         propagatingExecution = execution.createScope(activity);
       }
 
-      propagatingExecution.fire(Event.START, activity, ExecutionImpl.TRANSITION_START_ACTIVITY);
+      propagatingExecution.fire(Event.START, activity, AtomicOperation.TRANSITION_START_ACTIVITY);
     }
   }
   

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionStartActivityMessage.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionStartActivityMessage.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionStartActivityMessage.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -43,7 +43,7 @@
   public Object execute(Environment environment) throws Exception {
     AsyncContinuations.restoreState(execution);
 
-    execution.performAtomicOperationSync(ExecutionImpl.TRANSITION_START_ACTIVITY);
+    execution.performAtomicOperationSync(AtomicOperation.TRANSITION_START_ACTIVITY);
     
     JobDbSession jobDbSession = environment.get(JobDbSession.class);
     jobDbSession.delete(this);

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionTake.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionTake.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionTake.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -23,7 +23,6 @@
 
 import org.jbpm.api.model.Event;
 import org.jbpm.pvm.internal.job.MessageImpl;
-import org.jbpm.pvm.internal.model.EventImpl;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.pvm.internal.model.TransitionImpl;
 
@@ -31,22 +30,20 @@
 /**
  * @author Tom Baeyens
  */
-public class TransitionTake implements AtomicOperation {
+public class TransitionTake extends AtomicOperation {
 
   public boolean isAsync(ExecutionImpl execution) {
-    TransitionImpl transition = execution.getTransition();
-    EventImpl event = transition.getEvent(Event.TAKE);
-    return ((event!=null) && (event.isAsync()));
+    return false;
   }
 
   public void perform(ExecutionImpl execution) {
     TransitionImpl transition = execution.getTransition();
     execution.setActivity(null);
-    execution.fire(Event.TAKE, transition, ExecutionImpl.TRANSITION_START_ACTIVITY);
+    execution.fire(Event.TAKE, transition, AtomicOperation.TRANSITION_START_ACTIVITY);
   }
 
   public MessageImpl< ? > createAsyncMessage(ExecutionImpl execution) {
-    throw new UnsupportedOperationException("please implement me");
+    return null;
   }
 
   public String toString() {

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/resources/jbpm.execution.hbm.xml	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/resources/jbpm.execution.hbm.xml	2009-05-27 16:43:05 UTC (rev 4917)
@@ -231,20 +231,12 @@
 
     <subclass name="org.jbpm.pvm.internal.job.MessageImpl" discriminator-value="Msg">
       <subclass name="org.jbpm.pvm.internal.model.op.ExecuteActivityMessage" discriminator-value="ExeAct" />
+      <subclass name="org.jbpm.pvm.internal.model.op.ExecuteEventListenerMessage" discriminator-value="ExeEvtLsnr" />
       <subclass name="org.jbpm.pvm.internal.model.op.SignalMessage" discriminator-value="Signal">
         <property name="signalName" column="SIGNAL_" />
       </subclass>
-      <subclass name="org.jbpm.pvm.internal.model.op.TransitionEndActivityMessage" discriminator-value="TrEndAct" />
-      <subclass name="org.jbpm.pvm.internal.model.op.TransitionTakeMessage" discriminator-value="TrTake" />
-      <subclass name="org.jbpm.pvm.internal.model.op.TransitionStartActivityMessage" discriminator-value="TrStartAct" />
-      <subclass name="org.jbpm.pvm.internal.model.op.ExecuteEventListenerMessage" discriminator-value="ExeEvtLst">
-        <property name="processDefinitionId" column="PROCDEF_" />
-        <property name="activityName" column="ACT_" />
-        <property name="transitionIndex" column="TRIDX_" />
-        <property name="eventName" column="EVENT_" />
-        <property name="eventListenerIndex" column="EVTLSTIDX_" />
-      </subclass>
       <subclass name="org.jbpm.pvm.internal.job.CommandMessage" discriminator-value="Cmd" />
+      
     </subclass>
     
     <subclass name="org.jbpm.pvm.internal.job.TimerImpl" discriminator-value="Timer">

Modified: jbpm4/branches/tbaeyens/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventTest.java	2009-05-27 14:04:11 UTC (rev 4916)
+++ jbpm4/branches/tbaeyens/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventTest.java	2009-05-27 16:43:05 UTC (rev 4917)
@@ -231,44 +231,4 @@
       execution.end();
     }
   }
-
-  public static class RecordingProcessDefinition extends ProcessDefinitionImpl {
-    private static final long serialVersionUID = 1L;
-    protected ExecutionImpl newProcessInstance() {
-      return new RecordingExecution();
-    }
-  }
-  
-  public static class RecordingExecution extends ExecutionImpl {
-    private static final long serialVersionUID = 1L;
-    List<String> events = new ArrayList<String>();
-    public void fire(String eventName, ObservableElement eventSource) {
-      events.add(eventName+" on "+eventSource);
-    }
-  }
-  
-  public void testBasicEventSequence() {
-    ClientProcessDefinition processDefinition = ProcessDefinitionBuilder
-    .startProcess("basic", new RecordingProcessDefinition())
-      .startActivity("initial", new AutomaticActivity())
-        .initial()
-        .transition("end")
-      .endActivity()
-      .startActivity("end", new EndState())
-      .endActivity()
-    .endProcess();
-
-    RecordingExecution execution = (RecordingExecution) processDefinition.startProcessInstance();
-
-    int index = 0;
-    assertEquals("start on process(basic)", execution.events.get(index));
-    index++;
-    assertEquals("end on activity(initial)", execution.events.get(index));
-    index++;
-    assertEquals("take on (initial)-->(end)", execution.events.get(index));
-    index++;
-    assertEquals("start on activity(end)", execution.events.get(index));
-    index++;
-    assertEquals("end on process(basic)", execution.events.get(index));
-  }
 }




More information about the jbpm-commits mailing list