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
.SlcExecution
;
12 import org
.argeo
.slc
.process
.SlcExecutionNotifier
;
13 import org
.argeo
.slc
.process
.SlcExecutionStep
;
15 /** Thread of a single execution */
16 public class ExecutionThread
extends Thread
{
17 private final static Log log
= LogFactory
.getLog(ExecutionThread
.class);
19 private final RealizedFlow realizedFlow
;
20 private final ProcessThread processThread
;
22 public ExecutionThread(ProcessThread processThread
,
23 RealizedFlow realizedFlow
) {
24 super(processThread
.getProcessThreadGroup(), "Flow "
25 + realizedFlow
.getFlowDescriptor().getName());
26 this.realizedFlow
= realizedFlow
;
27 this.processThread
= processThread
;
31 if (getContextClassLoader() != null) {
32 if (log
.isTraceEnabled())
33 log
.debug("Context class loader set to "
34 + getContextClassLoader());
37 // Retrieve execution flow descriptor
38 ExecutionFlowDescriptor executionFlowDescriptor
= realizedFlow
40 String flowName
= executionFlowDescriptor
.getName();
42 dispatchAddStep(processThread
.getSlcProcess(), new SlcExecutionStep(
43 SlcExecutionStep
.TYPE_PHASE_START
, "Flow " + flowName
));
46 processThread
.getExecutionModulesManager().execute(realizedFlow
);
47 } catch (Exception e
) {
48 // TODO: re-throw exception ?
49 String msg
= "Execution of flow " + flowName
+ " failed.";
51 dispatchAddStep(processThread
.getSlcProcess(),
52 new SlcExecutionStep(msg
+ " " + e
.getMessage()));
53 processThread
.notifyError();
55 processThread
.flowCompleted();
56 dispatchAddStep(processThread
.getSlcProcess(),
57 new SlcExecutionStep(SlcExecutionStep
.TYPE_PHASE_END
,
62 protected void dispatchAddStep(SlcExecution slcExecution
,
63 SlcExecutionStep step
) {
64 slcExecution
.getSteps().add(step
);
65 List
<SlcExecutionStep
> steps
= new ArrayList
<SlcExecutionStep
>();
67 for (Iterator
<SlcExecutionNotifier
> it
= processThread
68 .getExecutionModulesManager().getSlcExecutionNotifiers()
69 .iterator(); it
.hasNext();) {
70 it
.next().addSteps(slcExecution
, steps
);