Execution modules now properly started when a flow is called.
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 30 May 2013 16:20:58 +0000 (16:20 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 30 May 2013 16:20:58 +0000 (16:20 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@6311 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionProcess.java
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java

index 693389d119fe02bd1ce462c93061a988b7ce18c7..5c00bcffb1be2b49f0f28f01353cb6917ef93ae4 100644 (file)
@@ -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();
index e9a3b6380fd803dcc478b9a7e6375fe3f8eb91d1..180d8f008f84bc7e7d8644896b4486ade72c7fcb 100644 (file)
@@ -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)
index 8f1efe35dc965b84619f490b9de494e9b9fd4bf6..aad574184aefd7d1390c7e1d7d7e4244190ff7d7 100644 (file)
@@ -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();