[jbpm-commits] JBoss JBPM SVN: r4874 - in jbpm4/trunk/modules: api/src/main/java/org/jbpm/api/session and 7 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri May 22 10:06:48 EDT 2009
Author: tom.baeyens at jboss.com
Date: 2009-05-22 10:06:47 -0400 (Fri, 22 May 2009)
New Revision: 4874
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/OpenExecution.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/session/TimerSession.java
jbpm4/trunk/modules/enterprise/src/main/java/org/jbpm/enterprise/internal/ejb/EjbTimerSession.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TimerSessionBinding.java
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
Log:
JBPM-2256 removed relation ScopeInstanceImpl.timers. This was a bug that popped up in context of async fork
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/OpenExecution.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/OpenExecution.java 2009-05-22 10:03:00 UTC (rev 4873)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/OpenExecution.java 2009-05-22 14:06:47 UTC (rev 4874)
@@ -113,14 +113,6 @@
* the given type name. */
void createVariable(String key, Object value, String typeName);
- // timer access /////////////////////////////////////////////////////////////
-
- /** indicates if this execution scope has timers */
- boolean hasTimers();
-
- /** timers for this execution scope */
- Set<Timer> getTimers();
-
// priority /////////////////////////////////////////////////////////////////
/** setter for the priority. The default priority is 0, which means
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/session/TimerSession.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/session/TimerSession.java 2009-05-22 10:03:00 UTC (rev 4873)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/session/TimerSession.java 2009-05-22 14:06:47 UTC (rev 4874)
@@ -21,6 +21,9 @@
*/
package org.jbpm.api.session;
+import java.util.List;
+
+import org.jbpm.api.Execution;
import org.jbpm.api.job.Timer;
/**
@@ -28,28 +31,30 @@
*/
public interface TimerSession {
- /**
- * Schedule the execution of a timer.
- * @param timerImpl the timer to be executed.
- * @throws IllegalArgumentException if the timer is null
- * or if its activity is null or if its dueDate is null
- * or if its dueDate is negative or if its dueDate is past
- * or if its dueDate is equals to Long.MAX_VALUE
- */
- public void schedule(Timer timer);
+ /** Schedule the execution of a timer.
+ *
+ * @param timerImpl
+ * the timer to be executed.
+ * @throws IllegalArgumentException
+ * if the timer is null or if its activity is null or if its dueDate
+ * is null or if its dueDate is negative or if its dueDate is past
+ * or if its dueDate is equals to Long.MAX_VALUE
+ */
+ void schedule(Timer timer);
- /**
- * Cancels a timer.
- * <br />
- * If a transaction is in progress, the cancellation will be effective
- * at the end of the transaction.
- * If the timer has been created in the same transaction or
- * if there is no transaction, the cancellation is immediately effective.
- * <br />
- * If the timer is executing when the cancellation becomes effective,
- * the execution in progress will not be stopped.
- * @param timerImpl the timer to be cancelled.
- */
- public void cancel(Timer timer);
-
+ /** Cancels a timer. <br />
+ * If a transaction is in progress, the cancellation will be effective at the
+ * end of the transaction. If the timer has been created in the same
+ * transaction or if there is no transaction, the cancellation is immediately
+ * effective. <br />
+ * If the timer is executing when the cancellation becomes effective, the
+ * execution in progress will not be stopped.
+ *
+ * @param timerImpl
+ * the timer to be cancelled.
+ */
+ void cancel(Timer timer);
+
+ /** retrieve all the outstanding timers associated for the given execution */
+ List<Timer> findTimersByExecution(Execution execution);
}
Modified: jbpm4/trunk/modules/enterprise/src/main/java/org/jbpm/enterprise/internal/ejb/EjbTimerSession.java
===================================================================
--- jbpm4/trunk/modules/enterprise/src/main/java/org/jbpm/enterprise/internal/ejb/EjbTimerSession.java 2009-05-22 10:03:00 UTC (rev 4873)
+++ jbpm4/trunk/modules/enterprise/src/main/java/org/jbpm/enterprise/internal/ejb/EjbTimerSession.java 2009-05-22 14:06:47 UTC (rev 4874)
@@ -21,9 +21,12 @@
*/
package org.jbpm.enterprise.internal.ejb;
+import java.util.List;
+
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
+import org.jbpm.api.Execution;
import org.jbpm.api.JbpmException;
import org.jbpm.api.env.Environment;
import org.jbpm.api.job.Timer;
@@ -78,4 +81,8 @@
log.error("could not remove bean for timer " + timer, e);
}
}
+
+ public List<Timer> findTimersByExecution(Execution execution) {
+ return null;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java 2009-05-22 10:03:00 UTC (rev 4873)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java 2009-05-22 14:06:47 UTC (rev 4874)
@@ -30,15 +30,18 @@
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.client.ClientExecution;
import org.jbpm.api.client.ClientProcessDefinition;
+import org.jbpm.api.env.Environment;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.job.Job;
import org.jbpm.api.job.Message;
import org.jbpm.api.job.Timer;
import org.jbpm.api.session.PvmDbSession;
+import org.jbpm.api.session.TimerSession;
import org.jbpm.api.task.Task;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
import org.jbpm.pvm.internal.job.JobImpl;
+import org.jbpm.pvm.internal.job.TimerImpl;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.query.HistoryProcessInstanceQueryImpl;
import org.jbpm.pvm.internal.svc.DefaultCommandService;
@@ -246,15 +249,21 @@
}
}
- ExecutionImpl processInstance = (ExecutionImpl) findExecutionById(processInstanceId);
-
- // delete remaining tasks for this process instance
- List<TaskImpl> tasks = findTasks(processInstanceId);
- for (TaskImpl task: tasks) {
- session.delete(task);
- }
+ ExecutionImpl processInstance = (ExecutionImpl) findProcessInstanceById(processInstanceId);
+ if (processInstance!=null) {
+ // delete remaining tasks for this process instance
+ List<TaskImpl> tasks = findTasks(processInstanceId);
+ for (TaskImpl task: tasks) {
+ session.delete(task);
+ }
- if (processInstance!=null) {
+ // delete remaining jobs for this process instance
+ // TODO JBPM-
+ List<JobImpl> jobs = findJobs(processInstanceId);
+ for (JobImpl job: jobs) {
+ session.delete(job);
+ }
+
if (log.isDebugEnabled()) {
log.debug("deleting process instance "+processInstanceId);
}
@@ -322,7 +331,7 @@
}
}
- private List<TaskImpl> findTasks(String processInstanceId) {
+ List<TaskImpl> findTasks(String processInstanceId) {
Query query = session.createQuery(
"select task " +
"from "+TaskImpl.class.getName()+" as task " +
@@ -332,6 +341,16 @@
return query.list();
}
+ List<JobImpl> findJobs(String processInstanceId) {
+ Query query = session.createQuery(
+ "select job " +
+ "from "+JobImpl.class.getName()+" as job " +
+ "where job.execution.processInstance.id = :processInstanceId"
+ );
+ query.setString("processInstanceId", processInstanceId);
+ return query.list();
+ }
+
/** see if hibernate knows about the history class */
public boolean isHistoryEnabled() {
ClassMetadata historyHibernateMetadata = session.getSessionFactory().getClassMetadata(HistoryProcessInstanceImpl.class);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java 2009-05-22 10:03:00 UTC (rev 4873)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java 2009-05-22 14:06:47 UTC (rev 4874)
@@ -29,6 +29,7 @@
import org.jbpm.api.env.Transaction;
import org.jbpm.api.job.Timer;
import org.jbpm.api.model.ObservableElement;
+import org.jbpm.api.session.TimerSession;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.cal.BusinessCalendar;
import org.jbpm.pvm.internal.cal.Duration;
@@ -62,6 +63,11 @@
public TimerImpl() {
}
+
+ public void schedule() {
+ TimerSession timerSession = Environment.getFromCurrent(TimerSession.class);
+ timerSession.schedule(this);
+ }
public void setDueDateDescription(String dueDateDescription) {
Duration duration = new Duration(dueDateDescription);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java 2009-05-22 10:03:00 UTC (rev 4873)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java 2009-05-22 14:06:47 UTC (rev 4874)
@@ -13,11 +13,17 @@
**/
package org.jbpm.pvm.internal.jobexecutor;
+import java.util.List;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.jbpm.api.Execution;
import org.jbpm.api.JbpmException;
import org.jbpm.api.env.Transaction;
import org.jbpm.api.job.Timer;
import org.jbpm.api.session.TimerSession;
import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.job.TimerImpl;
/**
* Timers created with this service are committed at the end of the transaction,
@@ -37,14 +43,14 @@
JobExecutor jobExecutor;
/* injected */
- JobDbSession jobDbSession;
+ Session session;
boolean jobExecutorNotificationScheduled = false;
public void schedule(Timer timer) {
log.debug("scheduling " + timer);
validate(timer);
- jobDbSession.save(timer);
+ session.save(timer);
if ( (!jobExecutorNotificationScheduled)
&& (jobExecutor!=null)
) {
@@ -70,9 +76,19 @@
public void cancel(Timer timer) {
log.debug("canceling " + timer);
if (timer != null) {
- jobDbSession.delete(timer);
+ session.delete(timer);
} else {
throw new JbpmException("timer is null");
}
}
+
+ public List<Timer> findTimersByExecution(Execution execution) {
+ Query query = session.createQuery(
+ "select timer " +
+ "from "+TimerImpl.class.getName()+" timer " +
+ "where timer.execution = :execution"
+ );
+ query.setEntity("execution", execution);
+ return query.list();
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2009-05-22 10:03:00 UTC (rev 4873)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2009-05-22 14:06:47 UTC (rev 4874)
@@ -43,6 +43,7 @@
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;
import org.jbpm.api.model.Comment;
@@ -52,6 +53,7 @@
import org.jbpm.api.model.Transition;
import org.jbpm.api.session.MessageSession;
import org.jbpm.api.session.RepositorySession;
+import org.jbpm.api.session.TimerSession;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.hibernate.HibernatePvmDbSession;
import org.jbpm.pvm.internal.history.HistoryEvent;
@@ -271,6 +273,19 @@
return parent;
}
+
+ protected void destroyTimers(CompositeElementImpl scope) {
+ TimerSession timerSession = Environment.getFromCurrent(TimerSession.class, false);
+ if (timerSession!=null) {
+ log.debug("destroying timers of "+this);
+ List<Timer> timers = timerSession.findTimersByExecution(this);
+ for (Timer timer: timers) {
+ timerSession.cancel(timer);
+ }
+ }
+ }
+
+
// basic object methods /////////////////////////////////////////////////////
public String toString() {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2009-05-22 10:03:00 UTC (rev 4873)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2009-05-22 14:06:47 UTC (rev 4874)
@@ -22,9 +22,7 @@
package org.jbpm.pvm.internal.model;
import java.io.Serializable;
-import java.util.Date;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -34,8 +32,6 @@
import org.jbpm.api.Execution;
import org.jbpm.api.JbpmException;
import org.jbpm.api.env.Environment;
-import org.jbpm.api.job.Timer;
-import org.jbpm.api.session.TimerSession;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.job.TimerImpl;
import org.jbpm.pvm.internal.type.Converter;
@@ -59,8 +55,6 @@
protected boolean hasVariables;
protected Map<String, Variable> variables;
- protected boolean hasTimers;
- protected Set<TimerImpl> timers;
protected String state;
protected String suspendHistoryState;
@@ -267,121 +261,55 @@
// timers ///////////////////////////////////////////////////////////////////
- protected void initializeTimers(ScopeElementImpl scope) {
- // initialize the timers
- Set<TimerDefinitionImpl> timerDefinitions = scope.getTimerDefinitions();
- if (!timerDefinitions.isEmpty()) {
- timers = new HashSet<TimerImpl>();
- for (TimerDefinitionImpl timerDefinition: timerDefinitions) {
- createTimer(
- timerDefinition.getEventName(),
- timerDefinition.getSignalName(),
- timerDefinition.getDueDateDescription(),
- timerDefinition.getDueDate(),
- timerDefinition.getRepeat(),
- timerDefinition.isExclusive(),
- timerDefinition.getRetries()
- );
- }
- }
+ protected TimerImpl newTimer() {
+ return new TimerImpl();
}
-
- protected void destroyTimers(CompositeElementImpl scope) {
- log.debug("destroying timers of "+toString());
- if (hasTimers && timers!=null && !timers.isEmpty()) {
- // get the TimerSession from the environment
- Environment environment = Environment.getCurrent();
- if (environment==null) {
- throw new JbpmException("non environment for initializing timers");
- }
- TimerSession timerSession = environment.get(TimerSession.class);
- if (timerSession==null) {
- throw new JbpmException("no TimerSession in environment for initializing timers");
- }
- for (Timer timer : timers) {
- timerSession.cancel(timer);
- }
- timers.clear();
- hasTimers = false;
- }
+
+ public TimerImpl createTimer() {
+ return createTimer(null);
}
- public void createTimer(String eventName, String signalName, String dueDateDescription) {
- createTimer(eventName, signalName, dueDateDescription, null, null, null, null);
- }
-
- public void createTimer(String eventName, String signalName, String dueDateDescription, String repeat) {
- createTimer(eventName, signalName, dueDateDescription, null, repeat, null, null);
- }
-
- public void createTimer(String eventName, String signalName, String dueDateDescription, Date dueDate, String repeat, Boolean isExclusive, Integer retries) {
- if ( (eventName==null)
- && (signalName==null)
- ) {
- throw new JbpmException("no event or signal specified");
- }
+ public TimerImpl createTimer(TimerDefinitionImpl timerDefinition) {
if (log.isDebugEnabled()) {
log.debug("creating timer on "+this.toString());
}
-
- // instantiate the timer
- TimerImpl timer = instantiateTimer();
- // create the bidirectional reference
+
+ TimerImpl timer = newTimer();
timer.setExecution(getTimerExecution());
- timers.add(timer);
- hasTimers = true;
- // setInverseReference(timerImpl);
- // initialise all the timer properties
- timer.setEventName(eventName);
- timer.setSignalName(signalName);
- if (dueDate!=null) {
- timer.setDueDate(dueDate);
- } else {
- timer.setDueDateDescription(dueDateDescription);
+ if (timerDefinition!=null) {
+ timer.setEventName(timerDefinition.getEventName());
+ timer.setSignalName(timerDefinition.getSignalName());
+ timer.setDueDate(timerDefinition.getDueDate());
+ timer.setDueDateDescription(timerDefinition.getDueDateDescription());
+ Boolean isExclusive = timerDefinition.isExclusive();
+ if (isExclusive!=null) {
+ timer.setExclusive(isExclusive);
+ }
+ Integer retries = timerDefinition.getRetries();
+ if (retries!=null) {
+ timer.setRetries(retries);
+ }
+ timer.setRepeat(timerDefinition.getRepeat());
}
- // the if is added to keep the original default
- if (isExclusive!=null) {
- timer.setExclusive(isExclusive);
- }
-
- // the if is added to keep the original default
- if (retries!=null) {
- timer.setRetries(retries);
- }
+ return timer;
+ }
- // the if is added to keep the original default
- if (repeat!=null) {
- timer.setRepeat(repeat);
+ protected void initializeTimers(ScopeElementImpl scope) {
+ // initialize the timers
+ Set<TimerDefinitionImpl> timerDefinitions = scope.getTimerDefinitions();
+ if (!timerDefinitions.isEmpty()) {
+ for (TimerDefinitionImpl timerDefinition: timerDefinitions) {
+ TimerImpl timer = createTimer(timerDefinition);
+ timer.schedule();
+ }
}
-
- // get the TimerSession from the environment
- Environment environment = Environment.getCurrent();
- if (environment==null) {
- throw new JbpmException("non environment for initializing timers");
- }
- TimerSession timerSession = environment.get(TimerSession.class);
- if (timerSession==null) {
- throw new JbpmException("no TimerSession in environment for initializing timers");
- }
-
- // schedule the timer with the TimerSession
- timerSession.schedule(timer);
}
- public boolean hasTimers() {
- return hasTimers;
+ protected void destroyTimers(CompositeElementImpl scope) {
}
- public Set<Timer> getTimers() {
- return (Set) timers;
- }
-
- protected TimerImpl instantiateTimer() {
- return new TimerImpl();
- }
-
// state ////////////////////////////////////////////////////////////////////
/** @see Execution#suspend() */
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TimerSessionBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TimerSessionBinding.java 2009-05-22 10:03:00 UTC (rev 4873)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TimerSessionBinding.java 2009-05-22 14:06:47 UTC (rev 4874)
@@ -21,8 +21,8 @@
*/
package org.jbpm.pvm.internal.wire.binding;
+import org.hibernate.Session;
import org.jbpm.api.session.TimerSession;
-import org.jbpm.pvm.internal.jobexecutor.JobDbSession;
import org.jbpm.pvm.internal.jobexecutor.JobExecutor;
import org.jbpm.pvm.internal.jobexecutor.JobExecutorTimerSession;
import org.jbpm.pvm.internal.util.XmlUtil;
@@ -61,7 +61,7 @@
// inject fields
objectDescriptor.addInjection("transaction", new TransactionRefDescriptor());
objectDescriptor.addInjection("jobExecutor", new EnvDescriptor(JobExecutor.class));
- objectDescriptor.addInjection("jobDbSession", new ContextTypeRefDescriptor(JobDbSession.class));
+ objectDescriptor.addInjection("session", new ContextTypeRefDescriptor(Session.class));
}
return objectDescriptor;
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2009-05-22 10:03:00 UTC (rev 4873)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2009-05-22 14:06:47 UTC (rev 4874)
@@ -43,15 +43,6 @@
<one-to-many class="org.jbpm.pvm.internal.type.Variable" />
</map>
- <property name="hasTimers" column="HASTIMERS_" />
- <set name="timers"
- cascade="all-delete-orphan">
- <key foreign-key="FK_TMR_EXECUTION">
- <column name="EXECUTION_" />
- </key>
- <one-to-many class="org.jbpm.pvm.internal.job.TimerImpl" />
- </set>
-
<property name="name" column="NAME_" />
<property name="key" column="KEY_" />
<property name="id" column="ID_" unique="true" />
More information about the jbpm-commits
mailing list