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 ExecutionFlowDescriptor executionFlowDescriptor
= realizedFlow
33 String flowName
= executionFlowDescriptor
.getName();
35 dispatchAddStep(processThread
.getSlcProcess(), new SlcExecutionStep(
36 SlcExecutionStep
.TYPE_PHASE_START
, "Flow " + flowName
));
39 processThread
.getExecutionModulesManager().execute(realizedFlow
);
40 } catch (Exception e
) {
41 // TODO: re-throw exception ?
42 String msg
= "Execution of flow " + flowName
+ " failed.";
44 dispatchAddStep(processThread
.getSlcProcess(),
45 new SlcExecutionStep(msg
+ " " + e
.getMessage()));
46 processThread
.notifyError();
48 processThread
.flowCompleted();
49 dispatchAddStep(processThread
.getSlcProcess(),
50 new SlcExecutionStep(SlcExecutionStep
.TYPE_PHASE_END
,
55 protected void dispatchAddStep(SlcExecution slcExecution
,
56 SlcExecutionStep step
) {
57 slcExecution
.getSteps().add(step
);
58 List
<SlcExecutionStep
> steps
= new ArrayList
<SlcExecutionStep
>();
60 for (Iterator
<SlcExecutionNotifier
> it
= processThread
61 .getExecutionModulesManager().getSlcExecutionNotifiers()
62 .iterator(); it
.hasNext();) {
63 it
.next().addSteps(slcExecution
, steps
);