X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2FExecutionThread.java;h=190481b7104a4ce703b3bcc11e4a3649e53d77a4;hb=645840383404d5962ca2af85c2020c3d66219518;hp=9190ea6fc1647c38d097390fff116237322de466;hpb=b811ec0603b1e596f26eee8a5378c6294cba495d;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java index 9190ea6fc..190481b71 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Mathieu Baudier + * Copyright (C) 2007-2012 Mathieu Baudier * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.argeo.slc.core.execution; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.slc.SlcException; import org.argeo.slc.execution.ExecutionFlowDescriptor; -import org.argeo.slc.process.RealizedFlow; -import org.argeo.slc.process.SlcExecutionStep; +import org.argeo.slc.execution.ExecutionStep; +import org.argeo.slc.execution.RealizedFlow; +import org.springframework.security.Authentication; +import org.springframework.security.context.SecurityContextHolder; /** Thread of a single execution */ public class ExecutionThread extends Thread { @@ -40,9 +42,16 @@ public class ExecutionThread extends Thread { } public void run() { + // authenticate thread + Authentication authentication = getProcessThreadGroup() + .getAuthentication(); + if (authentication == null) + throw new SlcException("Can only execute authenticated threads"); + SecurityContextHolder.getContext().setAuthentication(authentication); + if (getContextClassLoader() != null) { if (log.isTraceEnabled()) - log.debug("Context class loader set to " + log.trace("Context class loader set to " + getContextClassLoader()); } @@ -51,8 +60,8 @@ public class ExecutionThread extends Thread { .getFlowDescriptor(); String flowName = executionFlowDescriptor.getName(); - dispatchAddStep(new SlcExecutionStep(SlcExecutionStep.PHASE_START, - "Flow " + flowName)); + dispatchAddStep(new ExecutionStep(realizedFlow.getModuleName(), + ExecutionStep.PHASE_START, "Flow " + flowName)); try { String autoUpgrade = System @@ -60,23 +69,34 @@ public class ExecutionThread extends Thread { if (autoUpgrade != null && autoUpgrade.equals("true")) processThread.getExecutionModulesManager().upgrade( realizedFlow.getModuleNameVersion()); + + // START FLOW processThread.getExecutionModulesManager().execute(realizedFlow); + // END FLOW } catch (Exception e) { // TODO: re-throw exception ? String msg = "Execution of flow " + flowName + " failed."; log.error(msg, e); - dispatchAddStep(new SlcExecutionStep(SlcExecutionStep.ERROR, msg - + " " + e.getMessage())); + dispatchAddStep(new ExecutionStep(realizedFlow.getModuleName(), + ExecutionStep.ERROR, msg + " " + e.getMessage())); processThread.notifyError(); } finally { processThread.flowCompleted(); - dispatchAddStep(new SlcExecutionStep(SlcExecutionStep.PHASE_END, - "Flow " + flowName)); + dispatchAddStep(new ExecutionStep(realizedFlow.getModuleName(), + ExecutionStep.PHASE_END, "Flow " + flowName)); } } - private void dispatchAddStep(SlcExecutionStep step) { + private void dispatchAddStep(ExecutionStep step) { processThread.getProcessThreadGroup().dispatchAddStep(step); } + protected ProcessThreadGroup getProcessThreadGroup() { + return processThread.getProcessThreadGroup(); + } + + public RealizedFlow getRealizedFlow() { + return realizedFlow; + } + }