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
73 // public void dispatchUpdateStatus(ExecutionProcess process,
74 // String oldStatus, String newStatus) {
75 // // filtered notifiers
76 // for (Iterator<FilteredNotifier> it = filteredNotifiers.iterator(); it
78 // FilteredNotifier filteredNotifier = it.next();
79 // if (filteredNotifier.receiveFrom(process))
80 // filteredNotifier.getNotifier().updateStatus(process, oldStatus,
86 // public void dispatchAddSteps(ExecutionProcess process,
87 // List<ExecutionStep> steps) {
88 // process.addSteps(steps);
89 // for (Iterator<FilteredNotifier> it = filteredNotifiers.iterator(); it
91 // FilteredNotifier filteredNotifier = it.next();
92 // if (filteredNotifier.receiveFrom(process))
93 // filteredNotifier.getNotifier().addSteps(process, steps);
97 // public void registerProcessNotifier(ExecutionProcessNotifier notifier,
98 // Map<String, String> properties) {
99 // filteredNotifiers.add(new FilteredNotifier(notifier, properties));
102 // public void unregisterProcessNotifier(ExecutionProcessNotifier notifier,
103 // Map<String, String> properties) {
104 // filteredNotifiers.remove(notifier);
107 // protected class FilteredNotifier {
108 // private final ExecutionProcessNotifier notifier;
109 // private final String processId;
111 // public FilteredNotifier(ExecutionProcessNotifier notifier,
112 // Map<String, String> properties) {
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);
124 // * Whether event from this process should be received by this listener.
126 // public Boolean receiveFrom(ExecutionProcess process) {
127 // if (processId != null)
128 // if (process.getUuid().equals(processId))
136 // public int hashCode() {
137 // return notifier.hashCode();
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);
152 // public ExecutionProcessNotifier getNotifier() {