X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2FProcessThread.java;h=5af3262d57cb4923a76ce2e6a738154876ff12aa;hb=f3e477b3048c639451df616cfa61564eae11efbb;hp=1987f259e9ef8c84d997f6ada6a0a0f0283cc638;hpb=17ffc9fdb8f3a490881e540db8ff81655308233e;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java index 1987f259e..5af3262d5 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java @@ -1,42 +1,58 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.argeo.slc.core.execution; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.process.RealizedFlow; import org.argeo.slc.process.SlcExecution; -import org.argeo.slc.process.SlcExecutionNotifier; /** Thread of the SLC Process, starting the sub executions. */ public class ProcessThread extends Thread { private final static Log log = LogFactory.getLog(ProcessThread.class); - private final AbstractExecutionModulesManager executionModulesManager; + private final ExecutionModulesManager executionModulesManager; private final SlcExecution slcProcess; private final ProcessThreadGroup processThreadGroup; private final List flowsToProcess = new ArrayList(); private Boolean hadAnError = false; - public ProcessThread( - AbstractExecutionModulesManager executionModulesManager, + public ProcessThread(ExecutionModulesManager executionModulesManager, SlcExecution slcExecution) { super(executionModulesManager.getProcessesThreadGroup(), "SLC Process #" + slcExecution.getUuid()); this.executionModulesManager = executionModulesManager; this.slcProcess = slcExecution; - processThreadGroup = new ProcessThreadGroup(this); + processThreadGroup = new ProcessThreadGroup(executionModulesManager, + this); } public void run() { - log.info("\n##\n## Process SLC Execution " + slcProcess + "\n##\n"); + log.info("\n##\n## SLC Process #" + slcProcess.getUuid() + + " STARTED\n##\n"); slcProcess.setStatus(SlcExecution.STATUS_RUNNING); - dispatchUpdateStatus(slcProcess, SlcExecution.STATUS_SCHEDULED, - SlcExecution.STATUS_RUNNING); + executionModulesManager.dispatchUpdateStatus(slcProcess, + SlcExecution.STATUS_SCHEDULED, SlcExecution.STATUS_RUNNING); flowsToProcess.addAll(slcProcess.getRealizedFlows()); @@ -45,29 +61,30 @@ public class ProcessThread extends Thread { ExecutionThread thread = new ExecutionThread(this, flow); thread.start(); - synchronized (this) { - try { - wait(); - } catch (InterruptedException e) { - // silent - } + try { + thread.join(); + } catch (InterruptedException e) { + log.error("Flow " + flow + " was interrupted", e); } + + // synchronized (this) { + // try { + // wait(); + // } catch (InterruptedException e) { + // // silent + // } + // } } + // TODO: error management at flow level? if (hadAnError) slcProcess.setStatus(SlcExecution.STATUS_ERROR); else slcProcess.setStatus(SlcExecution.STATUS_FINISHED); - dispatchUpdateStatus(slcProcess, SlcExecution.STATUS_RUNNING, - slcProcess.getStatus()); - } + executionModulesManager.dispatchUpdateStatus(slcProcess, + SlcExecution.STATUS_RUNNING, slcProcess.getStatus()); - protected void dispatchUpdateStatus(SlcExecution slcExecution, - String oldStatus, String newStatus) { - for (Iterator it = executionModulesManager - .getSlcExecutionNotifiers().iterator(); it.hasNext();) { - it.next().updateStatus(slcExecution, oldStatus, newStatus); - } + log.info("\n## SLC Process #" + slcProcess.getUuid() + " COMPLETED\n"); } public void notifyError() { @@ -75,7 +92,7 @@ public class ProcessThread extends Thread { } public synchronized void flowCompleted() { - notifyAll(); + // notifyAll(); } public SlcExecution getSlcProcess() { @@ -86,7 +103,7 @@ public class ProcessThread extends Thread { return processThreadGroup; } - public AbstractExecutionModulesManager getExecutionModulesManager() { + public ExecutionModulesManager getExecutionModulesManager() { return executionModulesManager; } }