1 package org
.argeo
.slc
.core
.execution
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
6 import org
.argeo
.slc
.process
.RealizedFlow
;
7 import org
.argeo
.slc
.process
.SlcExecutionStep
;
9 /** Thread of a single execution */
10 public class ExecutionThread
extends Thread
{
11 public final static String SYSPROP_EXECUTION_AUTO_UPGRADE
= "slc.execution.autoupgrade";
13 private final static Log log
= LogFactory
.getLog(ExecutionThread
.class);
15 private final RealizedFlow realizedFlow
;
16 private final ProcessThread processThread
;
18 public ExecutionThread(ProcessThread processThread
,
19 RealizedFlow realizedFlow
) {
20 super(processThread
.getProcessThreadGroup(), "Flow "
21 + realizedFlow
.getFlowDescriptor().getName());
22 this.realizedFlow
= realizedFlow
;
23 this.processThread
= processThread
;
27 if (getContextClassLoader() != null) {
28 if (log
.isTraceEnabled())
29 log
.debug("Context class loader set to "
30 + getContextClassLoader());
33 // Retrieve execution flow descriptor
34 ExecutionFlowDescriptor executionFlowDescriptor
= realizedFlow
36 String flowName
= executionFlowDescriptor
.getName();
38 dispatchAddStep(new SlcExecutionStep(SlcExecutionStep
.TYPE_PHASE_START
,
42 String autoUpgrade
= System
43 .getProperty(SYSPROP_EXECUTION_AUTO_UPGRADE
);
44 if (autoUpgrade
!= null && autoUpgrade
.equals("true"))
45 processThread
.getExecutionModulesManager().upgrade(
46 realizedFlow
.getModuleNameVersion());
47 processThread
.getExecutionModulesManager().execute(realizedFlow
);
48 } catch (Exception e
) {
49 // TODO: re-throw exception ?
50 String msg
= "Execution of flow " + flowName
+ " failed.";
52 dispatchAddStep(new SlcExecutionStep(msg
+ " " + e
.getMessage()));
53 processThread
.notifyError();
55 processThread
.flowCompleted();
56 dispatchAddStep(new SlcExecutionStep(
57 SlcExecutionStep
.TYPE_PHASE_END
, "Flow " + flowName
));
61 private void dispatchAddStep(SlcExecutionStep step
) {
62 processThread
.getProcessThreadGroup().dispatchAddStep(step
);