]> git.argeo.org Git - gpl/argeo-slc.git/blob - ExecutionThread.java
db289b4a5c6bf878788e9ea5ff7d6a8fa7d566c2
[gpl/argeo-slc.git] / ExecutionThread.java
1 package org.argeo.slc.core.execution;
2
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;
8
9 /** Thread of a single execution */
10 public class ExecutionThread extends Thread {
11 public final static String SYSPROP_EXECUTION_AUTO_UPGRADE = "slc.execution.autoupgrade";
12
13 private final static Log log = LogFactory.getLog(ExecutionThread.class);
14
15 private final RealizedFlow realizedFlow;
16 private final ProcessThread processThread;
17
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;
24 }
25
26 public void run() {
27 if (getContextClassLoader() != null) {
28 if (log.isTraceEnabled())
29 log.debug("Context class loader set to "
30 + getContextClassLoader());
31 }
32
33 // Retrieve execution flow descriptor
34 ExecutionFlowDescriptor executionFlowDescriptor = realizedFlow
35 .getFlowDescriptor();
36 String flowName = executionFlowDescriptor.getName();
37
38 dispatchAddStep(new SlcExecutionStep(SlcExecutionStep.TYPE_PHASE_START,
39 "Flow " + flowName));
40
41 try {
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.";
51 log.error(msg, e);
52 dispatchAddStep(new SlcExecutionStep(msg + " " + e.getMessage()));
53 processThread.notifyError();
54 } finally {
55 processThread.flowCompleted();
56 dispatchAddStep(new SlcExecutionStep(
57 SlcExecutionStep.TYPE_PHASE_END, "Flow " + flowName));
58 }
59 }
60
61 private void dispatchAddStep(SlcExecutionStep step) {
62 processThread.getProcessThreadGroup().dispatchAddStep(step);
63 }
64
65 }