Bug 1339: Added doublecheck for RPC registration 39/8839/1
authorLukas Sedlak <lsedlak@cisco.com>
Wed, 9 Jul 2014 07:21:35 +0000 (09:21 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 9 Jul 2014 07:21:38 +0000 (09:21 +0200)
Change-Id: I786934b6cc690817688e60fd3d422293f37056be
Signed-off-by: Lukas Sedlak <lsedlak@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentConnector.java

index fe8c4a1..6e4b2d8 100644 (file)
@@ -602,7 +602,7 @@ public class BindingIndependentConnector implements //
             final Optional<Class<? extends RpcService>> rpcInterface = mappingService.getRpcServiceClassFor(
                     name.getNamespace().toString(), name.getFormattedRevision());
             if (rpcInterface.isPresent()) {
-                getRpcForwarder(rpcInterface.get(), null).registerToBidningBroker();
+                getRpcForwarder(rpcInterface.get(), null).registerToBindingBroker();
             }
         }
 
@@ -621,6 +621,7 @@ public class BindingIndependentConnector implements //
         private final WeakHashMap<Method, RpcInvocationStrategy> strategiesByMethod = new WeakHashMap<>();
         private final RpcService proxy;
         private ObjectRegistration<?> forwarderRegistration;
+        private boolean registrationInProgress = false;
 
         public DomToBindingRpcForwarder(final Class<? extends RpcService> service) {
             this.rpcServiceType = new WeakReference<Class<? extends RpcService>>(service);
@@ -680,7 +681,8 @@ public class BindingIndependentConnector implements //
          *
          */
         public void registerToDOMBroker() {
-            if(forwarderRegistration == null) {
+            if(!registrationInProgress && forwarderRegistration == null) {
+                registrationInProgress = true;
                 CompositeObjectRegistrationBuilder<DomToBindingRpcForwarder> builder = CompositeObjectRegistration.builderFor(this);
                 try {
                     for (QName rpc : supportedRpcs) {
@@ -690,6 +692,7 @@ public class BindingIndependentConnector implements //
                     LOG.error("Could not forward Rpcs of type {}", rpcServiceType.get(), e);
                 }
                 this.forwarderRegistration = builder.toInstance();
+                registrationInProgress = false;
             }
         }
 
@@ -801,12 +804,15 @@ public class BindingIndependentConnector implements //
          * creating forwarding loop.
          *
          */
-        public void registerToBidningBroker() {
-            if(forwarderRegistration == null) {
+        public void registerToBindingBroker() {
+            if(!registrationInProgress && forwarderRegistration == null) {
                try {
+                   registrationInProgress = true;
                    this.forwarderRegistration = baRpcRegistry.addRpcImplementation((Class)rpcServiceType.get(), proxy);
                } catch (Exception e) {
                    LOG.error("Unable to forward RPCs for {}",rpcServiceType.get(),e);
+               } finally {
+                   registrationInProgress = false;
                }
             }
         }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.