From 36016cf7b99743d146948b0712fca639efa0ee8e Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Thu, 30 May 2013 16:20:58 +0000 Subject: [PATCH] Execution modules now properly started when a flow is called. git-svn-id: https://svn.argeo.org/slc/trunk@6311 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../java/org/argeo/slc/jcr/SlcJcrUtils.java | 11 +++++++++ .../jcr/execution/JcrExecutionProcess.java | 15 ++++++++++++ .../slc/osgi/OsgiExecutionModulesManager.java | 23 +++++++++++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java index 693389d11..5c00bcffb 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java @@ -28,6 +28,8 @@ import javax.jcr.nodetype.NodeType; import org.argeo.jcr.JcrUtils; import org.argeo.jcr.UserJcrUtils; +import org.argeo.slc.BasicNameVersion; +import org.argeo.slc.NameVersion; import org.argeo.slc.SlcException; import org.argeo.slc.core.execution.PrimitiveAccessor; import org.argeo.slc.core.execution.PrimitiveUtils; @@ -70,6 +72,15 @@ public class SlcJcrUtils implements SlcNames { return moduleName; } + /** Extracts the module name and version from a flow path */ + public static NameVersion moduleNameVersion(String fullFlowPath) { + String[] tokens = fullFlowPath.split("/"); + String module = tokens[AGENT_FACTORY_DEPTH + 2]; + String moduleName = module.substring(0, module.indexOf('_')); + String moduleVersion = module.substring(module.indexOf('_') + 1); + return new BasicNameVersion(moduleName, moduleVersion); + } + /** Module node name based on module name and version */ public static String getModuleNodeName(ModuleDescriptor moduleDescriptor) { return moduleDescriptor.getName() + "_" + moduleDescriptor.getVersion(); diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionProcess.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionProcess.java index e9a3b6380..180d8f008 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionProcess.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionProcess.java @@ -22,16 +22,20 @@ import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; +import javax.jcr.Property; import javax.jcr.Repository; import javax.jcr.RepositoryException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.jcr.JcrUtils; +import org.argeo.slc.NameVersion; import org.argeo.slc.SlcException; +import org.argeo.slc.core.execution.ProcessThread; import org.argeo.slc.execution.ExecutionProcess; import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.execution.RealizedFlow; +import org.argeo.slc.jcr.SlcJcrUtils; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; @@ -148,6 +152,17 @@ public class JcrExecutionProcess implements ExecutionProcess, SlcNames { NodeIterator nit = rootRealizedFlowNode.getNodes(SLC_FLOW); while (nit.hasNext()) { Node realizedFlowNode = nit.nextNode(); + + if (realizedFlowNode.hasNode(SLC_ADDRESS)) { + String flowPath = realizedFlowNode.getNode(SLC_ADDRESS) + .getProperty(Property.JCR_PATH).getString(); + NameVersion moduleNameVersion = SlcJcrUtils + .moduleNameVersion(flowPath); + ((ProcessThread) Thread.currentThread()) + .getExecutionModulesManager().start( + moduleNameVersion); + } + RealizedFlow realizedFlow = new JcrRealizedFlow( realizedFlowNode); if (realizedFlow != null) diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java index 8f1efe35d..aad574184 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java @@ -102,8 +102,10 @@ public class OsgiExecutionModulesManager extends OsgiBundle osgiBundle = bundlesManager.findFromPattern(module); if (osgiBundle == null) throw new SlcException("No OSGi bundle found for " + module); - Bundle moduleBundle = bundlesManager.findRelatedBundle(osgiBundle); - bundlesManager.startSynchronous(moduleBundle); + // Bundle moduleBundle = + // bundlesManager.findRelatedBundle(osgiBundle); + start(osgiBundle); + RealizedFlow lastLaunch = findRealizedFlow(module, flow); if (lastLaunch == null) throw new SlcException("Cannot find launch for " + module + " " @@ -132,6 +134,23 @@ public class OsgiExecutionModulesManager extends } } + // public void startExectionModule(String moduleName, String moduleVersion) + // { + // try { + // ServiceReference[] sr = bundlesManager.getServiceRefSynchronous( + // ApplicationContext.class.getName(), + // "org.springframework.context.service.name=" + moduleName); + // // bundlesManager.startSynchronous(moduleBundle); + // if (sr == null || sr.length == 0) + // throw new SlcException( + // "Cannot find execution module application context " + // + moduleName); + // } catch (InvalidSyntaxException e) { + // throw new SlcException("Cannot start exeuction module " + // + moduleName, e); + // } + // } + public synchronized ExecutionModuleDescriptor getExecutionModuleDescriptor( String moduleName, String version) { ExecutionModuleDescriptor md = new ExecutionModuleDescriptor(); -- 2.39.5