Bug 7407 - Add request leadership functionality to shards
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / DistributedShardFrontend.java
index 8edfddedf49be40e3a51e584ab9cd905d03fb3ca..f6060a89fda05ab2972b965687c9694fed552d60 100644 (file)
@@ -45,20 +45,23 @@ class DistributedShardFrontend implements ReadableWriteableDOMDataTreeShard {
     private final Map<DOMDataTreeIdentifier, ChildShardContext> childShards = new HashMap<>();
     @GuardedBy("this")
     private final List<ShardProxyProducer> producers = new ArrayList<>();
-    private final DistributedDataStore distributedDataStore;
+
+    private final DistributedShardChangePublisher publisher;
 
     DistributedShardFrontend(final DistributedDataStore distributedDataStore,
                              final DataStoreClient client,
                              final DOMDataTreeIdentifier shardRoot) {
-        this.distributedDataStore = Preconditions.checkNotNull(distributedDataStore);
         this.client = Preconditions.checkNotNull(client);
         this.shardRoot = Preconditions.checkNotNull(shardRoot);
+
+        publisher = new DistributedShardChangePublisher(client, Preconditions.checkNotNull(distributedDataStore),
+                shardRoot, childShards);
     }
 
     @Override
     public synchronized DOMDataTreeShardProducer createProducer(final Collection<DOMDataTreeIdentifier> paths) {
         for (final DOMDataTreeIdentifier prodPrefix : paths) {
-            Preconditions.checkArgument(paths.contains(prodPrefix), "Prefix %s is not contained under shard root",
+            Preconditions.checkArgument(shardRoot.contains(prodPrefix), "Prefix %s is not contained under shard root",
                     prodPrefix, paths);
         }
 
@@ -134,9 +137,9 @@ class DistributedShardFrontend implements ReadableWriteableDOMDataTreeShard {
 
     @Nonnull
     @Override
+    @SuppressWarnings("unchecked")
     public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerTreeChangeListener(
             final YangInstanceIdentifier treeId, final L listener) {
-        throw new UnsupportedOperationException("Listener registration not supported");
+        return publisher.registerTreeChangeListener(treeId, listener);
     }
-
 }