Author: tom.baeyens(a)jboss.com
Date: 2009-05-25 10:15:29 -0400 (Mon, 25 May 2009)
New Revision: 4886
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/CommandMessage.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.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/model/ExecutionImpl.java
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
Log:
JBPM-2277 job configuration and execution state persistence refactoring
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/CommandMessage.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/CommandMessage.java 2009-05-25
13:34:43 UTC (rev 4885)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/CommandMessage.java 2009-05-25
14:15:29 UTC (rev 4886)
@@ -21,11 +21,11 @@
*/
package org.jbpm.pvm.internal.job;
+import org.jbpm.api.JbpmException;
import org.jbpm.api.cmd.Command;
import org.jbpm.api.env.Environment;
import org.jbpm.pvm.internal.jobexecutor.JobDbSession;
import org.jbpm.pvm.internal.wire.Descriptor;
-import org.jbpm.pvm.internal.wire.WireContext;
/**
@@ -39,11 +39,15 @@
}
public CommandMessage(Descriptor commandDescriptor) {
- this.commandDescriptor = commandDescriptor;
+ throw new JbpmException("obsolete");
}
+ public CommandMessage(Command<?> command) {
+ setConfiguration(command);
+ }
+
public Object execute(Environment environment) throws Exception {
- Command<Object> command = (Command<Object>)
WireContext.create(commandDescriptor);
+ Command<?> command = (Command<?>) getConfiguration();
command.execute(environment);
JobDbSession jobDbSession = environment.get(JobDbSession.class);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java 2009-05-25
13:34:43 UTC (rev 4885)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java 2009-05-25
14:15:29 UTC (rev 4886)
@@ -1,10 +1,16 @@
package org.jbpm.pvm.internal.job;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Date;
+import org.jbpm.api.JbpmException;
import org.jbpm.api.cmd.Command;
import org.jbpm.api.job.Job;
+import org.jbpm.pvm.internal.lob.Lob;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.wire.Descriptor;
@@ -26,7 +32,7 @@
protected Date dueDate = null;
/** job state. */
- protected String state;
+ protected String state = STATE_WAITING;
/** the execution (if any) for this jobImpl */
protected ExecutionImpl execution;
@@ -56,6 +62,10 @@
* occurs during command execution. */
protected int retries = 3;
+ protected Lob configurationBytes;
+
+ protected Object configuration;
+
/** a command that can be used as the behaviour of this job */
protected Descriptor commandDescriptor;
@@ -87,10 +97,45 @@
this.state = STATE_SUSPENDED;
}
public void resume() {
- this.state = STATE_WAITING;
+ if (retries==0) {
+ this.state = STATE_ERROR;
+ } else {
+ this.state = STATE_WAITING;
+ }
}
-
+ public Object getConfiguration() {
+ if ( (configuration==null)
+ && (configurationBytes!=null)
+ ) {
+ try {
+ byte[] bytes = configurationBytes.extractBytes();
+ ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
+ ObjectInputStream objectStream = new ObjectInputStream(byteStream);
+ configuration = objectStream.readObject();
+ } catch (Exception e) {
+ throw new JbpmException("couldn't deserialize configuration object for
"+this, e);
+ }
+ }
+ return configuration;
+ }
+
+ public void setConfiguration(Object configuration) {
+ this.configuration = configuration;
+
+ try {
+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectStream = new ObjectOutputStream(byteStream);
+ objectStream.writeObject(configuration);
+ byte[] bytes = byteStream.toByteArray();
+ configurationBytes = new Lob(bytes);
+ } catch (Exception e) {
+ throw new JbpmException("couldn't serialize configuration object for
"+this, e);
+ }
+ }
+
+ // getters and setters //////////////////////////////////////////////////////
+
public long getDbid() {
return dbid;
}
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-25
13:34:43 UTC (rev 4885)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java 2009-05-25
14:15:29 UTC (rev 4886)
@@ -123,7 +123,7 @@
boolean deleteThisJob = true;
// if there is no repeat on this timer
if (repeat==null) {
- // delete the jobImpl
+ // delete the job
if (log.isDebugEnabled()) log.debug("deleting " + this);
JobDbSession dbSession = environment.get(JobDbSession.class);
if (dbSession==null) {
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-25
13:34:43 UTC (rev 4885)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2009-05-25
14:15:29 UTC (rev 4886)
@@ -111,13 +111,6 @@
/** a unique id for this execution. */
protected String id;
- protected String processDefinitionId;
- private ProcessDefinitionImpl processDefinition;
-
- /** current activity */
- protected String activityName;
- private ActivityImpl activity;
-
/** are concurrent executions that related to this execution. */
protected Collection<ExecutionImpl> executions;
@@ -142,20 +135,38 @@
protected Date historyActivityStart;
protected int priority = Priority.NORMAL;
+
+ // persistent indicators of the current position ////////////////////////////
- // transient member fields //////////////////////////////////////////////////
+ /** persistent process definition reference */
+ protected String processDefinitionId;
+
+ /** 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} */
+ protected ProcessDefinitionImpl processDefinition;
+
+ /** transient cached current activity pointer. persistence is managed in {@link
#activityName} */
+ private ActivityImpl activity;
+
/** transition is not to be made persistable by default */
protected TransitionImpl transition;
- protected Integer transitionSourceIndex;
/** 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 String transitionSourceName;
protected EventImpl event;
+
protected ObservableElementImpl eventSource;
+
+ // cached named executions //////////////////////////////////////////////////
/** caches the child executions by execution name. This member might be
* null and is only created from the executions in case its needed. Note
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-25 13:34:43
UTC (rev 4885)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2009-05-25 14:15:29
UTC (rev 4886)
@@ -216,6 +216,7 @@
cascade="none"
foreign-key="FK_JOB_PRINST"
index="IDX_JOB_PRINST"/>
+
<many-to-one name="execution"
class="org.jbpm.pvm.internal.model.ExecutionImpl"
column="EXECUTION_"
@@ -223,12 +224,12 @@
foreign-key="FK_JOB_EXE"
index="IDX_JOB_EXE"/>
- <!-- many-to-one name="commandDescriptor"
- column="CMDDESCR_"
-
class="org.jbpm.pvm.internal.wire.descriptor.AbstractDescriptor"
+ <many-to-one name="configurationBytes"
+ column="CFG_"
cascade="all"
- foreign-key="FK_JOB_CMDDESCR"
- index="IDX_JOB_CMDDESCR"/ -->
+ class="org.jbpm.pvm.internal.lob.Lob"
+ foreign-key="FK_JOB_CFG"
+ index="IDX_JOB_CFG" />
<subclass name="org.jbpm.pvm.internal.job.MessageImpl"
discriminator-value="Msg">
<subclass name="org.jbpm.pvm.internal.model.op.ExecuteActivityMessage"
discriminator-value="ExeAct" />