Route store delegation fix

RouteStoreImpl should pass the delegation to the underlying LocalRouteStore or DistributedRouteStore

Change-Id: If9aebfdf9d3958da4ee820141db0e3fbf34f8261
diff --git a/incubator/store/src/main/java/org/onosproject/incubator/store/routing/impl/RouteStoreImpl.java b/incubator/store/src/main/java/org/onosproject/incubator/store/routing/impl/RouteStoreImpl.java
index 0699715..747007e 100644
--- a/incubator/store/src/main/java/org/onosproject/incubator/store/routing/impl/RouteStoreImpl.java
+++ b/incubator/store/src/main/java/org/onosproject/incubator/store/routing/impl/RouteStoreImpl.java
@@ -44,6 +44,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import static com.google.common.base.Preconditions.checkState;
+
 /**
  * An implementation of RouteStore that is backed by either LocalRouteStore or
  * DistributedRouteStore according to configuration.
@@ -101,12 +103,14 @@
                 }
                 currentRouteStore = new DistributedRouteStore(storageService);
                 ((DistributedRouteStore) currentRouteStore).activate();
+                ((DistributedRouteStore) currentRouteStore).setDelegate(delegate);
             } else {
                 if (currentRouteStore != null) {
                     ((DistributedRouteStore) currentRouteStore).deactivate();
                 }
                 currentRouteStore = new LocalRouteStore();
                 ((LocalRouteStore) currentRouteStore).activate();
+                ((LocalRouteStore) currentRouteStore).setDelegate(delegate);
             }
 
             this.distributed = expectDistributed;
@@ -116,6 +120,26 @@
     }
 
     @Override
+    public void setDelegate(RouteStoreDelegate delegate) {
+        checkState(this.delegate == null || this.delegate == delegate,
+                "Store delegate already set");
+        this.delegate = delegate;
+
+        // Set the delegate of underlying route store implementation
+        currentRouteStore.setDelegate(delegate);
+    }
+
+    @Override
+    public void unsetDelegate(RouteStoreDelegate delegate) {
+        if (this.delegate == delegate) {
+            this.delegate = null;
+        }
+
+        // Unset the delegate of underlying route store implementation
+        currentRouteStore.unsetDelegate(delegate);
+    }
+
+    @Override
     public void updateRoute(Route route) {
         currentRouteStore.updateRoute(route);
     }