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