BUG 2138: Introduce DistributedShardedDOMDataTree
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / ShardProxyProducer.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.sharding;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableList;
13 import java.util.Collection;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
17 import org.opendaylight.mdsal.dom.spi.shard.DOMDataTreeShardProducer;
18 import org.opendaylight.mdsal.dom.spi.shard.DOMDataTreeShardWriteTransaction;
19
20 /**
21  * Proxy producer implementation that creates transactions that forward all calls to {@link DataStoreClient}.
22  */
23 class ShardProxyProducer implements DOMDataTreeShardProducer {
24
25     private final DOMDataTreeIdentifier shardRoot;
26     private final Collection<DOMDataTreeIdentifier> prefixes;
27     private final DataStoreClient client;
28
29     ShardProxyProducer(final DOMDataTreeIdentifier shardRoot, final Collection<DOMDataTreeIdentifier> prefixes,
30                        final DataStoreClient client) {
31         this.shardRoot = Preconditions.checkNotNull(shardRoot);
32         this.prefixes = ImmutableList.copyOf(Preconditions.checkNotNull(prefixes));
33         this.client = Preconditions.checkNotNull(client);
34     }
35
36     @Nonnull
37     @Override
38     public Collection<DOMDataTreeIdentifier> getPrefixes() {
39         return prefixes;
40     }
41
42     @Override
43     public DOMDataTreeShardWriteTransaction createTransaction() {
44         return new ShardProxyTransaction(shardRoot, prefixes, client);
45     }
46 }
47