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 org
.apache
.commons
.logging
.Log
;
20 import org
.apache
.commons
.logging
.LogFactory
;
21 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
22 import org
.argeo
.slc
.process
.RealizedFlow
;
23 import org
.argeo
.slc
.process
.SlcExecutionStep
;
25 /** Thread of a single execution */
26 public class ExecutionThread
extends Thread
{
27 public final static String SYSPROP_EXECUTION_AUTO_UPGRADE
= "slc.execution.autoupgrade";
29 private final static Log log
= LogFactory
.getLog(ExecutionThread
.class);
31 private final RealizedFlow realizedFlow
;
32 private final ProcessThread processThread
;
34 public ExecutionThread(ProcessThread processThread
,
35 RealizedFlow realizedFlow
) {
36 super(processThread
.getProcessThreadGroup(), "Flow "
37 + realizedFlow
.getFlowDescriptor().getName());
38 this.realizedFlow
= realizedFlow
;
39 this.processThread
= processThread
;
43 if (getContextClassLoader() != null) {
44 if (log
.isTraceEnabled())
45 log
.debug("Context class loader set to "
46 + getContextClassLoader());
49 // Retrieve execution flow descriptor
50 ExecutionFlowDescriptor executionFlowDescriptor
= realizedFlow
52 String flowName
= executionFlowDescriptor
.getName();
54 dispatchAddStep(new SlcExecutionStep(SlcExecutionStep
.PHASE_START
,
58 String autoUpgrade
= System
59 .getProperty(SYSPROP_EXECUTION_AUTO_UPGRADE
);
60 if (autoUpgrade
!= null && autoUpgrade
.equals("true"))
61 processThread
.getExecutionModulesManager().upgrade(
62 realizedFlow
.getModuleNameVersion());
63 processThread
.getExecutionModulesManager().execute(realizedFlow
);
64 } catch (Exception e
) {
65 // TODO: re-throw exception ?
66 String msg
= "Execution of flow " + flowName
+ " failed.";
68 dispatchAddStep(new SlcExecutionStep(SlcExecutionStep
.ERROR
, msg
69 + " " + e
.getMessage()));
70 processThread
.notifyError();
72 processThread
.flowCompleted();
73 dispatchAddStep(new SlcExecutionStep(SlcExecutionStep
.PHASE_END
,
78 private void dispatchAddStep(SlcExecutionStep step
) {
79 processThread
.getProcessThreadGroup().dispatchAddStep(step
);