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
;
23 import org
.apache
.commons
.logging
.Log
;
24 import org
.apache
.commons
.logging
.LogFactory
;
25 import org
.argeo
.slc
.process
.RealizedFlow
;
26 import org
.argeo
.slc
.process
.SlcExecution
;
27 import org
.argeo
.slc
.process
.SlcExecutionNotifier
;
29 /** Thread of the SLC Process, starting the sub executions. */
30 public class ProcessThread
extends Thread
{
31 private final static Log log
= LogFactory
.getLog(ProcessThread
.class);
33 private final AbstractExecutionModulesManager executionModulesManager
;
34 private final SlcExecution slcProcess
;
35 private final ProcessThreadGroup processThreadGroup
;
36 private final List
<RealizedFlow
> flowsToProcess
= new ArrayList
<RealizedFlow
>();
38 private Boolean hadAnError
= false;
41 AbstractExecutionModulesManager executionModulesManager
,
42 SlcExecution slcExecution
) {
43 super(executionModulesManager
.getProcessesThreadGroup(),
44 "SLC Process #" + slcExecution
.getUuid());
45 this.executionModulesManager
= executionModulesManager
;
46 this.slcProcess
= slcExecution
;
47 processThreadGroup
= new ProcessThreadGroup(this);
51 log
.info("\n##\n## Process SLC Execution " + slcProcess
+ "\n##\n");
53 slcProcess
.setStatus(SlcExecution
.STATUS_RUNNING
);
54 dispatchUpdateStatus(slcProcess
, SlcExecution
.STATUS_SCHEDULED
,
55 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
);
67 } catch (InterruptedException e
) {
74 slcProcess
.setStatus(SlcExecution
.STATUS_ERROR
);
76 slcProcess
.setStatus(SlcExecution
.STATUS_FINISHED
);
77 dispatchUpdateStatus(slcProcess
, SlcExecution
.STATUS_RUNNING
,
78 slcProcess
.getStatus());
81 protected void dispatchUpdateStatus(SlcExecution slcExecution
,
82 String oldStatus
, String newStatus
) {
83 for (Iterator
<SlcExecutionNotifier
> it
= executionModulesManager
84 .getSlcExecutionNotifiers().iterator(); it
.hasNext();) {
85 it
.next().updateStatus(slcExecution
, oldStatus
, newStatus
);
89 public void notifyError() {
93 public synchronized void flowCompleted() {
97 public SlcExecution
getSlcProcess() {
101 public ProcessThreadGroup
getProcessThreadGroup() {
102 return processThreadGroup
;
105 public AbstractExecutionModulesManager
getExecutionModulesManager() {
106 return executionModulesManager
;