You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/12/11 15:25:09 UTC

[camel] branch sandbox/camel-3.x updated: CAMEL-12969: OSGi service registry should unget services later during shutting down CamelContext which we can do in the start/stop service API instead. This reduces leaks if a service is get udring shutdown as now the lifecycle/osgi service registry is stopped as last action when camel context is shutting down.

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch sandbox/camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/sandbox/camel-3.x by this push:
     new 6e717d0  CAMEL-12969: OSGi service registry should unget services later during shutting down CamelContext which we can do in the start/stop service API instead. This reduces leaks if a service is get udring shutdown as now the lifecycle/osgi service registry is stopped as last action when camel context is shutting down.
6e717d0 is described below

commit 6e717d043ce7d28b72d1ab0d506b165f4bfae1d8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Dec 11 15:20:56 2018 +0100

    CAMEL-12969: OSGi service registry should unget services later during shutting down CamelContext which we can do in the start/stop service API instead. This reduces leaks if a service is get udring shutdown as now the lifecycle/osgi service registry is stopped as last action when camel context is shutting down.
    
    Conflicts:
    	components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
---
 .../org/apache/camel/core/osgi/OsgiServiceRegistry.java  | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
index 104cce9..c10eb22 100644
--- a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
+++ b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
@@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.Service;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.support.LifecycleStrategySupport;
 import org.osgi.framework.BundleContext;
@@ -37,7 +38,7 @@ import org.slf4j.LoggerFactory;
 /**
  * The OsgiServiceRegistry support to get the service object from the bundle context
  */
-public class OsgiServiceRegistry extends LifecycleStrategySupport implements Registry {
+public class OsgiServiceRegistry extends LifecycleStrategySupport implements Registry, Service {
     private static final Logger LOG = LoggerFactory.getLogger(OsgiCamelContextHelper.class);
     private final BundleContext bundleContext;
     private final Queue<ServiceReference<?>> serviceReferenceQueue = new ConcurrentLinkedQueue<>();
@@ -51,7 +52,7 @@ public class OsgiServiceRegistry extends LifecycleStrategySupport implements Reg
      */
     public <T> T lookupByNameAndType(String name, Class<T> type) {
         Object service = null;
-        ServiceReference<?> sr  = null;
+        ServiceReference<?> sr;
         try {
             ServiceReference<?>[] refs = bundleContext.getServiceReferences(type.getName(), "(name=" + name + ")");            
             if (refs != null && refs.length > 0) {
@@ -131,8 +132,14 @@ public class OsgiServiceRegistry extends LifecycleStrategySupport implements Reg
     }
 
     @Override
-    public void onContextStop(CamelContext context) {
-        // Unget the OSGi service
+    public void start() throws Exception {
+        // noop
+    }
+
+    @Override
+    public void stop() throws Exception {
+        // Unget the OSGi service as OSGi uses reference counting
+        // and we should do this as one of the last actions when stopping Camel
         ServiceReference<?> sr = serviceReferenceQueue.poll();
         while (sr != null) {
             bundleContext.ungetService(sr);
@@ -141,5 +148,4 @@ public class OsgiServiceRegistry extends LifecycleStrategySupport implements Reg
         // Clean up the OSGi Service Cache
         serviceReferenceQueue.clear();
     }
-
 }