]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java
FlowNamespace extended (flows in flows, param in arg)
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / AbstractExecutionModulesManager.java
1 package org.argeo.slc.core.execution;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Map;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.argeo.slc.execution.ExecutionContext;
10 import org.argeo.slc.execution.ExecutionFlow;
11 import org.argeo.slc.execution.ExecutionFlowDescriptorConverter;
12 import org.argeo.slc.execution.ExecutionModulesListener;
13 import org.argeo.slc.execution.ExecutionModulesManager;
14 import org.argeo.slc.process.RealizedFlow;
15 import org.argeo.slc.process.SlcExecution;
16 import org.argeo.slc.process.SlcExecutionNotifier;
17
18 public abstract class AbstractExecutionModulesManager implements
19 ExecutionModulesManager {
20 private final static Log log = LogFactory
21 .getLog(AbstractExecutionModulesManager.class);
22
23 private List<SlcExecutionNotifier> slcExecutionNotifiers = new ArrayList<SlcExecutionNotifier>();
24 private List<ExecutionModulesListener> executionModulesListeners = new ArrayList<ExecutionModulesListener>();
25
26 private ThreadGroup processesThreadGroup = new ThreadGroup("Processes");
27
28 protected abstract ExecutionFlow findExecutionFlow(String moduleName,
29 String moduleVersion, String flowName);
30
31 protected abstract ExecutionContext findExecutionContext(String moduleName,
32 String moduleVersion);
33
34 protected abstract ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter(
35 String moduleName, String moduleVersion);
36
37 public void process(SlcExecution slcExecution) {
38 new ProcessThread(this, slcExecution).start();
39 }
40
41 public void execute(RealizedFlow realizedFlow) {
42 if (log.isTraceEnabled())
43 log.trace("Executing " + realizedFlow);
44
45 String moduleName = realizedFlow.getModuleName();
46 String moduleVersion = realizedFlow.getModuleVersion();
47
48 Map<? extends String, ? extends Object> variablesToAdd = getExecutionFlowDescriptorConverter(
49 moduleName, moduleVersion).convertValues(
50 realizedFlow.getFlowDescriptor());
51 ExecutionContext executionContext = findExecutionContext(moduleName,
52 moduleVersion);
53 for (String key : variablesToAdd.keySet())
54 executionContext.setVariable(key, variablesToAdd.get(key));
55
56 ExecutionFlow flow = findExecutionFlow(moduleName, moduleVersion,
57 realizedFlow.getFlowDescriptor().getName());
58
59 //
60 // Actually runs the flow, IN THIS THREAD
61 //
62 flow.run();
63 //
64 //
65 //
66 }
67
68 public void setSlcExecutionNotifiers(
69 List<SlcExecutionNotifier> slcExecutionNotifiers) {
70 this.slcExecutionNotifiers = slcExecutionNotifiers;
71 }
72
73 public List<SlcExecutionNotifier> getSlcExecutionNotifiers() {
74 return slcExecutionNotifiers;
75 }
76
77 public ThreadGroup getProcessesThreadGroup() {
78 return processesThreadGroup;
79 }
80
81 public List<ExecutionModulesListener> getExecutionModulesListeners() {
82 return executionModulesListeners;
83 }
84
85 public void setExecutionModulesListeners(
86 List<ExecutionModulesListener> executionModulesListeners) {
87 this.executionModulesListeners = executionModulesListeners;
88 }
89
90 }