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
;
22 import org
.apache
.commons
.logging
.Log
;
23 import org
.apache
.commons
.logging
.LogFactory
;
24 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
25 import org
.argeo
.slc
.process
.RealizedFlow
;
26 import org
.argeo
.slc
.process
.SlcExecution
;
28 /** Thread of the SLC Process, starting the sub executions. */
29 public class ProcessThread
extends Thread
{
30 private final static Log log
= LogFactory
.getLog(ProcessThread
.class);
32 private final ExecutionModulesManager executionModulesManager
;
33 private final SlcExecution slcProcess
;
34 private final ProcessThreadGroup processThreadGroup
;
35 private final List
<RealizedFlow
> flowsToProcess
= new ArrayList
<RealizedFlow
>();
37 private Boolean hadAnError
= false;
39 public ProcessThread(ExecutionModulesManager executionModulesManager
,
40 SlcExecution slcExecution
) {
41 super(executionModulesManager
.getProcessesThreadGroup(),
42 "SLC Process #" + slcExecution
.getUuid());
43 this.executionModulesManager
= executionModulesManager
;
44 this.slcProcess
= slcExecution
;
45 processThreadGroup
= new ProcessThreadGroup(executionModulesManager
,
50 log
.info("\n##\n## SLC Process #" + slcProcess
.getUuid()
53 slcProcess
.setStatus(SlcExecution
.STATUS_RUNNING
);
54 executionModulesManager
.dispatchUpdateStatus(slcProcess
,
55 SlcExecution
.STATUS_SCHEDULED
, SlcExecution
.STATUS_RUNNING
);
57 flowsToProcess
.addAll(slcProcess
.getRealizedFlows());
59 while (flowsToProcess
.size() > 0) {
60 RealizedFlow flow
= flowsToProcess
.remove(0);
61 ExecutionThread thread
= new ExecutionThread(this, flow
);
66 } catch (InterruptedException e
) {
67 log
.error("Flow " + flow
+ " was interrupted", e
);
70 // synchronized (this) {
73 // } catch (InterruptedException e) {
79 // TODO: error management at flow level?
81 slcProcess
.setStatus(SlcExecution
.STATUS_ERROR
);
83 slcProcess
.setStatus(SlcExecution
.STATUS_FINISHED
);
84 executionModulesManager
.dispatchUpdateStatus(slcProcess
,
85 SlcExecution
.STATUS_RUNNING
, slcProcess
.getStatus());
87 log
.info("\n## SLC Process #" + slcProcess
.getUuid() + " COMPLETED\n");
90 public void notifyError() {
94 public synchronized void flowCompleted() {
98 public SlcExecution
getSlcProcess() {
102 public ProcessThreadGroup
getProcessThreadGroup() {
103 return processThreadGroup
;
106 public ExecutionModulesManager
getExecutionModulesManager() {
107 return executionModulesManager
;