]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java
Remove unnecessary check causing failures
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / AbstractExecutionModulesManager.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
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 package org.argeo.slc.core.execution;
17
18 import java.util.Map;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.argeo.slc.execution.ExecutionContext;
23 import org.argeo.slc.execution.ExecutionFlow;
24 import org.argeo.slc.execution.ExecutionFlowDescriptorConverter;
25 import org.argeo.slc.execution.ExecutionModulesManager;
26 import org.argeo.slc.execution.RealizedFlow;
27
28 /** Provides the base feature of an execution module manager. */
29 public abstract class AbstractExecutionModulesManager implements
30 ExecutionModulesManager {
31 private final static Log log = LogFactory
32 .getLog(AbstractExecutionModulesManager.class);
33
34 // private List<FilteredNotifier> filteredNotifiers = Collections
35 // .synchronizedList(new ArrayList<FilteredNotifier>());
36
37 protected abstract ExecutionFlow findExecutionFlow(String moduleName,
38 String moduleVersion, String flowName);
39
40 protected abstract ExecutionContext findExecutionContext(String moduleName,
41 String moduleVersion);
42
43 protected abstract ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter(
44 String moduleName, String moduleVersion);
45
46 public void execute(RealizedFlow realizedFlow) {
47 if (log.isTraceEnabled())
48 log.trace("Executing " + realizedFlow);
49
50 String moduleName = realizedFlow.getModuleName();
51 String moduleVersion = realizedFlow.getModuleVersion();
52
53 Map<? extends String, ? extends Object> variablesToAdd = getExecutionFlowDescriptorConverter(
54 moduleName, moduleVersion).convertValues(
55 realizedFlow.getFlowDescriptor());
56 ExecutionContext executionContext = findExecutionContext(moduleName,
57 moduleVersion);
58 for (String key : variablesToAdd.keySet())
59 executionContext.setVariable(key, variablesToAdd.get(key));
60
61 ExecutionFlow flow = findExecutionFlow(moduleName, moduleVersion,
62 realizedFlow.getFlowDescriptor().getName());
63
64 //
65 // Actually runs the flow, IN THIS THREAD
66 //
67 flow.run();
68 //
69 //
70 //
71 }
72
73 // public void dispatchUpdateStatus(ExecutionProcess process,
74 // String oldStatus, String newStatus) {
75 // // filtered notifiers
76 // for (Iterator<FilteredNotifier> it = filteredNotifiers.iterator(); it
77 // .hasNext();) {
78 // FilteredNotifier filteredNotifier = it.next();
79 // if (filteredNotifier.receiveFrom(process))
80 // filteredNotifier.getNotifier().updateStatus(process, oldStatus,
81 // newStatus);
82 // }
83 //
84 // }
85
86 // public void dispatchAddSteps(ExecutionProcess process,
87 // List<ExecutionStep> steps) {
88 // process.addSteps(steps);
89 // for (Iterator<FilteredNotifier> it = filteredNotifiers.iterator(); it
90 // .hasNext();) {
91 // FilteredNotifier filteredNotifier = it.next();
92 // if (filteredNotifier.receiveFrom(process))
93 // filteredNotifier.getNotifier().addSteps(process, steps);
94 // }
95 // }
96
97 // public void registerProcessNotifier(ExecutionProcessNotifier notifier,
98 // Map<String, String> properties) {
99 // filteredNotifiers.add(new FilteredNotifier(notifier, properties));
100 // }
101 //
102 // public void unregisterProcessNotifier(ExecutionProcessNotifier notifier,
103 // Map<String, String> properties) {
104 // filteredNotifiers.remove(notifier);
105 // }
106
107 // protected class FilteredNotifier {
108 // private final ExecutionProcessNotifier notifier;
109 // private final String processId;
110 //
111 // public FilteredNotifier(ExecutionProcessNotifier notifier,
112 // Map<String, String> properties) {
113 // super();
114 // this.notifier = notifier;
115 // if (properties == null)
116 // properties = new HashMap<String, String>();
117 // if (properties.containsKey(SLC_PROCESS_ID))
118 // processId = properties.get(SLC_PROCESS_ID);
119 // else
120 // processId = null;
121 // }
122 //
123 // /**
124 // * Whether event from this process should be received by this listener.
125 // */
126 // public Boolean receiveFrom(ExecutionProcess process) {
127 // if (processId != null)
128 // if (process.getUuid().equals(processId))
129 // return true;
130 // else
131 // return false;
132 // return true;
133 // }
134 //
135 // @Override
136 // public int hashCode() {
137 // return notifier.hashCode();
138 // }
139 //
140 // @Override
141 // public boolean equals(Object obj) {
142 // if (obj instanceof FilteredNotifier) {
143 // FilteredNotifier fn = (FilteredNotifier) obj;
144 // return notifier.equals(fn.notifier);
145 // } else if (obj instanceof ExecutionProcessNotifier) {
146 // ExecutionProcessNotifier epn = (ExecutionProcessNotifier) obj;
147 // return notifier.equals(epn);
148 // } else
149 // return false;
150 // }
151 //
152 // public ExecutionProcessNotifier getNotifier() {
153 // return notifier;
154 // }
155 //
156 // }
157 }