2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.core
.execution
;
19 import java
.util
.ArrayList
;
20 import java
.util
.List
;
23 import org
.apache
.commons
.logging
.Log
;
24 import org
.apache
.commons
.logging
.LogFactory
;
25 import org
.argeo
.slc
.execution
.ExecutionContext
;
26 import org
.argeo
.slc
.execution
.ExecutionFlow
;
27 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptorConverter
;
28 import org
.argeo
.slc
.execution
.ExecutionModulesListener
;
29 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
30 import org
.argeo
.slc
.process
.RealizedFlow
;
31 import org
.argeo
.slc
.process
.SlcExecution
;
32 import org
.argeo
.slc
.process
.SlcExecutionNotifier
;
34 public abstract class AbstractExecutionModulesManager
implements
35 ExecutionModulesManager
{
36 private final static Log log
= LogFactory
37 .getLog(AbstractExecutionModulesManager
.class);
39 private List
<SlcExecutionNotifier
> slcExecutionNotifiers
= new ArrayList
<SlcExecutionNotifier
>();
40 private List
<ExecutionModulesListener
> executionModulesListeners
= new ArrayList
<ExecutionModulesListener
>();
42 private ThreadGroup processesThreadGroup
= new ThreadGroup("Processes");
44 protected abstract ExecutionFlow
findExecutionFlow(String moduleName
,
45 String moduleVersion
, String flowName
);
47 protected abstract ExecutionContext
findExecutionContext(String moduleName
,
48 String moduleVersion
);
50 protected abstract ExecutionFlowDescriptorConverter
getExecutionFlowDescriptorConverter(
51 String moduleName
, String moduleVersion
);
53 public void process(SlcExecution slcExecution
) {
54 new ProcessThread(this, slcExecution
).start();
57 public void execute(RealizedFlow realizedFlow
) {
58 if (log
.isTraceEnabled())
59 log
.trace("Executing " + realizedFlow
);
61 String moduleName
= realizedFlow
.getModuleName();
62 String moduleVersion
= realizedFlow
.getModuleVersion();
64 Map
<?
extends String
, ?
extends Object
> variablesToAdd
= getExecutionFlowDescriptorConverter(
65 moduleName
, moduleVersion
).convertValues(
66 realizedFlow
.getFlowDescriptor());
67 ExecutionContext executionContext
= findExecutionContext(moduleName
,
69 for (String key
: variablesToAdd
.keySet())
70 executionContext
.setVariable(key
, variablesToAdd
.get(key
));
72 ExecutionFlow flow
= findExecutionFlow(moduleName
, moduleVersion
,
73 realizedFlow
.getFlowDescriptor().getName());
76 // Actually runs the flow, IN THIS THREAD
84 public void setSlcExecutionNotifiers(
85 List
<SlcExecutionNotifier
> slcExecutionNotifiers
) {
86 this.slcExecutionNotifiers
= slcExecutionNotifiers
;
89 public List
<SlcExecutionNotifier
> getSlcExecutionNotifiers() {
90 return slcExecutionNotifiers
;
93 public ThreadGroup
getProcessesThreadGroup() {
94 return processesThreadGroup
;
97 public List
<ExecutionModulesListener
> getExecutionModulesListeners() {
98 return executionModulesListeners
;
101 public void setExecutionModulesListeners(
102 List
<ExecutionModulesListener
> executionModulesListeners
) {
103 this.executionModulesListeners
= executionModulesListeners
;