From: Mathieu Baudier Date: Thu, 30 Jul 2009 20:25:48 +0000 (+0000) Subject: Also cache bundle metadata X-Git-Tag: argeo-slc-2.1.7~1570 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=c37222d3fdb7f7d3e6d620321ec509f9e9abd94c;p=gpl%2Fargeo-slc.git Also cache bundle metadata git-svn-id: https://svn.argeo.org/slc/trunk@2844 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java index 9fb09bebf..50b76fa47 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java @@ -15,6 +15,9 @@ public class OsgiBundle extends BasicNameVersion implements Module { private Long internalBundleId; + private String label; + private String description; + public OsgiBundle() { } @@ -77,4 +80,20 @@ public class OsgiBundle extends BasicNameVersion implements Module { this.internalBundleId = internalBundleId; } + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + } 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 ca8fabaee..b2038b928 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 @@ -12,6 +12,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; +import org.argeo.slc.build.BasicNameVersion; import org.argeo.slc.core.execution.AbstractExecutionModulesManager; import org.argeo.slc.core.execution.DefaultExecutionFlowDescriptorConverter; import org.argeo.slc.deploy.ModuleDescriptor; @@ -48,12 +49,33 @@ public class OsgiExecutionModulesManager extends private Boolean useCachedServices = Boolean.parseBoolean(System .getProperty(PROPERTY_CACHE_SERVICES, "true")); - public ExecutionModuleDescriptor getExecutionModuleDescriptor( + public synchronized ExecutionModuleDescriptor getExecutionModuleDescriptor( String moduleName, String version) { ExecutionModuleDescriptor md = new ExecutionModuleDescriptor(); - md.setName(moduleName); - md.setVersion(version); - setMetadataFromBundle(md, null); + 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; + } + } + 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); + } ExecutionFlowDescriptorConverter executionFlowDescriptorConverter = getExecutionFlowDescriptorConverter( moduleName, version); if (executionFlowDescriptorConverter == null) @@ -321,6 +343,10 @@ public class OsgiExecutionModulesManager extends 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); if (log.isTraceEnabled()) log.debug("Registered execution context from " + osgiBundle); @@ -364,10 +390,16 @@ public class OsgiExecutionModulesManager extends ExecutionFlow executionFlow = (ExecutionFlow) service; OsgiBundle osgiBundle = asOsgiBundle(properties); if (executionFlows.containsKey(osgiBundle)) { - executionFlows.get(osgiBundle).remove(executionFlow); + 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); + } } } else if (service instanceof ExecutionFlowDescriptorConverter) { OsgiBundle osgiBundle = asOsgiBundle(properties);