X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.osgi%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fosgi%2FOsgiExecutionModulesManager.java;h=f2fc44f810f19bbf6d90617442030d7cc4c868ce;hb=098e868d40b2130c6735b1547247c61a5d88da95;hp=2cfad6683cdc7404daaa076b945ac1c6902b3b44;hpb=1fdb1b4e7b1d2b0cabb6483238301b857a6392fa;p=gpl%2Fargeo-slc.git 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 2cfad6683..f2fc44f81 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 @@ -16,23 +16,27 @@ package org.argeo.slc.osgi; +import java.lang.management.ManagementFactory; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.StandardMBean; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.slc.BasicNameVersion; +import org.argeo.slc.NameVersion; import org.argeo.slc.SlcException; -import org.argeo.slc.build.BasicNameVersion; -import org.argeo.slc.build.NameVersion; import org.argeo.slc.core.execution.AbstractExecutionModulesManager; import org.argeo.slc.core.execution.DefaultExecutionFlowDescriptorConverter; +import org.argeo.slc.deploy.Module; import org.argeo.slc.deploy.ModuleDescriptor; import org.argeo.slc.execution.ExecutionContext; import org.argeo.slc.execution.ExecutionFlow; @@ -42,118 +46,120 @@ import org.argeo.slc.execution.ExecutionModuleDescriptor; import org.argeo.slc.execution.ExecutionModulesListener; import org.argeo.slc.process.RealizedFlow; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; import org.osgi.framework.Constants; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; +import org.osgi.framework.launch.Framework; import org.springframework.osgi.service.importer.OsgiServiceLifecycleListener; +/** Execution modules manager implementation based on an OSGi runtime. */ public class OsgiExecutionModulesManager extends - AbstractExecutionModulesManager implements InitializingBean, - DisposableBean, OsgiServiceLifecycleListener { - -// static { -// // Force usage of vanilla Xalan when in OSGi -// // We would like to do it in a cleaner way -// // but the integration of Xalan and Xerces in the JRE -// // makes it very difficult -// // Suggestions welcome! -// Properties systemProperties = System.getProperties(); -// // if (!systemProperties -// // .containsKey("javax.xml.parsers.DocumentBuilderFactory")) -// // System.setProperty("javax.xml.parsers.DocumentBuilderFactory", -// // "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); -// // if -// // (!systemProperties.containsKey("javax.xml.parsers.SAXParserFactory")) -// // System.setProperty("javax.xml.parsers.SAXParserFactory", -// // "org.apache.xerces.jaxp.SAXParserFactoryImpl"); -// if (!systemProperties -// .containsKey("javax.xml.transform.TransformerFactory")) -// System.setProperty("javax.xml.transform.TransformerFactory", -// "org.apache.xalan.processor.TransformerFactoryImpl"); -// } - - private final static String PROPERTY_CACHE_SERVICES = "slc.osgi.execution.cacheServices"; + AbstractExecutionModulesManager implements OsgiServiceLifecycleListener { private final static Log log = LogFactory .getLog(OsgiExecutionModulesManager.class); private BundlesManager bundlesManager; - private ServiceTracker executionContextsTracker; private Map executionContexts = new HashMap(); private Map executionFlowDescriptorConverters = new HashMap(); private Map> executionFlows = new HashMap>(); private ExecutionFlowDescriptorConverter defaultDescriptorConverter = new DefaultExecutionFlowDescriptorConverter(); - private Boolean useCachedServices = Boolean.parseBoolean(System - .getProperty(PROPERTY_CACHE_SERVICES, "true")); + private List executionModulesListeners = new ArrayList(); + + private Boolean registerFlowsToJmx = true; + + public void init() throws Exception { + final String module = System.getProperty(UNIQUE_LAUNCH_MODULE_PROPERTY); + final String flow = System.getProperty(UNIQUE_LAUNCH_FLOW_PROPERTY); + if (module != null) { + // launch a flow and stops + new Thread("Unique Flow") { + @Override + public void run() { + if (log.isDebugEnabled()) + log.debug("Launch unique flow " + flow + + " from module " + module); + try { + OsgiBundle osgiBundle = bundlesManager + .findFromPattern(module); + Bundle moduleBundle = bundlesManager + .findRelatedBundle(osgiBundle); + bundlesManager.startSynchronous(moduleBundle); + RealizedFlow lastLaunch = findRealizedFlow(module, flow); + if (lastLaunch == null) + throw new SlcException("Cannot find launch for " + + module + " " + flow); + execute(lastLaunch); + } catch (Exception e) { + log.error("Error in unique flow " + flow + + " from module " + module, e); + } finally { + if (log.isDebugEnabled()) + log.debug("Shutdown OSGi runtime..."); + Framework framework = (Framework) bundlesManager + .getBundleContext().getBundle(0); + try { + // shutdown framework + framework.stop(); + // wait 1 min for shutdown + framework.waitForStop(60 * 1000); + // close VM + System.exit(0); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + } + }.start(); + } + + } + + public void destroy() { + + } public synchronized ExecutionModuleDescriptor getExecutionModuleDescriptor( String moduleName, String version) { ExecutionModuleDescriptor md = new ExecutionModuleDescriptor(); - if (useCachedServices) { - OsgiBundle osgiBundle = null; - BasicNameVersion nameVersion = new BasicNameVersion(moduleName, - version); - bundles: for (Iterator iterator = executionContexts - .keySet().iterator(); iterator.hasNext();) { - OsgiBundle ob = iterator.next(); - if (ob.equals(nameVersion)) { - osgiBundle = ob; - break bundles; - } + OsgiBundle osgiBundle = null; + BasicNameVersion nameVersion = new BasicNameVersion(moduleName, version); + bundles: for (Iterator iterator = executionContexts + .keySet().iterator(); iterator.hasNext();) { + OsgiBundle ob = iterator.next(); + if (ob.equals(nameVersion)) { + osgiBundle = ob; + break bundles; } - if (osgiBundle == null) - throw new SlcException("No execution module registered for " - + nameVersion); - md.setName(osgiBundle.getName()); - md.setVersion(osgiBundle.getVersion()); - md.setLabel(osgiBundle.getLabel()); - md.setDescription(osgiBundle.getDescription()); - } else { - md.setName(moduleName); - md.setVersion(version); - setMetadataFromBundle(md, null); } + if (osgiBundle == null) + throw new SlcException("No execution module registered for " + + nameVersion); + md.setName(osgiBundle.getName()); + md.setVersion(osgiBundle.getVersion()); + md.setTitle(osgiBundle.getTitle()); + md.setDescription(osgiBundle.getDescription()); + ExecutionFlowDescriptorConverter executionFlowDescriptorConverter = getExecutionFlowDescriptorConverter( moduleName, version); if (executionFlowDescriptorConverter == null) throw new SlcException("No flow converter found."); - executionFlowDescriptorConverter.addFlowsToDescriptor(md, listFlows( - moduleName, version)); + executionFlowDescriptorConverter.addFlowsToDescriptor(md, + listFlows(moduleName, version)); return md; } public synchronized List listExecutionModules() { List descriptors = new ArrayList(); - if (useCachedServices) { - for (Iterator iterator = executionContexts.keySet() - .iterator(); iterator.hasNext();) { - OsgiBundle osgiBundle = iterator.next(); - ExecutionModuleDescriptor md = new ExecutionModuleDescriptor(); - setMetadataFromBundle(md, bundlesManager - .findRelatedBundle(osgiBundle)); - descriptors.add(md); - } - } else { - ServiceReference[] arr = executionContextsTracker - .getServiceReferences(); - if (arr == null) { - log.error("Tracker returned null."); - return descriptors; - } - - List srs = Arrays.asList(arr); - // ServiceReference[] srs = - // executionContexts.getServiceReferences(); - for (ServiceReference sr : srs) { - ExecutionModuleDescriptor md = new ExecutionModuleDescriptor(); - setMetadataFromBundle(md, sr.getBundle()); - descriptors.add(md); - } + for (Iterator iterator = executionContexts.keySet() + .iterator(); iterator.hasNext();) { + OsgiBundle osgiBundle = iterator.next(); + ExecutionModuleDescriptor md = new ExecutionModuleDescriptor(); + setMetadataFromBundle(md, + bundlesManager.findRelatedBundle(osgiBundle)); + descriptors.add(md); } return descriptors; } @@ -162,37 +168,12 @@ public class OsgiExecutionModulesManager extends String moduleName, String moduleVersion) { Map flows = new HashMap(); - if (useCachedServices) { - OsgiBundle key = new OsgiBundle( - moduleName, moduleVersion); - if(!executionFlows.containsKey(key)) - return flows; - Set flowsT = executionFlows.get(key); - for (ExecutionFlow flow : flowsT) - flows.put(flow.getName(), flow); - } else { - - // TODO: use service trackers? - // String filter = OsgiFilterUtils.unifyFilter(ExecutionFlow.class, - // null); - - String filter = "(Bundle-SymbolicName=" + moduleName + ")"; - ServiceReference[] sfs; - try { - sfs = bundlesManager.getBundleContext().getServiceReferences( - ExecutionFlow.class.getName(), filter); - } catch (InvalidSyntaxException e) { - throw new SlcException( - "Cannot retrieve service reference for flow " + filter, - e); - } - - for (ServiceReference sf : sfs) { - ExecutionFlow flow = (ExecutionFlow) bundlesManager - .getBundleContext().getService(sf); - flows.put(flow.getName(), flow); - } - } + OsgiBundle key = new OsgiBundle(moduleName, moduleVersion); + if (!executionFlows.containsKey(key)) + return flows; + Set flowsT = executionFlows.get(key); + for (ExecutionFlow flow : flowsT) + flows.put(flow.getName(), flow); return flows; } @@ -201,7 +182,7 @@ public class OsgiExecutionModulesManager extends String filter = "(&(Bundle-SymbolicName=" + moduleName + ")(org.springframework.osgi.bean.name=" + flowName + "))"; return bundlesManager.getSingleServiceStrict(ExecutionFlow.class, - filter); + filter, true); } protected ExecutionContext findExecutionContext(String moduleName, @@ -209,31 +190,15 @@ public class OsgiExecutionModulesManager extends String filter = "(&(Bundle-SymbolicName=" + moduleName + ")(Bundle-Version=" + moduleVersion + "))"; return bundlesManager.getSingleServiceStrict(ExecutionContext.class, - filter); + filter, true); } protected ExecutionFlowDescriptorConverter findExecutionFlowDescriptorConverter( String moduleName, String moduleVersion) { - String filter = "(&(Bundle-SymbolicName=" + moduleName + ")(Bundle-Version=" + moduleVersion + "))"; return bundlesManager.getSingleService( - ExecutionFlowDescriptorConverter.class, filter); - } - - public void setBundlesManager(BundlesManager bundlesManager) { - this.bundlesManager = bundlesManager; - } - - public void afterPropertiesSet() throws Exception { - if (!useCachedServices) - executionContextsTracker = bundlesManager - .newTracker(ExecutionContext.class); - } - - public void destroy() throws Exception { - if (executionContextsTracker != null) - executionContextsTracker.close(); + ExecutionFlowDescriptorConverter.class, filter, false); } /** @@ -272,8 +237,7 @@ public class OsgiExecutionModulesManager extends launch.setFlowDescriptor(descriptor); return launch; } else { - log - .warn("Could not find any execution module matching these requirements."); + log.warn("Could not find any execution module matching these requirements."); return null; } } @@ -285,21 +249,16 @@ public class OsgiExecutionModulesManager extends protected synchronized ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter( String moduleName, String moduleVersion) { - if (useCachedServices) { - OsgiBundle osgiBundle = new OsgiBundle(moduleName, moduleVersion); - if (executionFlowDescriptorConverters.containsKey(osgiBundle)) - return executionFlowDescriptorConverters.get(osgiBundle); - else - return defaultDescriptorConverter; - } else { - // Check whether a descriptor converter is published by this module - ExecutionFlowDescriptorConverter descriptorConverter = findExecutionFlowDescriptorConverter( - moduleName, moduleVersion); - if (descriptorConverter == null) - return defaultDescriptorConverter; - else - return descriptorConverter; - } + OsgiBundle osgiBundle = new OsgiBundle(moduleName, moduleVersion); + return getExecutionFlowDescriptorConverter(osgiBundle); + } + + protected synchronized ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter( + OsgiBundle osgiBundle) { + if (executionFlowDescriptorConverters.containsKey(osgiBundle)) + return executionFlowDescriptorConverters.get(osgiBundle); + else + return defaultDescriptorConverter; } public ModuleDescriptor getModuleDescriptor(String moduleName, @@ -318,6 +277,26 @@ public class OsgiExecutionModulesManager extends return lst; } + public void start(NameVersion nameVersion) { + try { + Bundle bundle = bundlesManager.findRelatedBundle(new OsgiBundle( + nameVersion)); + bundlesManager.startSynchronous(bundle); + } catch (BundleException e) { + throw new SlcException("Cannot start " + nameVersion, e); + } + } + + public void stop(NameVersion nameVersion) { + try { + Bundle bundle = bundlesManager.findRelatedBundle(new OsgiBundle( + nameVersion)); + bundlesManager.stopSynchronous(bundle); + } catch (BundleException e) { + throw new SlcException("Cannot stop " + nameVersion, e); + } + } + protected void setMetadataFromBundle(ModuleDescriptor md, Bundle bundle) { Bundle bdl = bundle; if (bdl == null) { @@ -341,7 +320,7 @@ public class OsgiExecutionModulesManager extends md.setName(bdl.getSymbolicName()); md.setVersion(getHeaderSafe(bdl, Constants.BUNDLE_VERSION)); - md.setLabel(getHeaderSafe(bdl, Constants.BUNDLE_NAME)); + md.setTitle(getHeaderSafe(bdl, Constants.BUNDLE_NAME)); md.setDescription(getHeaderSafe(bdl, Constants.BUNDLE_DESCRIPTION)); } @@ -353,98 +332,215 @@ public class OsgiExecutionModulesManager extends return obj.toString(); } - @SuppressWarnings("unchecked") - public synchronized void bind(Object service, Map properties) - throws Exception { - if (service instanceof ExecutionContext) { - ExecutionContext executionContext = (ExecutionContext) service; - OsgiBundle osgiBundle = asOsgiBundle(properties); - Bundle bundle = bundlesManager.findRelatedBundle(osgiBundle); - osgiBundle.setLabel(getHeaderSafe(bundle, Constants.BUNDLE_NAME)); - osgiBundle.setDescription(getHeaderSafe(bundle, - Constants.BUNDLE_DESCRIPTION)); - executionContexts.put(osgiBundle, executionContext); + /* + * REGISTRATION + */ + + /** Registers an execution context. */ + public synchronized void register(ExecutionContext executionContext, + Map properties) { + OsgiBundle osgiBundle = asOsgiBundle(properties); + Bundle bundle = bundlesManager.findRelatedBundle(osgiBundle); + osgiBundle.setTitle(getHeaderSafe(bundle, Constants.BUNDLE_NAME)); + osgiBundle.setDescription(getHeaderSafe(bundle, + Constants.BUNDLE_DESCRIPTION)); + executionContexts.put(osgiBundle, executionContext); + if (log.isTraceEnabled()) + log.trace("Registered execution context from " + osgiBundle); + // Notify + for (ExecutionModulesListener listener : executionModulesListeners) + listener.executionModuleAdded(osgiBundle.getModuleDescriptor()); + } + + /** Unregisters an execution context. */ + public synchronized void unregister(ExecutionContext executionContext, + Map properties) { + OsgiBundle osgiBundle = asOsgiBundle(properties); + if (executionContexts.containsKey(osgiBundle)) { + executionContexts.remove(osgiBundle); if (log.isTraceEnabled()) - log.debug("Registered execution context from " + osgiBundle); + log.trace("Removed execution context from " + osgiBundle); // Notify - for (ExecutionModulesListener listener : getExecutionModulesListeners()) - listener.executionModuleAdded(osgiBundle, executionContext); + for (ExecutionModulesListener listener : executionModulesListeners) + listener.executionModuleRemoved(osgiBundle + .getModuleDescriptor()); + } + } - } else if (service instanceof ExecutionFlow) { - ExecutionFlow executionFlow = (ExecutionFlow) service; - OsgiBundle osgiBundle = asOsgiBundle(properties); - if (!executionFlows.containsKey(osgiBundle)) { - executionFlows.put(osgiBundle, new HashSet()); - } - executionFlows.get(osgiBundle).add(executionFlow); + /** Registers an execution flow. */ + public synchronized void register(ExecutionFlow executionFlow, + Map properties) { + OsgiBundle osgiBundle = asOsgiBundle(properties); + if (!executionFlows.containsKey(osgiBundle)) { + executionFlows.put(osgiBundle, new HashSet()); + } + executionFlows.get(osgiBundle).add(executionFlow); + if (log.isTraceEnabled()) + log.trace("Registered " + executionFlow + " from " + osgiBundle); + + // notifications + if (registerFlowsToJmx) + registerMBean(osgiBundle, executionFlow); + ExecutionFlowDescriptorConverter efdc = getExecutionFlowDescriptorConverter(osgiBundle); + for (ExecutionModulesListener listener : executionModulesListeners) + listener.executionFlowAdded(osgiBundle.getModuleDescriptor(), + efdc.getExecutionFlowDescriptor(executionFlow)); + } + + /** Unregisters an execution flow. */ + public synchronized void unregister(ExecutionFlow executionFlow, + Map properties) { + OsgiBundle osgiBundle = asOsgiBundle(properties); + if (executionFlows.containsKey(osgiBundle)) { + Set flows = executionFlows.get(osgiBundle); + flows.remove(executionFlow); if (log.isTraceEnabled()) - log - .debug("Registered " + executionFlow + " from " - + osgiBundle); - for (ExecutionModulesListener listener : getExecutionModulesListeners()) - listener.executionFlowAdded(osgiBundle, executionFlow); + log.trace("Removed " + executionFlow + " from " + osgiBundle); + if (flows.size() == 0) { + executionFlows.remove(osgiBundle); + if (log.isTraceEnabled()) + log.trace("Removed flows set from " + osgiBundle); + } + + // notifications + if (registerFlowsToJmx) + unregisterMBean(osgiBundle, executionFlow); + ExecutionFlowDescriptorConverter efdc = getExecutionFlowDescriptorConverter(osgiBundle); + for (ExecutionModulesListener listener : executionModulesListeners) + listener.executionFlowRemoved(osgiBundle.getModuleDescriptor(), + efdc.getExecutionFlowDescriptor(executionFlow)); + } + } - } else if (service instanceof ExecutionFlowDescriptorConverter) { + /** Registers an execution module listener. */ + public synchronized void register( + ExecutionModulesListener executionModulesListener, + Map properties) { + // sync with current state + for (OsgiBundle osgiBundle : executionContexts.keySet()) { + executionModulesListener.executionModuleAdded(osgiBundle + .getModuleDescriptor()); + } + for (OsgiBundle osgiBundle : executionFlows.keySet()) { + ExecutionFlowDescriptorConverter efdc = getExecutionFlowDescriptorConverter(osgiBundle); + for (ExecutionFlow executionFlow : executionFlows.get(osgiBundle)) + executionModulesListener.executionFlowAdded( + osgiBundle.getModuleDescriptor(), + efdc.getExecutionFlowDescriptor(executionFlow)); + } + executionModulesListeners.add(executionModulesListener); + } + + /** Unregisters an execution module listener. */ + public synchronized void unregister( + ExecutionModulesListener executionModulesListener, + Map properties) { + executionModulesListeners.remove(executionModulesListener); + } + + @SuppressWarnings({ "rawtypes" }) + public synchronized void bind(Object service, Map properties) + throws Exception { + if (service instanceof ExecutionFlowDescriptorConverter) { ExecutionFlowDescriptorConverter executionFlowDescriptorConverter = (ExecutionFlowDescriptorConverter) service; OsgiBundle osgiBundle = asOsgiBundle(properties); executionFlowDescriptorConverters.put(osgiBundle, executionFlowDescriptorConverter); if (log.isTraceEnabled()) - log - .debug("Registered execution flow descriptor converter from " - + osgiBundle); + log.debug("Registered execution flow descriptor converter from " + + osgiBundle); } else { // ignore } } - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") public synchronized void unbind(Object service, Map properties) throws Exception { - if (service instanceof ExecutionContext) { - OsgiBundle osgiBundle = asOsgiBundle(properties); - if (executionContexts.containsKey(osgiBundle)) { - ExecutionContext executionContext = executionContexts - .remove(osgiBundle); - if (log.isTraceEnabled()) - log.debug("Removed execution context from " + osgiBundle); - // Notify - for (ExecutionModulesListener listener : getExecutionModulesListeners()) - listener.executionModuleRemoved(osgiBundle, - executionContext); - } - } else if (service instanceof ExecutionFlow) { - ExecutionFlow executionFlow = (ExecutionFlow) service; - OsgiBundle osgiBundle = asOsgiBundle(properties); - if (executionFlows.containsKey(osgiBundle)) { - Set flows = executionFlows.get(osgiBundle); - flows.remove(executionFlow); - if (log.isTraceEnabled()) - log.debug("Removed " + executionFlow + " from " - + osgiBundle); - if (flows.size() == 0) { - executionFlows.remove(osgiBundle); - if (log.isTraceEnabled()) - log.debug("Removed flows set from " + osgiBundle); - } - for (ExecutionModulesListener listener : getExecutionModulesListeners()) - listener.executionFlowRemoved(osgiBundle, executionFlow); - } - } else if (service instanceof ExecutionFlowDescriptorConverter) { + if (service instanceof ExecutionFlowDescriptorConverter) { OsgiBundle osgiBundle = asOsgiBundle(properties); if (executionFlowDescriptorConverters.containsKey(osgiBundle)) { executionFlowDescriptorConverters.remove(osgiBundle); if (log.isTraceEnabled()) - log - .debug("Removed execution flow descriptor converter from " - + osgiBundle); + log.debug("Removed execution flow descriptor converter from " + + osgiBundle); } } else { // ignore } } - @SuppressWarnings("unchecked") + /* + * JMX + */ + protected MBeanServer getMBeanServer() { + return ManagementFactory.getPlatformMBeanServer(); + } + + public void registerMBean(Module module, ExecutionFlow executionFlow) { + try { + StandardMBean mbean = new StandardMBean(executionFlow, + ExecutionFlow.class); + getMBeanServer().registerMBean(mbean, + flowMBeanName(module, executionFlow)); + } catch (Exception e) { + String msg = "Cannot register execution flow " + executionFlow + + " as mbean"; + throw new SlcException(msg, e); + } + } + + public void unregisterMBean(Module module, ExecutionFlow executionFlow) { + try { + getMBeanServer().unregisterMBean( + flowMBeanName(module, executionFlow)); + } catch (Exception e) { + String msg = "Cannot unregister execution flow " + executionFlow + + " as mbean"; + throw new SlcException(msg, e); + } + } + + @SuppressWarnings("deprecation") + protected ObjectName flowMBeanName(Module module, + ExecutionFlow executionFlow) { + String executionModulesPrefix = "SLCExecutionModules"; + String path = executionFlow.getPath(); + String name = executionFlow.getName(); + if (path == null && name.indexOf('/') >= 0) { + path = name.substring(0, name.lastIndexOf('/')); + name = name.substring(name.lastIndexOf('/')); + } + + StringBuffer buf = new StringBuffer(executionModulesPrefix + ":" + + "module=" + module.getName() + " [" + module.getVersion() + + "],"); + + if (path != null && !path.equals("")) { + int depth = 0; + for (String token : path.split("/")) { + if (!token.equals("")) { + buf.append("path").append(depth).append('='); + // in order to have directories first + buf.append('/'); + buf.append(token).append(','); + depth++; + } + } + } + buf.append("name=").append(name); + try { + return new ObjectName(buf.toString()); + } catch (Exception e) { + throw new SlcException("Cannot generate object name based on " + + buf, e); + } + } + + /* + * UTILITIES + */ + @SuppressWarnings("rawtypes") private OsgiBundle asOsgiBundle(Map properties) { String bundleSymbolicName = checkAndGet(Constants.BUNDLE_SYMBOLICNAME, properties); @@ -452,7 +548,7 @@ public class OsgiExecutionModulesManager extends return new OsgiBundle(bundleSymbolicName, bundleVersion); } - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") private String checkAndGet(Object key, Map properties) { if (!properties.containsKey(key) || properties.get(key) == null) throw new SlcException(key + " not set in " + properties); @@ -460,8 +556,17 @@ public class OsgiExecutionModulesManager extends return properties.get(key).toString(); } + public void setBundlesManager(BundlesManager bundlesManager) { + this.bundlesManager = bundlesManager; + } + public void setDefaultDescriptorConverter( ExecutionFlowDescriptorConverter defaultDescriptorConverter) { this.defaultDescriptorConverter = defaultDescriptorConverter; } + + public void setRegisterFlowsToJmx(Boolean registerFlowsToJmx) { + this.registerFlowsToJmx = registerFlowsToJmx; + } + }