Resolve the service reference before intantiating proxy for it 90/4790/2
authorRobert Varga <rovarga@cisco.com>
Sun, 26 Jan 2014 09:27:24 +0000 (10:27 +0100)
committerRobert Varga <rovarga@cisco.com>
Sun, 26 Jan 2014 10:11:34 +0000 (11:11 +0100)
The original code assumed that if it has a ServiceReference, that
service does not disappear. Now it resolves it before deciding whether
to use a proxy.

Change-Id: I4dfdf886ab1f6fca7cdd523cf3e112af6d9b1411
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/RuntimeMappingModule.java

index cef37db684fc6717d28db0ba4f25339a15136fce..51efa9e2e5498ef3e1e5e6296ea61fee9fa0646c 100644 (file)
@@ -80,7 +80,12 @@ public final class RuntimeMappingModule extends
         if(serviceRef == null) {
             return null;
         }
-        return new RuntimeGeneratedMappingServiceProxy(getBundleContext(),serviceRef);
+
+        BindingIndependentMappingService delegate = bundleContext.getService(serviceRef);
+        if (delegate == null) {
+            return null;
+        }
+        return new RuntimeGeneratedMappingServiceProxy(getBundleContext(),serviceRef,delegate);
     }
 
     private BundleContext getBundleContext() {
@@ -101,10 +106,11 @@ public final class RuntimeMappingModule extends
         private BundleContext bundleContext;
 
         public RuntimeGeneratedMappingServiceProxy(BundleContext bundleContext,
-                ServiceReference<BindingIndependentMappingService> serviceRef) {
-            this.bundleContext = bundleContext;
-            this.reference = serviceRef;
-            this.delegate = bundleContext.getService(serviceRef);
+                ServiceReference<BindingIndependentMappingService> serviceRef,
+                BindingIndependentMappingService delegate) {
+            this.bundleContext = Preconditions.checkNotNull(bundleContext);
+            this.reference = Preconditions.checkNotNull(serviceRef);
+            this.delegate = Preconditions.checkNotNull(delegate);
         }
 
         public CodecRegistry getCodecRegistry() {