1. Fixed not sending of events to the node that created the routing table entry 73/2973/2
authorBasheeruddin Ahmed <syedbahm@cisco.com>
Fri, 22 Nov 2013 03:32:17 +0000 (19:32 -0800)
committerBasheeruddin Ahmed <syedbahm@cisco.com>
Fri, 22 Nov 2013 04:51:41 +0000 (20:51 -0800)
2. Deprecated listener pattern and introduced the WB pattern based on code review
3. Included some documentation and logging package
4. Modified/Added unit test case

Change-Id: I1273b4c3a87180bae90419e3bdf55dca640cd899
Signed-off-by: Basheeruddin Ahmed <syedbahm@cisco.com>
opendaylight/distribution/opendaylight/src/main/resources/configuration/logback.xml
opendaylight/md-sal/zeromq-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTable.java
opendaylight/md-sal/zeromq-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/Activator.java
opendaylight/md-sal/zeromq-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImpl.java
opendaylight/md-sal/zeromq-routingtable/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImplTest.java
opendaylight/md-sal/zeromq-routingtable/integrationtest/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/ZeroMQRoutingTableTestIT.java

index c61b41c06542a24167fa863474b18198a7c32d3a..3ad0c61d4f66ffb8763354e65bc2d196d88929df 100644 (file)
@@ -62,6 +62,8 @@
   <logger name="org.opendaylight.controller.sal.implementation" level="INFO"/>
   <logger name="org.opendaylight.controller.sal.implementation.internal.Inventory" level="INFO"/>
   <logger name="org.opendaylight.controller.sal.implementation.internal.Topology" level="INFO"/>
   <logger name="org.opendaylight.controller.sal.implementation" level="INFO"/>
   <logger name="org.opendaylight.controller.sal.implementation.internal.Inventory" level="INFO"/>
   <logger name="org.opendaylight.controller.sal.implementation.internal.Topology" level="INFO"/>
+     <!-- zeromq router and zeromq routing table -->
+  <logger name="org.opendaylight.controller.sal.connector.remoterpc" level="INFO" />
   <!-- Functional Modules -->
   <logger name="org.opendaylight.controller.arphandler" level="INFO"/>
   <logger name="org.opendaylight.controller.hosttracker" level="INFO"/>
   <!-- Functional Modules -->
   <logger name="org.opendaylight.controller.arphandler" level="INFO"/>
   <logger name="org.opendaylight.controller.hosttracker" level="INFO"/>
index 97d2a6d02a40a054135b7bf390279fb669208f87..6ec4c2ce01f7ccb675873890a3ff80bfa6102963 100644 (file)
@@ -19,10 +19,12 @@ public interface RoutingTable<I,R> {
    *
    * @param routeId route identifier
    * @param route network address
    *
    * @param routeId route identifier
    * @param route network address
+   * @throws RoutingTableException for any logical exception
+   * @throws SystemException
    */
    */
-  public void addRoute(I routeId, R route) throws SystemException,  RoutingTableException;
+  public void addRoute(I routeId, R route) throws  RoutingTableException,SystemException;
 
 
-  /**
+    /**
    * Adds a network address for the route. If the route already exists,
    * it throws <code>DuplicateRouteException</code>.
    * This method would be used when registering a global service.
    * Adds a network address for the route. If the route already exists,
    * it throws <code>DuplicateRouteException</code>.
    * This method would be used when registering a global service.
@@ -31,6 +33,7 @@ public interface RoutingTable<I,R> {
    * @param routeId route identifier
    * @param route network address
    * @throws DuplicateRouteException
    * @param routeId route identifier
    * @param route network address
    * @throws DuplicateRouteException
+   * @throws RoutingTableException
    */
   public void addGlobalRoute(I routeId, R route) throws  RoutingTableException, SystemException;
 
    */
   public void addGlobalRoute(I routeId, R route) throws  RoutingTableException, SystemException;
 
@@ -50,8 +53,10 @@ public interface RoutingTable<I,R> {
      * Remove the route.
      * This method would be used when registering a global service.
      * @param routeId
      * Remove the route.
      * This method would be used when registering a global service.
      * @param routeId
+     * @throws RoutingTableException
+     * @throws SystemException
      */
      */
-    public void removeGlobalRoute(I routeId);
+    public void removeGlobalRoute(I routeId) throws RoutingTableException, SystemException;
 
   /**
    * Returns a set of network addresses associated with this route
 
   /**
    * Returns a set of network addresses associated with this route
@@ -69,6 +74,13 @@ public interface RoutingTable<I,R> {
    */
   public R getARoute(I routeId);
 
    */
   public R getARoute(I routeId);
 
+    /**
+     *
+     * This will be removed after listeners
+     * have made change on their end to use whiteboard pattern
+     * @deprecated
+     */
+
   public void registerRouteChangeListener(RouteChangeListener listener);
 
   public class DuplicateRouteException extends RoutingTableException {
   public void registerRouteChangeListener(RouteChangeListener listener);
 
   public class DuplicateRouteException extends RoutingTableException {
index 45414437ccb3d3afe6279fd1d428a8dc930d60fc..6e2d280a89f5158358c3d6757c7c1e4e2f72e64e 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.sal.connector.remoterpc.impl;
 import org.apache.felix.dm.Component;
 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
 import org.apache.felix.dm.Component;
 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
+import org.opendaylight.controller.sal.connector.remoterpc.api.RouteChangeListener;
 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable;
 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
 import org.slf4j.Logger;
 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable;
 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
 import org.slf4j.Logger;
@@ -72,6 +73,15 @@ public class Activator extends ComponentActivatorAbstractBase {
             c.setInterface(new String[] { RoutingTable.class.getName(),ICacheUpdateAware.class.getName()  }, props);
             logger.debug("configureGlobalInstance adding dependency:", IClusterGlobalServices.class);
 
             c.setInterface(new String[] { RoutingTable.class.getName(),ICacheUpdateAware.class.getName()  }, props);
             logger.debug("configureGlobalInstance adding dependency:", IClusterGlobalServices.class);
 
+
+            // RouteChangeListener services will be none or many so the
+            // dependency is optional
+            c.add(createServiceDependency()
+                    .setService(RouteChangeListener.class)
+                    .setCallbacks("setRouteChangeListener", "unsetRouteChangeListener")
+                    .setRequired(false));
+
+            //dependency is required as it provides us the caching support
             c.add(createServiceDependency().setService(
                     IClusterGlobalServices.class).setCallbacks(
                     "setClusterGlobalServices",
             c.add(createServiceDependency().setService(
                     IClusterGlobalServices.class).setCallbacks(
                     "setClusterGlobalServices",
index 558c8a80d32b59aaf092a4505e680c9eabb14190..4e1dfb00588a3e2ae566a744ea1f05eb51ca4bf1 100644 (file)
@@ -10,12 +10,16 @@ package org.opendaylight.controller.sal.connector.remoterpc.impl;
 
 import com.google.common.base.Preconditions;
 import org.apache.felix.dm.Component;
 
 import com.google.common.base.Preconditions;
 import org.apache.felix.dm.Component;
-import org.opendaylight.controller.clustering.services.*;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.CacheListenerAddException;
+import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
+import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
+import org.opendaylight.controller.clustering.services.IClusterServices;
 import org.opendaylight.controller.sal.connector.remoterpc.api.RouteChangeListener;
 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable;
 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableException;
 import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException;
 import org.opendaylight.controller.sal.connector.remoterpc.api.RouteChangeListener;
 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable;
 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableException;
 import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException;
-import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -23,243 +27,298 @@ import javax.transaction.HeuristicMixedException;
 import javax.transaction.HeuristicRollbackException;
 import javax.transaction.NotSupportedException;
 import javax.transaction.RollbackException;
 import javax.transaction.HeuristicRollbackException;
 import javax.transaction.NotSupportedException;
 import javax.transaction.RollbackException;
-import java.util.*;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 
 /**
  * @author: syedbahm
  */
 import java.util.concurrent.ConcurrentMap;
 
 /**
  * @author: syedbahm
  */
-public class RoutingTableImpl<I, R> implements RoutingTable<I, R>,ICacheUpdateAware<I,R> {
+public class RoutingTableImpl<I, R> implements RoutingTable<I, R>, ICacheUpdateAware<I, R> {
     public static final String ROUTING_TABLE_GLOBAL_CACHE = "routing_table_global_cache";
 
     public static final String ROUTING_TABLE_GLOBAL_CACHE = "routing_table_global_cache";
 
-  private Logger log = LoggerFactory
-            .getLogger(RoutingTableImpl.class);
-
-  private IClusterGlobalServices clusterGlobalServices = null;
-  private RoutingTableImpl routingTableInstance = null;
-  private ConcurrentMap routingTableCache = null;
-  private List<RouteChangeListener>  routeChangeListeners = new ArrayList<RouteChangeListener>();
-  private ServiceRegistration cacheAwareRegistration = null;
-                                                      
- public RoutingTableImpl() {
-  }
-
-  @Override
-  public void addRoute(I routeId, R route) throws RoutingTableException {
-       throw new UnsupportedOperationException(" Not implemented yet!");
-  }
-
-  @Override
-  public void addGlobalRoute(I routeId, R route) throws RoutingTableException, SystemException {
-    Preconditions.checkNotNull(routeId, "addGlobalRoute: routeId cannot be null!");
-    Preconditions.checkNotNull(route, "addGlobalRoute: route cannot be null!");
-    try {
-
-      Set<R> existingRoute = null;
-      // ok does the global route is already registered ?
-      if ((existingRoute = getRoutes(routeId)) == null) {
-
-          if(log.isDebugEnabled()){
-              log.debug("addGlobalRoute: adding  a new route with id"+ routeId + " and value = "+route);
-          }
-        // lets start a transaction
-        clusterGlobalServices.tbegin();
-        Set<R> routes  = new HashSet<R>();
-        routes.add(route);
-        routingTableCache.put(routeId, routes);
-        clusterGlobalServices.tcommit();
-      } else {
-        throw new DuplicateRouteException(" There is already existing route " + existingRoute);
-      }
-
-    } catch (NotSupportedException e) {
-      throw new RoutingTableException("Transaction error - while trying to create route id=" + routeId + "with route" + route, e);
-    } catch (HeuristicRollbackException e) {
-      throw new RoutingTableException("Transaction error - while trying to create route id=" + routeId + "with route" + route, e);
-    } catch (RollbackException e) {
-      throw new RoutingTableException("Transaction error - while trying to create route id=" + routeId + "with route" + route, e);
-    } catch (HeuristicMixedException e) {
-      throw new RoutingTableException("Transaction error - while trying to create route id=" + routeId + "with route" + route, e);
-    } catch (javax.transaction.SystemException e){
-        throw new SystemException ( "System error occurred - while trying to create with value",e);
+    private Logger log = LoggerFactory.getLogger(RoutingTableImpl.class);
+
+    private IClusterGlobalServices clusterGlobalServices = null;
+    private RoutingTableImpl routingTableInstance = null;
+    private ConcurrentMap routingTableCache = null;
+    private Set<RouteChangeListener> routeChangeListeners = Collections
+            .synchronizedSet(new HashSet<RouteChangeListener>());
+
+    public RoutingTableImpl() {
     }
 
     }
 
-  }
+    @Override
+    public void addRoute(I routeId, R route) throws RoutingTableException {
+        throw new UnsupportedOperationException(" Not implemented yet!");
+    }
 
 
-  @Override
-  public void removeRoute(I routeId, R route) {
-         throw new UnsupportedOperationException("Not implemented yet!");
-  }
     @Override
     @Override
-    public void removeGlobalRoute(I routeId) {
-        routingTableCache.remove(routeId);
+    public void addGlobalRoute(I routeId, R route) throws RoutingTableException, SystemException {
+        Preconditions.checkNotNull(routeId, "addGlobalRoute: routeId cannot be null!");
+        Preconditions.checkNotNull(route, "addGlobalRoute: route cannot be null!");
+        try {
+
+            Set<R> existingRoute = null;
+            // ok does the global route is already registered ?
+            if ((existingRoute = getRoutes(routeId)) == null) {
+
+                if (log.isDebugEnabled()) {
+                    log.debug("addGlobalRoute: adding  a new route with id" + routeId + " and value = "
+                            + route);
+                }
+                // lets start a transaction
+                clusterGlobalServices.tbegin();
+                Set<R> routes = new HashSet<R>();
+                routes.add(route);
+                routingTableCache.put(routeId, routes);
+                clusterGlobalServices.tcommit();
+            } else {
+                throw new DuplicateRouteException(" There is already existing route " + existingRoute);
+            }
+
+        } catch (NotSupportedException e) {
+            throw new RoutingTableException("Transaction error - while trying to create route id="
+                    + routeId + "with route" + route, e);
+        } catch (HeuristicRollbackException e) {
+            throw new RoutingTableException("Transaction error - while trying to create route id="
+                    + routeId + "with route" + route, e);
+        } catch (RollbackException e) {
+            throw new RoutingTableException("Transaction error - while trying to create route id="
+                    + routeId + "with route" + route, e);
+        } catch (HeuristicMixedException e) {
+            throw new RoutingTableException("Transaction error - while trying to create route id="
+                    + routeId + "with route" + route, e);
+        } catch (javax.transaction.SystemException e) {
+            throw new SystemException("System error occurred - while trying to create with value", e);
+        }
+
     }
 
     }
 
-  @Override
-  public Set<R> getRoutes(I routeId) {
+    @Override
+    public void removeRoute(I routeId, R route) {
+        throw new UnsupportedOperationException("Not implemented yet!");
+    }
 
 
-      //Note: currently works for global routes only wherein there is just single route
-      Preconditions.checkNotNull(routeId, "getARoute: routeId cannot be null!");
-      return (Set<R>) routingTableCache.get(routeId);
-  }
+    @Override
+    public void removeGlobalRoute(I routeId) throws RoutingTableException, SystemException {
+        Preconditions.checkNotNull(routeId, "removeGlobalRoute: routeId cannot be null!");
+        try {
+            if (log.isDebugEnabled()) {
+                log.debug("removeGlobalRoute: removing  a new route with id" + routeId);
+            }
+            // lets start a transaction
+            clusterGlobalServices.tbegin();
+
+            routingTableCache.remove(routeId);
+            clusterGlobalServices.tcommit();
+
+        } catch (NotSupportedException e) {
+            throw new RoutingTableException("Transaction error - while trying to remove route id="
+                    + routeId, e);
+        } catch (HeuristicRollbackException e) {
+            throw new RoutingTableException("Transaction error - while trying to remove route id="
+                    + routeId, e);
+        } catch (RollbackException e) {
+            throw new RoutingTableException("Transaction error - while trying to remove route id="
+                    + routeId, e);
+        } catch (HeuristicMixedException e) {
+            throw new RoutingTableException("Transaction error - while trying to remove route id="
+                    + routeId, e);
+        } catch (javax.transaction.SystemException e) {
+            throw new SystemException("System error occurred - while trying to remove with value", e);
+        }
+    }
 
 
-  @Override
-  public R getARoute(I routeId) {
-       throw new UnsupportedOperationException("Not implemented yet!");
-  }
+    @Override
+    public Set<R> getRoutes(I routeId) {
 
 
-  /**
-   * Registers listener for sending any change notification
-   * 
-   * @param listener
-   */
-  @Override
-  public void registerRouteChangeListener(RouteChangeListener listener) {
-      routeChangeListeners.add(listener);
-  }
+        // Note: currently works for global routes only wherein there is just single
+        // route
+        Preconditions.checkNotNull(routeId, "getARoute: routeId cannot be null!");
+        return (Set<R>) routingTableCache.get(routeId);
+    }
 
 
+    @Override
+    public R getARoute(I routeId) {
+        throw new UnsupportedOperationException("Not implemented yet!");
+    }
 
     /**
 
     /**
-     * Returning the list of route change listeners for Unit testing
-     * Note: the package scope is default
-     * @return   List of registered RouteChangeListener<I,R> listeners
+     * @deprecated doesn't do anything will be removed once listeners used
+     *             whiteboard pattern Registers listener for sending any change
+     *             notification
+     * @param listener
      */
      */
-  List<RouteChangeListener> getRegisteredRouteChangeListeners(){
-      return routeChangeListeners;
-  }
+    @Override
+    public void registerRouteChangeListener(RouteChangeListener listener) {
 
 
-  public void setClusterGlobalServices(IClusterGlobalServices clusterGlobalServices) {
-    this.clusterGlobalServices = clusterGlobalServices;
-  }
+    }
 
 
-  public void unsetClusterGlobalServices(IClusterGlobalServices clusterGlobalServices) {
-    if(cacheAwareRegistration != null) {
-        cacheAwareRegistration.unregister();
+    public void setRouteChangeListener(RouteChangeListener rcl) {
+        if(rcl != null){
+            routeChangeListeners.add(rcl);
+        }else{
+            log.warn("setRouteChangeListener called with null listener");
+        }
+    }
+
+    public void unSetRouteChangeListener(RouteChangeListener rcl) {
+        if(rcl != null){
+         routeChangeListeners.remove(rcl);
+        }else{
+            log.warn("unSetRouteChangeListener called with null listener");
+        }
     }
     }
-    this.clusterGlobalServices = null;
-  }
 
     /**
 
     /**
-     * Creates the Routing Table clustered global services cache
-     * @throws CacheExistException  -- cluster global services exception when cache exist
-     * @throws CacheConfigException -- cluster global services exception during cache config
-     * @throws CacheListenerAddException  -- cluster global services exception during adding of listener
+     * Returning the set of route change listeners for Unit testing Note: the
+     * package scope is default
+     *
+     * @return List of registered RouteChangeListener<I,R> listeners
      */
      */
+    Set<RouteChangeListener> getRegisteredRouteChangeListeners() {
+        return routeChangeListeners;
+    }
 
 
-  void createRoutingTableCache() throws CacheExistException, CacheConfigException, CacheListenerAddException {
-    // TBD: HOW DO WE DECIDE ON PROPERTIES OF THE CACHE i.e. what duration it
-    // should be caching?
-
-    // let us check here if the cache already exists -- if so don't create
-    if (!clusterGlobalServices.existCache(
-        ROUTING_TABLE_GLOBAL_CACHE)) {
+    public void setClusterGlobalServices(IClusterGlobalServices clusterGlobalServices) {
+        this.clusterGlobalServices = clusterGlobalServices;
+    }
 
 
-        if(log.isDebugEnabled()){
-            log.debug("createRoutingTableCache: creating a new routing table cache "+ROUTING_TABLE_GLOBAL_CACHE );
-        }
-      routingTableCache = clusterGlobalServices.createCache(
-          ROUTING_TABLE_GLOBAL_CACHE, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-    } else {
-        if(log.isDebugEnabled()){
-            log.debug("createRoutingTableCache: found existing routing table cache "+ROUTING_TABLE_GLOBAL_CACHE );
+    public void unsetClusterGlobalServices(IClusterGlobalServices clusterGlobalServices) {
+        if((clusterGlobalServices != null ) &&  (this.clusterGlobalServices.equals(clusterGlobalServices))){
+            this.clusterGlobalServices = null;
         }
         }
-      routingTableCache = clusterGlobalServices.getCache(
-          ROUTING_TABLE_GLOBAL_CACHE);
     }
 
     }
 
-  }
-
-  /**
-   * Function called by the dependency manager when all the required
-   * dependencies are satisfied
-   * 
-   */
-  void init(Component c) {
-    try {
-
-      createRoutingTableCache();
-    } catch (CacheExistException e) {
-      throw new IllegalStateException("could not construct routing table cache");
-    } catch (CacheConfigException e) {
-      throw new IllegalStateException("could not construct routing table cache");
-    } catch (CacheListenerAddException e) {
-        throw new IllegalStateException("could not construct routing table cache");
+    /**
+     * Creates the Routing Table clustered global services cache
+     *
+     * @throws CacheExistException
+     *           -- cluster global services exception when cache exist
+     * @throws CacheConfigException
+     *           -- cluster global services exception during cache config
+     * @throws CacheListenerAddException
+     *           -- cluster global services exception during adding of listener
+     */
+
+    void createRoutingTableCache() throws CacheExistException, CacheConfigException,
+            CacheListenerAddException {
+        // TBD: HOW DO WE DECIDE ON PROPERTIES OF THE CACHE i.e. what duration it
+        // should be caching?
+
+        // let us check here if the cache already exists -- if so don't create
+        if (!clusterGlobalServices.existCache(ROUTING_TABLE_GLOBAL_CACHE)) {
+
+            if (log.isDebugEnabled()) {
+                log.debug("createRoutingTableCache: creating a new routing table cache "
+                        + ROUTING_TABLE_GLOBAL_CACHE);
+            }
+            routingTableCache = clusterGlobalServices.createCache(ROUTING_TABLE_GLOBAL_CACHE,
+                    EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("createRoutingTableCache: found existing routing table cache "
+                        + ROUTING_TABLE_GLOBAL_CACHE);
+            }
+            routingTableCache = clusterGlobalServices.getCache(ROUTING_TABLE_GLOBAL_CACHE);
+        }
+
     }
     }
-  }
 
 
+    /**
+     * Function called by the dependency manager when all the required
+     * dependencies are satisfied
+     *
+     */
+    void init(Component c) {
+        try {
+
+            createRoutingTableCache();
+        } catch (CacheExistException e) {
+            throw new IllegalStateException("could not construct routing table cache");
+        } catch (CacheConfigException e) {
+            throw new IllegalStateException("could not construct routing table cache");
+        } catch (CacheListenerAddException e) {
+            throw new IllegalStateException("could not construct routing table cache");
+        }
+    }
 
     /**
 
     /**
-     * Get routing table method is useful for unit testing
-     * <note>It has package scope</note>
+     * Get routing table method is useful for unit testing <note>It has package
+     * scope</note>
      */
      */
-    ConcurrentMap getRoutingTableCache(){
+    ConcurrentMap getRoutingTableCache() {
         return this.routingTableCache;
     }
 
         return this.routingTableCache;
     }
 
+    /**
+     * Invoked when a new entry is available in the cache, the key is only
+     * provided, the value will come as an entryUpdate invocation
+     *
+     * @param key
+     *          Key for the entry just created
+     * @param cacheName
+     *          name of the cache for which update has been received
+     * @param originLocal
+     *          true if the event is generated from this node
+     */
+    @Override
+    public void entryCreated(I key, String cacheName, boolean originLocal) {
+        // TBD: do we require this.
+        if (log.isDebugEnabled()) {
+            log.debug("RoutingTableUpdates: entryCreated  routeId = " + key + " cacheName=" + cacheName);
+        }
+    }
 
 
-      /**
-       * Invoked when a new entry is available in the cache, the key is
-       * only provided, the value will come as an entryUpdate invocation
-       *
-       * @param key         Key for the entry just created
-       * @param cacheName   name of the cache for which update has been
-       *                    received
-       * @param originLocal true if the event is generated from this
-       *                    node
-       */
-      @Override
-      public void entryCreated(I key, String cacheName, boolean originLocal) {
-          //TBD: do we require this.
-          if(log.isDebugEnabled()){
-              log.debug("RoutingTableUpdates: entryCreated  routeId = "+key
-                      + " cacheName="+cacheName
-                      );
-          }
-      }
-
-      /**
-       * Called anytime a given entry is updated
-       *
-       * @param key         Key for the entry modified
-       * @param new_value   the new value the key will have
-       * @param cacheName   name of the cache for which update has been
-       *                    received
-       * @param originLocal true if the event is generated from this
-       *                    node
-       */
-      @Override
-      public void entryUpdated(I key, R new_value, String cacheName, boolean originLocal) {
-          if(log.isDebugEnabled()){
-              log.debug("RoutingTableUpdates: entryUpdated  routeId = "+key
-                      + ",value = "+ new_value
-                      + " ,cacheName="+cacheName
-                      );
-          }
-          for(RouteChangeListener rcl:routeChangeListeners){
-              rcl.onRouteUpdated(key, new_value);
-          }
-      }
-
-      /**
-       * Called anytime a given key is removed from the
-       * ConcurrentHashMap we are listening to.
-       *
-       * @param key         Key of the entry removed
-       * @param cacheName   name of the cache for which update has been
-       *                    received
-       * @param originLocal true if the event is generated from this
-       *                    node
-       */
-      @Override
-      public void entryDeleted(I key, String cacheName, boolean originLocal) {
-          if(log.isDebugEnabled()){
-              log.debug("RoutingTableUpdates: entryUpdated  routeId = "+key
-                      + " local = "+ originLocal
-                      + " cacheName="+cacheName
-                       );
-          }
-          for(RouteChangeListener rcl:routeChangeListeners){
-              rcl.onRouteDeleted(key);
-          }
-      }
-  }
\ No newline at end of file
+    /**
+     * Called anytime a given entry is updated
+     *
+     * @param key
+     *          Key for the entry modified
+     * @param new_value
+     *          the new value the key will have
+     * @param cacheName
+     *          name of the cache for which update has been received
+     * @param originLocal
+     *          true if the event is generated from this node
+     */
+    @Override
+    public void entryUpdated(I key, R new_value, String cacheName, boolean originLocal) {
+        if (log.isDebugEnabled()) {
+            log.debug("RoutingTableUpdates: entryUpdated  routeId = " + key + ",value = " + new_value
+                    + " ,cacheName=" + cacheName + " originLocal="+originLocal);
+        }
+        if (!originLocal) {
+            for (RouteChangeListener rcl : routeChangeListeners) {
+                rcl.onRouteUpdated(key, new_value);
+            }
+        }
+    }
+
+    /**
+     * Called anytime a given key is removed from the ConcurrentHashMap we are
+     * listening to.
+     *
+     * @param key
+     *          Key of the entry removed
+     * @param cacheName
+     *          name of the cache for which update has been received
+     * @param originLocal
+     *          true if the event is generated from this node
+     */
+    @Override
+    public void entryDeleted(I key, String cacheName, boolean originLocal) {
+        if (log.isDebugEnabled()) {
+            log.debug("RoutingTableUpdates: entryUpdated  routeId = " + key + " local = " + originLocal
+                    + " cacheName=" + cacheName + " originLocal="+originLocal);
+        }
+        if (!originLocal) {
+            for (RouteChangeListener rcl : routeChangeListeners) {
+                rcl.onRouteDeleted(key);
+            }
+        }
+    }
+}
\ No newline at end of file
index 75cc6f5da811a5c073071a71bb0fecf1e256455d..2ef251d9a1f0a642020b2b5d9299970bdf429189 100644 (file)
@@ -103,7 +103,12 @@ public class RoutingTableImplTest {
         Assert.assertEquals(rti.getRegisteredRouteChangeListeners().size(),0);
         rti.registerRouteChangeListener(new RouteChangeListenerImpl());
 
         Assert.assertEquals(rti.getRegisteredRouteChangeListeners().size(),0);
         rti.registerRouteChangeListener(new RouteChangeListenerImpl());
 
-        Assert.assertEquals(rti.getRegisteredRouteChangeListeners().size(),1);
+        Assert.assertEquals(rti.getRegisteredRouteChangeListeners().size(),0); //old should not work
+        //what about the new approach - using whiteboard pattern
+        rti.setRouteChangeListener(new RouteChangeListenerImpl());
+
+        Assert.assertEquals(rti.getRegisteredRouteChangeListeners().size(),1); //should not work
+
 
     }
     @Test
 
     }
     @Test
index 3b6d398511304f1fc2e3cf23361d977c83d40ebf..a7929e82fce2bce0b9895e2db666afbd26d0f16d 100644 (file)
@@ -21,7 +21,6 @@ import java.io.Serializable;
 import java.net.URI;
 import java.util.Set;
 
 import java.net.URI;
 import java.util.Set;
 
-
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
@@ -41,6 +40,7 @@ public class
     public static final String YANG = "org.opendaylight.yangtools";
     public static final String CONTROLLER = "org.opendaylight.controller";
     public static final String YANGTOOLS = "org.opendaylight.yangtools";
     public static final String YANG = "org.opendaylight.yangtools";
     public static final String CONTROLLER = "org.opendaylight.controller";
     public static final String YANGTOOLS = "org.opendaylight.yangtools";
+    RoutingIdentifierImpl rii  = new RoutingIdentifierImpl();
     // get the OSGI bundle context
     @Inject
     private BundleContext bc;
     // get the OSGI bundle context
     @Inject
     private BundleContext bc;
@@ -171,9 +171,6 @@ public class
 
                 mavenBundle(YANGTOOLS + ".thirdparty", "antlr4-runtime-osgi-nohead").versionAsInProject(), //
 
 
                 mavenBundle(YANGTOOLS + ".thirdparty", "antlr4-runtime-osgi-nohead").versionAsInProject(), //
 
-                mavenBundle(YANG, "concepts").versionAsInProject(),
-                mavenBundle(YANG, "yang-binding").versionAsInProject(), //
-                mavenBundle(YANG, "yang-common").versionAsInProject(), //
                 mavenBundle(YANG+".thirdparty", "xtend-lib-osgi").versionAsInProject(),
                 mavenBundle("com.google.guava", "guava").versionAsInProject(), //
                 mavenBundle("org.javassist", "javassist").versionAsInProject(),
                 mavenBundle(YANG+".thirdparty", "xtend-lib-osgi").versionAsInProject(),
                 mavenBundle("com.google.guava", "guava").versionAsInProject(), //
                 mavenBundle("org.javassist", "javassist").versionAsInProject(),
@@ -248,7 +245,7 @@ public class
 
     @Test
   public  void testAddGlobalRoute () throws Exception{
 
     @Test
   public  void testAddGlobalRoute () throws Exception{
-       RoutingIdentifierImpl rii  = new RoutingIdentifierImpl();
+
        routingTable.addGlobalRoute(rii,"172.27.12.1:5000");
 
        Set<String> routes = routingTable.getRoutes(rii);
        routingTable.addGlobalRoute(rii,"172.27.12.1:5000");
 
        Set<String> routes = routingTable.getRoutes(rii);
@@ -261,6 +258,20 @@ public class
     }
 
 
     }
 
 
+    @Test
+    public  void testDeleteGlobalRoute () throws Exception{
+
+        routingTable.removeGlobalRoute(rii);
+
+        Set<String> routes = routingTable.getRoutes(rii);
+
+        Assert.assertNull(routes);
+
+
+    }
+
+
+
    class RoutingIdentifierImpl implements RpcRouter.RouteIdentifier,Serializable {
 
        private final URI namespace = URI.create("http://cisco.com/example");
    class RoutingIdentifierImpl implements RpcRouter.RouteIdentifier,Serializable {
 
        private final URI namespace = URI.create("http://cisco.com/example");
@@ -281,6 +292,28 @@ public class
        public org.opendaylight.yangtools.yang.data.api.InstanceIdentifier getRoute() {
            return InstanceIdentifier.of(instance);
        }
        public org.opendaylight.yangtools.yang.data.api.InstanceIdentifier getRoute() {
            return InstanceIdentifier.of(instance);
        }
+
+       @Override
+       public boolean equals(Object o) {
+           if (this == o) return true;
+           if (o == null || getClass() != o.getClass()) return false;
+
+           RoutingIdentifierImpl that = (RoutingIdentifierImpl) o;
+
+           if (QNAME != null ? !QNAME.equals(that.QNAME) : that.QNAME != null) return false;
+           if (instance != null ? !instance.equals(that.instance) : that.instance != null) return false;
+           if (namespace != null ? !namespace.equals(that.namespace) : that.namespace != null) return false;
+
+           return true;
+       }
+
+       @Override
+       public int hashCode() {
+           int result = namespace != null ? namespace.hashCode() : 0;
+           result = 31 * result + (QNAME != null ? QNAME.hashCode() : 0);
+           result = 31 * result + (instance != null ? instance.hashCode() : 0);
+           return result;
+       }
    }
 
 
    }