]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java
Introduce SLC RCP
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / AbstractExecutionModulesManager.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.core.execution;
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.argeo.slc.execution.ExecutionContext;
26 import org.argeo.slc.execution.ExecutionFlow;
27 import org.argeo.slc.execution.ExecutionFlowDescriptorConverter;
28 import org.argeo.slc.execution.ExecutionModulesListener;
29 import org.argeo.slc.execution.ExecutionModulesManager;
30 import org.argeo.slc.process.RealizedFlow;
31 import org.argeo.slc.process.SlcExecution;
32 import org.argeo.slc.process.SlcExecutionNotifier;
33
34 public abstract class AbstractExecutionModulesManager implements
35 ExecutionModulesManager {
36 private final static Log log = LogFactory
37 .getLog(AbstractExecutionModulesManager.class);
38
39 private List<SlcExecutionNotifier> slcExecutionNotifiers = new ArrayList<SlcExecutionNotifier>();
40 private List<ExecutionModulesListener> executionModulesListeners = new ArrayList<ExecutionModulesListener>();
41
42 private ThreadGroup processesThreadGroup = new ThreadGroup("Processes");
43
44 protected abstract ExecutionFlow findExecutionFlow(String moduleName,
45 String moduleVersion, String flowName);
46
47 protected abstract ExecutionContext findExecutionContext(String moduleName,
48 String moduleVersion);
49
50 protected abstract ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter(
51 String moduleName, String moduleVersion);
52
53 public void process(SlcExecution slcExecution) {
54 new ProcessThread(this, slcExecution).start();
55 }
56
57 public void execute(RealizedFlow realizedFlow) {
58 if (log.isTraceEnabled())
59 log.trace("Executing " + realizedFlow);
60
61 String moduleName = realizedFlow.getModuleName();
62 String moduleVersion = realizedFlow.getModuleVersion();
63
64 Map<? extends String, ? extends Object> variablesToAdd = getExecutionFlowDescriptorConverter(
65 moduleName, moduleVersion).convertValues(
66 realizedFlow.getFlowDescriptor());
67 ExecutionContext executionContext = findExecutionContext(moduleName,
68 moduleVersion);
69 for (String key : variablesToAdd.keySet())
70 executionContext.setVariable(key, variablesToAdd.get(key));
71
72 ExecutionFlow flow = findExecutionFlow(moduleName, moduleVersion,
73 realizedFlow.getFlowDescriptor().getName());
74
75 //
76 // Actually runs the flow, IN THIS THREAD
77 //
78 flow.run();
79 //
80 //
81 //
82 }
83
84 public void setSlcExecutionNotifiers(
85 List<SlcExecutionNotifier> slcExecutionNotifiers) {
86 this.slcExecutionNotifiers = slcExecutionNotifiers;
87 }
88
89 public List<SlcExecutionNotifier> getSlcExecutionNotifiers() {
90 return slcExecutionNotifiers;
91 }
92
93 public ThreadGroup getProcessesThreadGroup() {
94 return processesThreadGroup;
95 }
96
97 public List<ExecutionModulesListener> getExecutionModulesListeners() {
98 return executionModulesListeners;
99 }
100
101 public void setExecutionModulesListeners(
102 List<ExecutionModulesListener> executionModulesListeners) {
103 this.executionModulesListeners = executionModulesListeners;
104 }
105
106 }