Author: tom.baeyens(a)jboss.com
Date: 2009-05-27 08:05:01 -0400 (Wed, 27 May 2009)
New Revision: 4912
Added:
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivity.java
Removed:
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/TransitionEndActivityMessage.java
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionTakeMessage.java
Modified:
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityImpl.java
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/EventImpl.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/ObservableElementImpl.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/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
Log:
execution refactoring
Modified:
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityImpl.java
===================================================================
---
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityImpl.java 2009-05-27
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ActivityImpl.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -400,6 +400,16 @@
return ! (continuation==Continuation.SYNCHRONOUS);
}
+ public boolean contains(ActivityImpl activity) {
+ while (activity!=null) {
+ if (activity.getParent()==this) {
+ return true;
+ }
+ activity = activity.getParentActivity();
+ }
+ return false;
+ }
+
// getters and setters //////////////////////////////////////////////////////
public ObservableElementImpl getParent() {
Modified:
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/EventImpl.java
===================================================================
---
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/EventImpl.java 2009-05-27
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/EventImpl.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -37,6 +37,7 @@
private static final long serialVersionUID = 1L;
protected String name;
+ protected ObservableElementImpl observableElement;
protected List<EventListenerReference> listenerReferences;
protected Continuation continuation = Continuation.SYNCHRONOUS;
@@ -100,4 +101,10 @@
public void setContinuation(Continuation continuation) {
this.continuation = continuation;
}
+ public ObservableElementImpl getObservableElement() {
+ return observableElement;
+ }
+ public void setObservableElement(ObservableElementImpl observableElement) {
+ this.observableElement = observableElement;
+ }
}
\ No newline at end of file
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
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -40,9 +40,7 @@
import org.jbpm.api.activity.ActivityExecution;
import org.jbpm.api.client.ClientProcessDefinition;
import org.jbpm.api.client.ClientProcessInstance;
-import org.jbpm.api.cmd.CommandService;
import org.jbpm.api.env.Environment;
-import org.jbpm.api.env.Transaction;
import org.jbpm.api.job.Timer;
import org.jbpm.api.listener.EventListenerExecution;
import org.jbpm.api.model.Activity;
@@ -56,7 +54,6 @@
import org.jbpm.api.session.RepositorySession;
import org.jbpm.api.session.TimerSession;
import org.jbpm.internal.log.Log;
-import org.jbpm.pvm.internal.env.PvmEnvironment;
import org.jbpm.pvm.internal.hibernate.HibernatePvmDbSession;
import org.jbpm.pvm.internal.history.HistoryEvent;
import org.jbpm.pvm.internal.history.HistorySession;
@@ -94,10 +91,13 @@
// atomic operations
public static final AtomicOperation EXECUTE_ACTIVITY = new ExecuteActivity();
- public static final AtomicOperation TRANSITION_END_ACTIVITY = new
TransitionEndActivity();
+ 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 PROPAGATE_TO_PARENT = new MoveToParentActivity();
+
+ public static final AtomicOperation EXECUTE_EVENT_LISTENER = new
ExecuteEventListener();
+ public static final AtomicOperation TRANSITION_END_ACTIVITY = new
TransitionEndActivity();
// persistent member fields /////////////////////////////////////////////////
@@ -146,9 +146,6 @@
/** persistent activity reference */
protected String activityName;
- protected Integer transitionSourceIndex;
- protected String transitionSourceName;
-
// transient cached indicators of the current position //////////////////////
/** transient cached process definition. persistence is managed in {@link
#processDefinitionId} */
@@ -160,12 +157,12 @@
/** transition is not to be made persistable by default */
protected TransitionImpl transition;
- /** the activity from which the transition was taken. This can be different from
- * the transition source in case a transition of an eclosing activity was taken. */
- protected ActivityImpl transitionSource;
-
protected EventImpl event;
+ protected AtomicOperation eventCompletedOperation;
+
+ protected int eventListenerIndex;
+
protected ObservableElementImpl eventSource;
// cached named executions //////////////////////////////////////////////////
@@ -452,11 +449,14 @@
checkActive();
setPropagation(Propagation.EXPLICIT);
- setTransition((TransitionImpl) transition);
- performAtomicOperation(TRANSITION_END_ACTIVITY);
+ setTransition((TransitionImpl) transition);
+
+ ObservableElementImpl observableElement = getActivity();
+
+ fire(Event.END, observableElement, TRANSITION_END_ACTIVITY);
}
-
+
public void take(Transition transition, Execution execution) {
((ExecutionImpl)execution).take(transition);
}
@@ -532,13 +532,49 @@
setActivity((ActivityImpl) activity);
}
+ // events ///////////////////////////////////////////////////////////////////
+
+ public void fire(String eventName, ObservableElement eventSource) {
+ fire(eventName, (ObservableElementImpl) eventSource, null);
+ }
+
+ public void fire(String eventName, ObservableElementImpl observableElement,
AtomicOperation eventCompletedOperation) {
+ EventImpl event = findEvent(observableElement, eventName);
+ if (event!=null) {
+ setEvent(event);
+ setEventSource(observableElement);
+ setEventListenerIndex(0);
+ setEventCompletedOperation(eventCompletedOperation);
+ performAtomicOperation(EXECUTE_EVENT_LISTENER);
+ } else {
+ if (eventCompletedOperation!=null) {
+ performAtomicOperationSync(eventCompletedOperation);
+ }
+ }
+ }
+
+ public static EventImpl findEvent(ObservableElementImpl observableElement, String
eventName) {
+ if (observableElement==null) {
+ return null;
+ }
+
+ EventImpl event = observableElement.getEvent(eventName);
+ if ( (event==null)
+ || (event.getListenerReferences()==null)
+ || (event.getListenerReferences().isEmpty())
+ ) {
+ return event;
+ }
+
+ return findEvent(observableElement.getParent(), eventName);
+ }
+
// execution : internal methods /////////////////////////////////////////////
public void moveTo(ActivityImpl destination) {
// move the execution to the destination
setActivity(destination);
transition = null;
- transitionSource = null;
}
public ExecutionImpl startActivity(ActivityImpl activity) {
@@ -603,52 +639,6 @@
}
}
- // events ///////////////////////////////////////////////////////////////////
-
- /** @see Execution#fire(String, ObservableElement) */
- public void fire(String eventName, ObservableElement eventSource) {
- fire(eventName, eventSource, (ObservableElementImpl) eventSource);
- }
-
- /** fires the event on the given *processElement* and then propagates the event
- * up to the *processElement* parent chain. */
- void fire(String eventName, ObservableElement eventSource, ObservableElementImpl
observableElement) {
- if (observableElement!=null) {
- EventImpl event = (EventImpl) observableElement.getEvent(eventName);
- if (event!=null) {
- if (log.isTraceEnabled()) {
- if (observableElement==eventSource) {
- log.trace("firing "+event+" on "+eventSource);
- } else {
- log.trace("firing "+event+" on
"+observableElement+", propagated from source "+eventSource);
- }
- }
- fire(event, eventSource, observableElement);
- }
- propagateEvent(eventName, eventSource, observableElement);
- }
- }
-
- /** this method enables specific process languages to overwrite the event propagation
behaviour */
- protected void propagateEvent(String eventName, ObservableElement eventSource,
ObservableElementImpl observableElement) {
- fire(eventName, eventSource, observableElement.getParent());
- }
-
- /** fires the given event without propagation */
- public void fire(EventImpl event, ObservableElement eventSource, ObservableElement
observableElement) {
- List<EventListenerReference> eventListenerReferences =
event.getListenerReferences();
- if (eventListenerReferences!=null) {
- for (EventListenerReference eventListenerReference: eventListenerReferences) {
- ExecuteEventListener executeEventListenerOperation = new
ExecuteEventListener(eventListenerReference, event, (ObservableElementImpl) eventSource,
observableElement);
- if (eventListenerReference.isAsync()) {
- sendContinuationMessage(executeEventListenerOperation);
- } else {
- executeEventListenerOperation.perform(this);
- }
- }
- }
- }
-
public void handleException(ObservableElementImpl observableElement,
EventImpl event,
EventListenerReference eventListenerReference,
@@ -690,23 +680,6 @@
ExceptionHandlerImpl.rethrow(exception, rethrowMessage+":
"+exception.getMessage());
}
-
- /** searches for an event up the process element parent hierarchy starting
- * from the given process element and returns an event or null if no such
- * event exists. */
- EventImpl findEvent(String eventName, ObservableElementImpl observableElement) {
- EventImpl event = null;
- while ( (event==null)
- && (observableElement!=null)
- ) {
- event = (EventImpl) observableElement.getEvent(eventName);
- if (event==null) {
- observableElement = observableElement.getParent();
- }
- }
- return event;
- }
-
// comments /////////////////////////////////////////////////////////////////
public Comment createComment(String message) {
@@ -1070,59 +1043,40 @@
return activityName;
}
- // transition getter and setter /////////////////////////////////////////////
- // this getter and setter is special because persistence is based on the //
- // transition index of the current activity. //
- /////////////////////////////////////////////////////////////////////////////
+ // special getters and setters /////////////////////////////////////////////////
- public void setTransition(TransitionImpl transition) {
- this.transition = transition;
- if (transition==null) {
- this.transitionSource = null;
- this.transitionSourceName = null;
- this.transitionSourceIndex = null;
- } else {
- this.transitionSource = transition.getSource();
- this.transitionSourceName = transitionSource.getName();
- this.transitionSourceIndex = transition.getSourceIndex();
+ public boolean hasAsyncEndEvent(List<ActivityImpl> leftActivities) {
+ for (ActivityImpl leftActivity : leftActivities) {
+ EventImpl endEvent = leftActivity.getEvent(Event.END);
+ if ( (endEvent!=null)
+ && (endEvent.isAsync())
+ ) {
+ return true;
+ }
}
+ return false;
}
- public TransitionImpl getTransition() {
- if ( (transition==null)
- && (transitionSourceIndex!=null)
- ) {
- transition = (TransitionImpl)
getTransitionSource().getOutgoingTransitions().get(transitionSourceIndex);
+ public List<Comment> getComments() {
+ if (comments==null) {
+ return Collections.emptyList();
}
- return transition;
+ return new ArrayList<Comment>(comments);
}
-
- public ActivityImpl getTransitionSource() {
- if ( (transitionSource==null)
- && (transitionSourceName!=null)
- ) {
- transitionSource = getProcessDefinition().findActivity(transitionSourceName);
- }
- return transitionSource;
- }
-
-
- // getters and setters /////////////////////////////////////////////////////////
-
-
public boolean isProcessInstance() {
return parent==null;
}
- public List<Comment> getComments() {
- if (comments==null) {
- return Collections.emptyList();
- }
- return new ArrayList<Comment>(comments);
+ // getters and setters /////////////////////////////////////////////////////////
+
+ public TransitionImpl getTransition() {
+ return transition;
}
-
- public Event getEvent() {
+ public void setTransition(TransitionImpl transition) {
+ this.transition = transition;
+ }
+ public EventImpl getEvent() {
return event;
}
public ObservableElement getEventSource() {
@@ -1212,16 +1166,16 @@
public String getProcessDefinitionId() {
return processDefinitionId;
}
-
- public boolean hasAsyncEndEvent(List<ActivityImpl> leftActivities) {
- for (ActivityImpl leftActivity : leftActivities) {
- EventImpl endEvent = leftActivity.getEvent(Event.END);
- if ( (endEvent!=null)
- && (endEvent.isAsync())
- ) {
- return true;
- }
- }
- return false;
+ public int getEventListenerIndex() {
+ return eventListenerIndex;
}
+ public void setEventListenerIndex(int eventListenerIndex) {
+ this.eventListenerIndex = eventListenerIndex;
+ }
+ public AtomicOperation getEventCompletedOperation() {
+ return eventCompletedOperation;
+ }
+ public void setEventCompletedOperation(AtomicOperation eventCompletedOperation) {
+ this.eventCompletedOperation = eventCompletedOperation;
+ }
}
Modified:
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ObservableElementImpl.java
===================================================================
---
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ObservableElementImpl.java 2009-05-27
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ObservableElementImpl.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -59,6 +59,7 @@
/** event factory method that also establishes the bidirectional relation. */
public EventImpl createEvent(String eventName) {
EventImpl event = new EventImpl();
+ event.setObservableElement(this);
event.setName(eventName);
return addEvent(event);
}
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
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/ExecuteEventListener.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -21,6 +21,8 @@
*/
package org.jbpm.pvm.internal.model.op;
+import java.util.List;
+
import org.jbpm.api.listener.EventListener;
import org.jbpm.api.model.ObservableElement;
import org.jbpm.internal.log.Log;
@@ -38,50 +40,77 @@
private static Log log = Log.getLog(ExecuteEventListener.class.getName());
- protected EventListenerReference eventListenerReference;
- protected EventImpl event;
- protected ObservableElementImpl eventSource;
- protected ObservableElement observableElement;
-
- public ExecuteEventListener(EventListenerReference eventListenerReference, EventImpl
event, ObservableElementImpl eventSource, ObservableElement observableElement) {
- this.eventListenerReference = eventListenerReference;
- this.event = event;
- this.eventSource = eventSource;
- this.observableElement = observableElement;
- }
-
public boolean isAsync(ExecutionImpl execution) {
+ int eventListenerIndex = execution.getEventListenerIndex();
+ EventImpl event = execution.getEvent();
+ List<EventListenerReference> eventListenerReferences =
event.getListenerReferences();
+ EventListenerReference eventListenerReference =
eventListenerReferences.get(eventListenerIndex);
return eventListenerReference.isAsync();
}
public void perform(ExecutionImpl execution) {
- try {
- execution.setEvent(event);
- execution.setEventSource(eventSource);
+ EventImpl event = execution.getEvent();
+ int eventListenerIndex = execution.getEventListenerIndex();
+ List<EventListenerReference> eventListenerReferences =
event.getListenerReferences();
+ EventListenerReference eventListenerReference =
eventListenerReferences.get(eventListenerIndex);
+ ObservableElement eventSource = execution.getEventSource();
+ ObservableElementImpl observableElement = event.getObservableElement();
- if ( (observableElement.equals(eventSource)) // this event is not propagated
- || (eventListenerReference.isPropagationEnabled()) // propagation is
allowed
- ) {
- EventListener eventListener = eventListenerReference.get();
+ 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);
+
+ // if there are more listeners in this event
+ if (eventListenerIndex<eventListenerReferences.size()) {
+ // execute the next listener
+ execution.performAtomicOperation(ExecutionImpl.EXECUTE_EVENT_LISTENER);
+
+ } else {
+ // there are no more listeners in this even
+
+ 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) {
+ // propagate to the that event
+ execution.setEvent(propagatedEvent);
+ execution.setEventListenerIndex(0);
+ execution.performAtomicOperation(ExecutionImpl.EXECUTE_EVENT_LISTENER);
+
+ } else {
+ // event is completed, perform the eventCompletedOperation
+ AtomicOperation eventCompletedOperation =
execution.getEventCompletedOperation();
+
+ execution.setEvent(null);
+ execution.setEventSource(null);
+ execution.setEventListenerIndex(0);
+ execution.setEventCompletedOperation(null);
- 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);
+ if (eventCompletedOperation!=null) {
+ execution.performAtomicOperation(eventCompletedOperation);
}
}
-
- } finally {
- execution.setEvent(null);
- execution.setEventSource(null);
}
}
public MessageImpl< ? > createAsyncMessage(ExecutionImpl execution) {
- return new ExecuteEventListenerMessage(execution, observableElement, event,
eventListenerReference);
+ throw new UnsupportedOperationException("please implement me");
}
public String toString() {
Deleted:
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
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivity.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -1,97 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, 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.jbpm.pvm.internal.model.op;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jbpm.internal.log.Log;
-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;
-import org.jbpm.pvm.internal.model.TransitionImpl;
-
-public class TransitionEndActivity implements AtomicOperation {
-
- private static final TransitionTake TRANSITION_TAKE = new TransitionTake();
-
- private static Log log = Log.getLog(TransitionEndActivity.class.getName());
-
- public boolean isAsync(ExecutionImpl execution) {
- TransitionImpl transition = execution.getTransition();
- List<ActivityImpl> leftActivities = getActivitiesLeft(execution.getActivity(),
transition.getDestination());
- return execution.hasAsyncEndEvent(leftActivities);
- }
-
- public void perform(ExecutionImpl execution) {
- TransitionImpl transition = execution.getTransition();
-
- if (execution.getName() != null) {
- log.debug(execution.toString() + " takes " + transition);
- } else {
- log.debug("taking " + transition);
- }
-
- List<ActivityImpl> leftActivities = getActivitiesLeft(execution.getActivity(),
transition.getDestination());
- ExecutionImpl propagatingExecution = endActivity(execution, leftActivities);
-
- propagatingExecution.performAtomicOperation(TRANSITION_TAKE);
- }
-
- public static ExecutionImpl endActivity(ExecutionImpl execution,
List<ActivityImpl> leftActivities) {
- ExecutionImpl propagatingExecution = execution;
- for (ActivityImpl leftActivity : leftActivities) {
- propagatingExecution = propagatingExecution.endActivity(leftActivity);
- }
- propagatingExecution.setActivity(null);
- return propagatingExecution;
- }
-
- List<ActivityImpl> getActivitiesLeft(ActivityImpl source, ActivityImpl
destination) {
- List<ActivityImpl> activitiesLeft = new ArrayList<ActivityImpl>();
-
- if (source.equals(destination)) {
- activitiesLeft.add(source);
- } else {
- List<ObservableElementImpl> destinationChain = destination.getParentChain();
-
- if (!destinationChain.contains(source)) {
- ActivityImpl sourceActivity = source;
- while ((sourceActivity != null) &&
(!destinationChain.contains(sourceActivity))) {
- activitiesLeft.add(sourceActivity);
- sourceActivity = sourceActivity.getParentActivity();
- }
- }
- }
-
- return activitiesLeft;
- }
-
- public String toString() {
- return "TakeTransition";
- }
-
- public MessageImpl< ? > createAsyncMessage(ExecutionImpl execution) {
- return new TransitionEndActivityMessage(execution);
- }
-}
\ No newline at end of file
Added:
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
(rev 0)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivity.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbpm.pvm.internal.model.op;
+
+import org.jbpm.api.model.Event;
+import org.jbpm.pvm.internal.job.MessageImpl;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TransitionEndActivity implements AtomicOperation {
+
+ public boolean isAsync(ExecutionImpl execution) {
+ return false;
+ }
+
+ public void perform(ExecutionImpl execution) {
+ ActivityImpl activity = execution.getActivity();
+
+ ExecutionImpl propagatingExecution = execution;
+ if (activity.isLocalScope()) {
+ propagatingExecution = execution.destroyScope(activity);
+ }
+
+ ActivityImpl parentActivity = activity.getParentActivity();
+ ActivityImpl destination = execution.getTransition().getDestination();
+ if (isLeft(parentActivity, activity, destination)) {
+ propagatingExecution.setActivity(parentActivity);
+ propagatingExecution.fire(Event.END, parentActivity,
ExecutionImpl.TRANSITION_END_ACTIVITY);
+ } else {
+ propagatingExecution.performAtomicOperation(ExecutionImpl.TRANSITION_TAKE);
+ }
+ }
+
+ protected boolean isLeft(ActivityImpl activity, ActivityImpl from, ActivityImpl to) {
+ return false;
+ }
+
+ public MessageImpl< ? > createAsyncMessage(ExecutionImpl execution) {
+ throw new UnsupportedOperationException("please implement me");
+ }
+
+ public String toString() {
+ return "TransitionEndActivity";
+ }
+}
Property changes on:
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivity.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivityMessage.java
===================================================================
---
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivityMessage.java 2009-05-27
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionEndActivityMessage.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, 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.jbpm.pvm.internal.model.op;
-
-import org.jbpm.api.Execution;
-import org.jbpm.api.env.Environment;
-import org.jbpm.pvm.internal.job.MessageImpl;
-import org.jbpm.pvm.internal.jobexecutor.JobDbSession;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-
-/**
- * @author Tom Baeyens
- */
-public class TransitionEndActivityMessage extends MessageImpl<Object> {
-
- private static final long serialVersionUID = 1L;
-
- public TransitionEndActivityMessage() {
- }
-
- public TransitionEndActivityMessage(ExecutionImpl execution) {
- super(execution);
- }
-
- public Object execute(Environment environment) throws Exception {
- AsyncContinuations.restoreState(execution);
-
- execution.performAtomicOperationSync(ExecutionImpl.TRANSITION_END_ACTIVITY);
-
- JobDbSession jobDbSession = environment.get(JobDbSession.class);
- jobDbSession.delete(this);
-
- return null;
- }
-
- public String toString() {
- return "TakeTransitionMessage["+dbid+"]";
- }
-}
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
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionStartActivity.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -21,13 +21,11 @@
*/
package org.jbpm.pvm.internal.model.op;
-import java.util.LinkedList;
-import java.util.List;
-
+import org.jbpm.api.JbpmException;
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.ActivityImpl;
-import org.jbpm.pvm.internal.model.ObservableElementImpl;
+import org.jbpm.pvm.internal.model.TransitionImpl;
/**
* @author Tom Baeyens
@@ -39,50 +37,57 @@
}
public void perform(ExecutionImpl execution) {
- ActivityImpl destination = execution.getTransition().getDestination();
- execution.setActivity(destination);
- List<ActivityImpl> enteredActivities =
getActivitiesEntered(execution.getTransitionSource(), destination);
+ TransitionImpl transition = execution.getTransition();
+ ActivityImpl source = transition.getSource();
+ ActivityImpl destination = transition.getDestination();
- ExecutionImpl propagatingExecution = execution;
- for (ActivityImpl enteredActivity : enteredActivities) {
- propagatingExecution = propagatingExecution.startActivity(enteredActivity);
- }
-
- propagatingExecution.setActivity(destination);
- propagatingExecution.setTransition(null);
-
- propagatingExecution.performAtomicOperation(ExecutionImpl.EXECUTE_ACTIVITY);
- }
-
- public List<ActivityImpl> getActivitiesEntered(ActivityImpl origin, ActivityImpl
destination) {
- LinkedList<ActivityImpl> activitiesEntered = new
LinkedList<ActivityImpl>();
-
- if (origin.equals(destination)) {
- activitiesEntered.add(destination);
+ ActivityImpl activity = execution.getActivity();
+ if (activity==null) {
+ // find outer most activity to start
+ activity = destination;
+ while ( (activity.getParentActivity()!=null)
+ && (!activity.getParentActivity().contains(source))
+ ) {
+ activity = activity.getParentActivity();
+ }
+ } else if (activity==destination){
+ activity = null;
+
} else {
- List<ObservableElementImpl> sourceChain = origin.getParentChain();
-
- if (!sourceChain.contains(destination)) {
- ActivityImpl destinationActivity = destination;
- while ( (destinationActivity!=null)
- && (!sourceChain.contains(destinationActivity))
- ) {
- activitiesEntered.addFirst(destinationActivity);
- destinationActivity = destinationActivity.getParentActivity();
- }
+ ActivityImpl parent = activity;
+ activity = destination;
+ while ( (activity!=null)
+ && (activity.getParent()!=parent)
+ ) {
+ activity = activity.getParentActivity();
}
+ if (activity==null) {
+ throw new JbpmException("implementation bug: couldn't find parent
"+parent+" around destination "+destination);
+ }
}
- return activitiesEntered;
+ if (activity==null) {
+ execution.setTransition(null);
+ execution.performAtomicOperation(ExecutionImpl.EXECUTE_ACTIVITY);
+
+ } else {
+ execution.setActivity(activity);
+
+ ExecutionImpl propagatingExecution = execution;
+ if (activity.isLocalScope()) {
+ propagatingExecution = execution.createScope(activity);
+ }
+
+
propagatingExecution.performAtomicOperation(ExecutionImpl.TRANSITION_START_ACTIVITY);
+ }
}
-
- public String toString() {
- return "ProceedToDestination";
+ public MessageImpl<?> createAsyncMessage(ExecutionImpl execution) {
+ throw new UnsupportedOperationException("please implement me");
}
- public MessageImpl<?> createAsyncMessage(ExecutionImpl execution) {
- return new TransitionStartActivityMessage(execution);
+ public String toString() {
+ return "TransitionStartActivity";
}
}
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
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionStartActivityMessage.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -21,7 +21,6 @@
*/
package org.jbpm.pvm.internal.model.op;
-import org.jbpm.api.Execution;
import org.jbpm.api.env.Environment;
import org.jbpm.pvm.internal.job.MessageImpl;
import org.jbpm.pvm.internal.jobexecutor.JobDbSession;
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
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionTake.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -41,11 +41,15 @@
public void perform(ExecutionImpl execution) {
TransitionImpl transition = execution.getTransition();
- execution.fire(Event.TAKE, transition);
- execution.performAtomicOperation(ExecutionImpl.TRANSITION_START_ACTIVITY);
+ execution.setActivity(null);
+ execution.fire(Event.TAKE, transition, ExecutionImpl.TRANSITION_START_ACTIVITY);
}
public MessageImpl< ? > createAsyncMessage(ExecutionImpl execution) {
- return new TransitionTakeMessage(execution);
+ throw new UnsupportedOperationException("please implement me");
}
+
+ public String toString() {
+ return "TransitionTake";
+ }
}
Deleted:
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionTakeMessage.java
===================================================================
---
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionTakeMessage.java 2009-05-27
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/op/TransitionTakeMessage.java 2009-05-27
12:05:01 UTC (rev 4912)
@@ -1,59 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, 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.jbpm.pvm.internal.model.op;
-
-import org.jbpm.api.Execution;
-import org.jbpm.api.env.Environment;
-import org.jbpm.pvm.internal.job.MessageImpl;
-import org.jbpm.pvm.internal.jobexecutor.JobDbSession;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-
-
-/**
- * @author Tom Baeyens
- */
-public class TransitionTakeMessage extends MessageImpl<Object> {
-
- private static final long serialVersionUID = 1L;
-
- public TransitionTakeMessage() {
- }
-
- public TransitionTakeMessage(ExecutionImpl execution) {
- super(execution);
- }
-
- public Object execute(Environment environment) throws Exception {
- AsyncContinuations.restoreState(execution);
-
- execution.performAtomicOperationSync(ExecutionImpl.TRANSITION_TAKE);
-
- JobDbSession jobDbSession = environment.get(JobDbSession.class);
- jobDbSession.delete(this);
-
- return null;
- }
-
- public String toString() {
- return "TransitionTakeMessage["+dbid+"]";
- }
-}
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
10:03:38 UTC (rev 4911)
+++
jbpm4/branches/tbaeyens/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2009-05-27
12:05:01 UTC (rev 4912)
@@ -30,8 +30,6 @@
<property name="activityName" column="ACTIVITYNAME_" />
<property name="processDefinitionId" column="PROCDEFID_"
/>
- <property name="transitionSourceName" column="TRANSRC_" />
- <property name="transitionSourceIndex" column="TRANSRCIDX_"
/>
<property name="hasVariables" column="HASVARS_" />
<map name="variables"