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
.Iterator
;
21 import java
.util
.List
;
24 import org
.apache
.commons
.logging
.Log
;
25 import org
.apache
.commons
.logging
.LogFactory
;
26 import org
.argeo
.slc
.execution
.ExecutionContext
;
27 import org
.argeo
.slc
.execution
.ExecutionFlow
;
28 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptorConverter
;
29 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
30 import org
.argeo
.slc
.execution
.ExecutionProcess
;
31 import org
.argeo
.slc
.process
.RealizedFlow
;
32 import org
.argeo
.slc
.process
.SlcExecutionNotifier
;
33 import org
.argeo
.slc
.process
.SlcExecutionStep
;
35 /** Provides the base feature of an execution module manager. */
36 @SuppressWarnings("deprecation")
37 public abstract class AbstractExecutionModulesManager
implements
38 ExecutionModulesManager
{
39 private final static Log log
= LogFactory
40 .getLog(AbstractExecutionModulesManager
.class);
42 private List
<SlcExecutionNotifier
> slcExecutionNotifiers
= new ArrayList
<SlcExecutionNotifier
>();
44 private ThreadGroup processesThreadGroup
= new ThreadGroup("Processes");
46 protected abstract ExecutionFlow
findExecutionFlow(String moduleName
,
47 String moduleVersion
, String flowName
);
49 protected abstract ExecutionContext
findExecutionContext(String moduleName
,
50 String moduleVersion
);
52 protected abstract ExecutionFlowDescriptorConverter
getExecutionFlowDescriptorConverter(
53 String moduleName
, String moduleVersion
);
55 public void execute(RealizedFlow realizedFlow
) {
56 if (log
.isTraceEnabled())
57 log
.trace("Executing " + realizedFlow
);
59 String moduleName
= realizedFlow
.getModuleName();
60 String moduleVersion
= realizedFlow
.getModuleVersion();
62 Map
<?
extends String
, ?
extends Object
> variablesToAdd
= getExecutionFlowDescriptorConverter(
63 moduleName
, moduleVersion
).convertValues(
64 realizedFlow
.getFlowDescriptor());
65 ExecutionContext executionContext
= findExecutionContext(moduleName
,
67 for (String key
: variablesToAdd
.keySet())
68 executionContext
.setVariable(key
, variablesToAdd
.get(key
));
70 ExecutionFlow flow
= findExecutionFlow(moduleName
, moduleVersion
,
71 realizedFlow
.getFlowDescriptor().getName());
74 // Actually runs the flow, IN THIS THREAD
82 public void dispatchUpdateStatus(ExecutionProcess slcExecution
,
83 String oldStatus
, String newStatus
) {
84 for (Iterator
<SlcExecutionNotifier
> it
= getSlcExecutionNotifiers()
85 .iterator(); it
.hasNext();) {
86 it
.next().updateStatus(slcExecution
, oldStatus
, newStatus
);
90 public void dispatchAddStep(ExecutionProcess slcExecution
,
91 SlcExecutionStep step
) {
92 List
<SlcExecutionStep
> steps
= new ArrayList
<SlcExecutionStep
>();
94 for (Iterator
<SlcExecutionNotifier
> it
= getSlcExecutionNotifiers()
95 .iterator(); it
.hasNext();) {
96 it
.next().addSteps(slcExecution
, steps
);
100 public void setSlcExecutionNotifiers(
101 List
<SlcExecutionNotifier
> slcExecutionNotifiers
) {
102 this.slcExecutionNotifiers
= slcExecutionNotifiers
;
105 public List
<SlcExecutionNotifier
> getSlcExecutionNotifiers() {
106 return slcExecutionNotifiers
;
109 public ThreadGroup
getProcessesThreadGroup() {
110 return processesThreadGroup
;