Fixed bug when global RPCs we're not forwarded 80/4580/3
authorTony Tkacik <ttkacik@cisco.com>
Wed, 22 Jan 2014 13:41:40 +0000 (14:41 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 22 Jan 2014 21:34:19 +0000 (22:34 +0100)
Change-Id: I2220530609cdbc02549637f92dd550ff657816d6
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/RpcProviderRegistry.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProviderRegistryImpl.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentConnector.java

index cc764888cca932b89dacfe8210c6671147bc5f9d..0fa85d530e87a8d138d65b038305cdcf8e7176ca 100644 (file)
@@ -4,6 +4,7 @@ import org.opendaylight.controller.md.sal.common.api.routing.RouteChangePublishe
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
 import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 
index ffc72657f0e3ef406961738c6c3598ac044ecd9e..f93457110181967063ec64c27a3f29c026320121 100644 (file)
@@ -56,6 +56,8 @@ public class RpcProviderRegistryImpl implements //
 
     private final String name;
 
+    private ListenerRegistry<GlobalRpcRegistrationListener> globalRpcListeners = ListenerRegistry.create();
+
     public String getName() {
         return name;
     }
@@ -86,6 +88,7 @@ public class RpcProviderRegistryImpl implements //
         checkState(currentDelegate == null, "Rpc service is already registered");
         LOG.debug("Registering {} as global implementation of {} in {}", implementation, type.getSimpleName(), this);
         RuntimeCodeHelper.setDelegate(publicProxy, implementation);
+        notifyGlobalRpcAdded(type);
         return new RpcProxyRegistration<T>(type, implementation, this);
     }
 
@@ -140,6 +143,17 @@ public class RpcProviderRegistryImpl implements //
         }
     }
 
+    private void notifyGlobalRpcAdded(Class<? extends RpcService> type) {
+        for(ListenerRegistration<GlobalRpcRegistrationListener> listener : globalRpcListeners) {
+            try {
+                listener.getInstance().onGlobalRpcRegistered(type);
+            } catch (Exception e) {
+                LOG.error("Unhandled exception during invoking listener {}", e);
+            }
+        }
+        
+    }
+
     private void notifyListenersRoutedCreated(RpcRouter router) {
 
         for (ListenerRegistration<RouterInstantiationListener> listener : routerInstantiationListener) {
@@ -182,6 +196,16 @@ public class RpcProviderRegistryImpl implements //
     public interface RouterInstantiationListener extends EventListener {
         void onRpcRouterCreated(RpcRouter<?> router);
     }
+    
+    public ListenerRegistration<GlobalRpcRegistrationListener> registerGlobalRpcRegistrationListener(GlobalRpcRegistrationListener listener) {
+        return globalRpcListeners.register(listener);
+    }
+
+    public interface GlobalRpcRegistrationListener extends EventListener {
+        void onGlobalRpcRegistered(Class<? extends RpcService> cls);
+        void onGlobalRpcUnregistered(Class<? extends RpcService> cls);
+        
+    }
 
     private class RouteChangeForwarder<T extends RpcService> implements
             RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>> {
index 7ec1f6512d27a165d878973c79668d679d7f3ee9..1d6c271f9f4d0188a594ae603437d566585f583a 100644 (file)
@@ -43,6 +43,7 @@ import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider;
 import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier;
 import org.opendaylight.controller.sal.binding.api.rpc.RpcRouter;
 import org.opendaylight.controller.sal.binding.impl.RpcProviderRegistryImpl;
+import org.opendaylight.controller.sal.binding.impl.RpcProviderRegistryImpl.GlobalRpcRegistrationListener;
 import org.opendaylight.controller.sal.binding.impl.RpcProviderRegistryImpl.RouterInstantiationListener;
 import org.opendaylight.controller.sal.common.util.CommitHandlerTransactions;
 import org.opendaylight.controller.sal.common.util.Rpcs;
@@ -304,6 +305,7 @@ public class BindingIndependentConnector implements //
             if (baRpcRegistry instanceof RpcProviderRegistryImpl) {
                 baRpcRegistryImpl = (RpcProviderRegistryImpl) baRpcRegistry;
                 baRpcRegistryImpl.registerRouterInstantiationListener(domToBindingRpcManager.getInstance());
+                baRpcRegistryImpl.registerGlobalRpcRegistrationListener(domToBindingRpcManager.getInstance());
             }
             if(biRpcRegistry instanceof org.opendaylight.controller.sal.dom.broker.spi.RpcRouter) {
                 biRouter = (org.opendaylight.controller.sal.dom.broker.spi.RpcRouter) biRpcRegistry;
@@ -502,7 +504,8 @@ public class BindingIndependentConnector implements //
      */
     private class DomToBindingRpcForwardingManager implements
             RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>,
-            RouterInstantiationListener {
+            RouterInstantiationListener,
+            GlobalRpcRegistrationListener {
 
         private final Map<Class<? extends RpcService>, DomToBindingRpcForwarder> forwarders = new WeakHashMap<>();
         private RpcProviderRegistryImpl registryImpl;
@@ -515,6 +518,15 @@ public class BindingIndependentConnector implements //
             this.registryImpl = registryImpl;
         }
         
+        @Override
+        public void onGlobalRpcRegistered(Class<? extends RpcService> cls) {
+            getRpcForwarder(cls, null);
+        }
+        
+        @Override
+        public void onGlobalRpcUnregistered(Class<? extends RpcService> cls) {
+            // NOOP
+        }
         
         @Override
         public void onRpcRouterCreated(RpcRouter<?> router) {