]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java
Improve JCR integration
[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.Iterator;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.argeo.slc.execution.ExecutionContext;
27 import org.argeo.slc.execution.ExecutionFlow;
28 import org.argeo.slc.execution.ExecutionFlowDescriptorConverter;
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 import org.argeo.slc.process.SlcExecutionStep;
34
35 /** Provides the base feature of an execution module manager. */
36 public abstract class AbstractExecutionModulesManager implements
37 ExecutionModulesManager {
38 private final static Log log = LogFactory
39 .getLog(AbstractExecutionModulesManager.class);
40
41 private List<SlcExecutionNotifier> slcExecutionNotifiers = new ArrayList<SlcExecutionNotifier>();
42
43 private ThreadGroup processesThreadGroup = new ThreadGroup("Processes");
44
45 protected abstract ExecutionFlow findExecutionFlow(String moduleName,
46 String moduleVersion, String flowName);
47
48 protected abstract ExecutionContext findExecutionContext(String moduleName,
49 String moduleVersion);
50
51 protected abstract ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter(
52 String moduleName, String moduleVersion);
53
54 public void process(SlcExecution slcExecution) {
55 new ProcessThread(this, slcExecution).start();
56 }
57
58 public void execute(RealizedFlow realizedFlow) {
59 if (log.isTraceEnabled())
60 log.trace("Executing " + realizedFlow);
61
62 String moduleName = realizedFlow.getModuleName();
63 String moduleVersion = realizedFlow.getModuleVersion();
64
65 Map<? extends String, ? extends Object> variablesToAdd = getExecutionFlowDescriptorConverter(
66 moduleName, moduleVersion).convertValues(
67 realizedFlow.getFlowDescriptor());
68 ExecutionContext executionContext = findExecutionContext(moduleName,
69 moduleVersion);
70 for (String key : variablesToAdd.keySet())
71 executionContext.setVariable(key, variablesToAdd.get(key));
72
73 ExecutionFlow flow = findExecutionFlow(moduleName, moduleVersion,
74 realizedFlow.getFlowDescriptor().getName());
75
76 //
77 // Actually runs the flow, IN THIS THREAD
78 //
79 flow.run();
80 //
81 //
82 //
83 }
84
85 public void dispatchUpdateStatus(SlcExecution slcExecution,
86 String oldStatus, String newStatus) {
87 for (Iterator<SlcExecutionNotifier> it = getSlcExecutionNotifiers()
88 .iterator(); it.hasNext();) {
89 it.next().updateStatus(slcExecution, oldStatus, newStatus);
90 }
91 }
92
93 public void dispatchAddStep(SlcExecution slcExecution, SlcExecutionStep step) {
94 List<SlcExecutionStep> steps = new ArrayList<SlcExecutionStep>();
95 steps.add(step);
96 for (Iterator<SlcExecutionNotifier> it = getSlcExecutionNotifiers()
97 .iterator(); it.hasNext();) {
98 it.next().addSteps(slcExecution, steps);
99 }
100 }
101
102 public void setSlcExecutionNotifiers(
103 List<SlcExecutionNotifier> slcExecutionNotifiers) {
104 this.slcExecutionNotifiers = slcExecutionNotifiers;
105 }
106
107 public List<SlcExecutionNotifier> getSlcExecutionNotifiers() {
108 return slcExecutionNotifiers;
109 }
110
111 public ThreadGroup getProcessesThreadGroup() {
112 return processesThreadGroup;
113 }
114
115 }