BUG 2138: Introduce DistributedShardedDOMDataTree
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / ShardProxyProducer.java
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardProxyProducer.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardProxyProducer.java
new file mode 100644 (file)
index 0000000..f977076
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.cluster.sharding;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.mdsal.dom.spi.shard.DOMDataTreeShardProducer;
+import org.opendaylight.mdsal.dom.spi.shard.DOMDataTreeShardWriteTransaction;
+
+/**
+ * Proxy producer implementation that creates transactions that forward all calls to {@link DataStoreClient}.
+ */
+class ShardProxyProducer implements DOMDataTreeShardProducer {
+
+    private final DOMDataTreeIdentifier shardRoot;
+    private final Collection<DOMDataTreeIdentifier> prefixes;
+    private final DataStoreClient client;
+
+    ShardProxyProducer(final DOMDataTreeIdentifier shardRoot, final Collection<DOMDataTreeIdentifier> prefixes,
+                       final DataStoreClient client) {
+        this.shardRoot = Preconditions.checkNotNull(shardRoot);
+        this.prefixes = ImmutableList.copyOf(Preconditions.checkNotNull(prefixes));
+        this.client = Preconditions.checkNotNull(client);
+    }
+
+    @Nonnull
+    @Override
+    public Collection<DOMDataTreeIdentifier> getPrefixes() {
+        return prefixes;
+    }
+
+    @Override
+    public DOMDataTreeShardWriteTransaction createTransaction() {
+        return new ShardProxyTransaction(shardRoot, prefixes, client);
+    }
+}
+