2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.core
.execution
;
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
;
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);
34 // private List<FilteredNotifier> filteredNotifiers = Collections
35 // .synchronizedList(new ArrayList<FilteredNotifier>());
37 protected abstract ExecutionFlow
findExecutionFlow(String moduleName
,
38 String moduleVersion
, String flowName
);
40 protected abstract ExecutionContext
findExecutionContext(String moduleName
,
41 String moduleVersion
);
43 protected abstract ExecutionFlowDescriptorConverter
getExecutionFlowDescriptorConverter(
44 String moduleName
, String moduleVersion
);
46 public void execute(RealizedFlow realizedFlow
) {
47 if (log
.isTraceEnabled())
48 log
.trace("Executing " + realizedFlow
);
50 String moduleName
= realizedFlow
.getModuleName();
51 String moduleVersion
= realizedFlow
.getModuleVersion();
53 Map
<?
extends String
, ?
extends Object
> variablesToAdd
= getExecutionFlowDescriptorConverter(
54 moduleName
, moduleVersion
).convertValues(
55 realizedFlow
.getFlowDescriptor());
56 ExecutionContext executionContext
= findExecutionContext(moduleName
,
58 for (String key
: variablesToAdd
.keySet())
59 executionContext
.setVariable(key
, variablesToAdd
.get(key
));
61 ExecutionFlow flow
= findExecutionFlow(moduleName
, moduleVersion
,
62 realizedFlow
.getFlowDescriptor().getName());
65 // Actually runs the flow, IN THIS THREAD
67 executionContext
.beforeFlow(flow
);
71 executionContext
.afterFlow(flow
);
78 // public void dispatchUpdateStatus(ExecutionProcess process,
79 // String oldStatus, String newStatus) {
80 // // filtered notifiers
81 // for (Iterator<FilteredNotifier> it = filteredNotifiers.iterator(); it
83 // FilteredNotifier filteredNotifier = it.next();
84 // if (filteredNotifier.receiveFrom(process))
85 // filteredNotifier.getNotifier().updateStatus(process, oldStatus,
91 // public void dispatchAddSteps(ExecutionProcess process,
92 // List<ExecutionStep> steps) {
93 // process.addSteps(steps);
94 // for (Iterator<FilteredNotifier> it = filteredNotifiers.iterator(); it
96 // FilteredNotifier filteredNotifier = it.next();
97 // if (filteredNotifier.receiveFrom(process))
98 // filteredNotifier.getNotifier().addSteps(process, steps);
102 // public void registerProcessNotifier(ExecutionProcessNotifier notifier,
103 // Map<String, String> properties) {
104 // filteredNotifiers.add(new FilteredNotifier(notifier, properties));
107 // public void unregisterProcessNotifier(ExecutionProcessNotifier notifier,
108 // Map<String, String> properties) {
109 // filteredNotifiers.remove(notifier);
112 // protected class FilteredNotifier {
113 // private final ExecutionProcessNotifier notifier;
114 // private final String processId;
116 // public FilteredNotifier(ExecutionProcessNotifier notifier,
117 // Map<String, String> properties) {
119 // this.notifier = notifier;
120 // if (properties == null)
121 // properties = new HashMap<String, String>();
122 // if (properties.containsKey(SLC_PROCESS_ID))
123 // processId = properties.get(SLC_PROCESS_ID);
129 // * Whether event from this process should be received by this listener.
131 // public Boolean receiveFrom(ExecutionProcess process) {
132 // if (processId != null)
133 // if (process.getUuid().equals(processId))
141 // public int hashCode() {
142 // return notifier.hashCode();
146 // public boolean equals(Object obj) {
147 // if (obj instanceof FilteredNotifier) {
148 // FilteredNotifier fn = (FilteredNotifier) obj;
149 // return notifier.equals(fn.notifier);
150 // } else if (obj instanceof ExecutionProcessNotifier) {
151 // ExecutionProcessNotifier epn = (ExecutionProcessNotifier) obj;
152 // return notifier.equals(epn);
157 // public ExecutionProcessNotifier getNotifier() {