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