Repository: camel Updated Branches: refs/heads/master 69e033368 -> 25e9ca642
CAMEL-9631: do not cache OSGi service instances Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/25e9ca64 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/25e9ca64 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/25e9ca64 Branch: refs/heads/master Commit: 25e9ca64205755bd32b10084eb14081f7db0722a Parents: 69e0333 Author: Börcsök József <borcs...@sch.bme.hu> Authored: Wed Jul 6 16:22:42 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Jul 7 09:21:06 2016 +0200 ---------------------------------------------------------------------- .../camel/core/osgi/OsgiServiceRegistry.java | 35 +++++++------------- 1 file changed, 12 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/25e9ca64/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java ---------------------------------------------------------------------- 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 7813b36..b916355 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 @@ -21,7 +21,6 @@ import java.util.HashSet; import java.util.Map; import java.util.Queue; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import org.apache.camel.CamelContext; @@ -36,7 +35,6 @@ import org.osgi.framework.ServiceReference; */ public class OsgiServiceRegistry extends LifecycleStrategySupport implements Registry { private final BundleContext bundleContext; - private final Map<String, Object> serviceCacheMap = new ConcurrentHashMap<String, Object>(); private final Queue<ServiceReference<?>> serviceReferenceQueue = new ConcurrentLinkedQueue<ServiceReference<?>>(); public OsgiServiceRegistry(BundleContext bc) { @@ -47,23 +45,18 @@ public class OsgiServiceRegistry extends LifecycleStrategySupport implements Reg * Support to lookup the Object with filter with the (name=NAME) and class type */ public <T> T lookupByNameAndType(String name, Class<T> type) { - Object service = serviceCacheMap.get(name); - if (service == null) { - ServiceReference<?> sr = null; - try { - ServiceReference<?>[] refs = bundleContext.getServiceReferences(type.getName(), "(name=" + name + ")"); - if (refs != null && refs.length > 0) { - // just return the first one - sr = refs[0]; - serviceReferenceQueue.add(sr); - service = bundleContext.getService(sr); - if (service != null) { - serviceCacheMap.put(name, service); - } - } - } catch (Exception ex) { - throw ObjectHelper.wrapRuntimeCamelException(ex); + Object service = null; + ServiceReference<?> sr = null; + try { + ServiceReference<?>[] refs = bundleContext.getServiceReferences(type.getName(), "(name=" + name + ")"); + if (refs != null && refs.length > 0) { + // just return the first one + sr = refs[0]; + serviceReferenceQueue.add(sr); + service = bundleContext.getService(sr); } + } catch (Exception ex) { + throw ObjectHelper.wrapRuntimeCamelException(ex); } return type.cast(service); } @@ -72,7 +65,7 @@ public class OsgiServiceRegistry extends LifecycleStrategySupport implements Reg * It's only support to look up the ServiceReference with Class name */ public Object lookupByName(String name) { - Object service = serviceCacheMap.get(name); + Object service = null; if (service == null) { ServiceReference<?> sr = bundleContext.getServiceReference(name); if (sr != null) { @@ -80,9 +73,6 @@ public class OsgiServiceRegistry extends LifecycleStrategySupport implements Reg // and call ungetService when the camel context is closed serviceReferenceQueue.add(sr); service = bundleContext.getService(sr); - if (service != null) { - serviceCacheMap.put(name, service); - } } } return service; @@ -144,7 +134,6 @@ public class OsgiServiceRegistry extends LifecycleStrategySupport implements Reg } // Clean up the OSGi Service Cache serviceReferenceQueue.clear(); - serviceCacheMap.clear(); } }