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
.process
.RealizedFlow
;
31 import org
.argeo
.slc
.process
.SlcExecution
;
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 public abstract class AbstractExecutionModulesManager
implements
37 ExecutionModulesManager
{
38 private final static Log log
= LogFactory
39 .getLog(AbstractExecutionModulesManager
.class);
41 private List
<SlcExecutionNotifier
> slcExecutionNotifiers
= new ArrayList
<SlcExecutionNotifier
>();
43 private ThreadGroup processesThreadGroup
= new ThreadGroup("Processes");
45 protected abstract ExecutionFlow
findExecutionFlow(String moduleName
,
46 String moduleVersion
, String flowName
);
48 protected abstract ExecutionContext
findExecutionContext(String moduleName
,
49 String moduleVersion
);
51 protected abstract ExecutionFlowDescriptorConverter
getExecutionFlowDescriptorConverter(
52 String moduleName
, String moduleVersion
);
54 public void process(SlcExecution slcExecution
) {
55 new ProcessThread(this, slcExecution
).start();
58 public void execute(RealizedFlow realizedFlow
) {
59 if (log
.isTraceEnabled())
60 log
.trace("Executing " + realizedFlow
);
62 String moduleName
= realizedFlow
.getModuleName();
63 String moduleVersion
= realizedFlow
.getModuleVersion();
65 Map
<?
extends String
, ?
extends Object
> variablesToAdd
= getExecutionFlowDescriptorConverter(
66 moduleName
, moduleVersion
).convertValues(
67 realizedFlow
.getFlowDescriptor());
68 ExecutionContext executionContext
= findExecutionContext(moduleName
,
70 for (String key
: variablesToAdd
.keySet())
71 executionContext
.setVariable(key
, variablesToAdd
.get(key
));
73 ExecutionFlow flow
= findExecutionFlow(moduleName
, moduleVersion
,
74 realizedFlow
.getFlowDescriptor().getName());
77 // Actually runs the flow, IN THIS THREAD
85 public void dispatchUpdateStatus(SlcExecution slcExecution
,
86 String oldStatus
, String newStatus
) {
87 for (Iterator
<SlcExecutionNotifier
> it
= getSlcExecutionNotifiers()
88 .iterator(); it
.hasNext();) {
89 it
.next().updateStatus(slcExecution
, oldStatus
, newStatus
);
93 public void dispatchAddStep(SlcExecution slcExecution
, SlcExecutionStep step
) {
94 List
<SlcExecutionStep
> steps
= new ArrayList
<SlcExecutionStep
>();
96 for (Iterator
<SlcExecutionNotifier
> it
= getSlcExecutionNotifiers()
97 .iterator(); it
.hasNext();) {
98 it
.next().addSteps(slcExecution
, steps
);
102 public void setSlcExecutionNotifiers(
103 List
<SlcExecutionNotifier
> slcExecutionNotifiers
) {
104 this.slcExecutionNotifiers
= slcExecutionNotifiers
;
107 public List
<SlcExecutionNotifier
> getSlcExecutionNotifiers() {
108 return slcExecutionNotifiers
;
111 public ThreadGroup
getProcessesThreadGroup() {
112 return processesThreadGroup
;