1 package org
.argeo
.slc
.core
.execution
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Iterator
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
10 import org
.argeo
.slc
.process
.RealizedFlow
;
11 import org
.argeo
.slc
.process
.SlcExecutionNotifier
;
12 import org
.argeo
.slc
.process
.SlcExecutionStep
;
14 /** Thread of a single execution */
15 public class ExecutionThread
extends Thread
{
16 public final static String SYSPROP_EXECUTION_AUTO_UPGRADE
= "slc.execution.autoupgrade";
18 private final static Log log
= LogFactory
.getLog(ExecutionThread
.class);
20 private final RealizedFlow realizedFlow
;
21 private final ProcessThread processThread
;
23 public ExecutionThread(ProcessThread processThread
,
24 RealizedFlow realizedFlow
) {
25 super(processThread
.getProcessThreadGroup(), "Flow "
26 + realizedFlow
.getFlowDescriptor().getName());
27 this.realizedFlow
= realizedFlow
;
28 this.processThread
= processThread
;
32 if (getContextClassLoader() != null) {
33 if (log
.isTraceEnabled())
34 log
.debug("Context class loader set to "
35 + getContextClassLoader());
38 // Retrieve execution flow descriptor
39 ExecutionFlowDescriptor executionFlowDescriptor
= realizedFlow
41 String flowName
= executionFlowDescriptor
.getName();
43 dispatchAddStep(new SlcExecutionStep(SlcExecutionStep
.TYPE_PHASE_START
,
47 String autoUpgrade
= System
48 .getProperty(SYSPROP_EXECUTION_AUTO_UPGRADE
);
49 if (autoUpgrade
!= null && autoUpgrade
.equals("true"))
50 processThread
.getExecutionModulesManager().upgrade(
51 realizedFlow
.getModuleNameVersion());
52 processThread
.getExecutionModulesManager().execute(realizedFlow
);
53 } catch (Exception e
) {
54 // TODO: re-throw exception ?
55 String msg
= "Execution of flow " + flowName
+ " failed.";
57 dispatchAddStep(new SlcExecutionStep(msg
+ " " + e
.getMessage()));
58 processThread
.notifyError();
60 processThread
.flowCompleted();
61 dispatchAddStep(new SlcExecutionStep(
62 SlcExecutionStep
.TYPE_PHASE_END
, "Flow " + flowName
));
66 public void dispatchAddStep(SlcExecutionStep step
) {
67 processThread
.getSlcProcess().getSteps().add(step
);
68 List
<SlcExecutionStep
> steps
= new ArrayList
<SlcExecutionStep
>();
70 for (Iterator
<SlcExecutionNotifier
> it
= processThread
71 .getExecutionModulesManager().getSlcExecutionNotifiers()
72 .iterator(); it
.hasNext();) {
73 it
.next().addSteps(processThread
.getSlcProcess(), steps
);