This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 0e4b008 CAMEL-12987: Ensure onContextStop is called on the OsgiServiceRegistry. (#2660) 0e4b008 is described below commit 0e4b0088d796a49491b6e177c9aa5f0e2e6519b0 Author: Bob Paulin <b...@bobpaulin.com> AuthorDate: Sun Dec 9 03:52:27 2018 -0600 CAMEL-12987: Ensure onContextStop is called on the OsgiServiceRegistry. (#2660) --- .../camel/core/osgi/OsgiCamelContextHelper.java | 21 +++++++++++++++------ .../camel/core/osgi/OsgiDefaultCamelContext.java | 12 +----------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextHelper.java b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextHelper.java index 08ff669..2b9b1fc 100644 --- a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextHelper.java +++ b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextHelper.java @@ -56,14 +56,23 @@ public final class OsgiCamelContextHelper { public static Registry wrapRegistry(CamelContext camelContext, Registry registry, BundleContext bundleContext) { ObjectHelper.notNull(bundleContext, "BundleContext"); - LOG.debug("Setting up OSGi ServiceRegistry"); - OsgiServiceRegistry osgiServiceRegistry = new OsgiServiceRegistry(bundleContext); + OsgiServiceRegistry osgiServiceRegistry = null; + Registry resultingRegistry = registry; + if(registry instanceof OsgiServiceRegistry) { + osgiServiceRegistry = (OsgiServiceRegistry)registry; + } else { + LOG.debug("Wrapping Registry in OsgiServiceRegistry"); + osgiServiceRegistry = new OsgiServiceRegistry(bundleContext); + CompositeRegistry compositeRegistry = new CompositeRegistry(); + compositeRegistry.addRegistry(osgiServiceRegistry); + compositeRegistry.addRegistry(registry); + resultingRegistry = compositeRegistry; + } + // Need to clean up the OSGi service when camel context is closed. camelContext.addLifecycleStrategy(osgiServiceRegistry); - CompositeRegistry compositeRegistry = new CompositeRegistry(); - compositeRegistry.addRegistry(osgiServiceRegistry); - compositeRegistry.addRegistry(registry); - return compositeRegistry; + + return resultingRegistry; } } diff --git a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java index 20e3a21..821ef5d 100644 --- a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java +++ b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java @@ -32,7 +32,6 @@ import org.osgi.framework.BundleContext; public class OsgiDefaultCamelContext extends DefaultCamelContext { private final BundleContext bundleContext; - private final Registry registry; public OsgiDefaultCamelContext(BundleContext bundleContext) { this(bundleContext, new OsgiServiceRegistry(bundleContext)); @@ -41,7 +40,7 @@ public class OsgiDefaultCamelContext extends DefaultCamelContext { public OsgiDefaultCamelContext(BundleContext bundleContext, Registry registry) { super(registry); this.bundleContext = bundleContext; - this.registry = registry; + setRegistry(OsgiCamelContextHelper.wrapRegistry(this, registry, bundleContext)); OsgiCamelContextHelper.osgiUpdate(this, bundleContext); // setup the application context classloader with the bundle classloader setApplicationContextClassLoader(new BundleDelegatingClassLoader(bundleContext.getBundle())); @@ -53,15 +52,6 @@ public class OsgiDefaultCamelContext extends DefaultCamelContext { } @Override - protected Registry createRegistry() { - if (registry != null) { - return OsgiCamelContextHelper.wrapRegistry(this, registry, bundleContext); - } else { - return OsgiCamelContextHelper.wrapRegistry(this, super.createRegistry(), bundleContext); - } - } - - @Override protected TypeConverter createTypeConverter() { // CAMEL-3614: make sure we use a bundle context which imports org.apache.camel.impl.converter package BundleContext ctx = BundleContextUtils.getBundleContext(getClass());