Cache MapJoiner
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / DistributedShardModificationFactory.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.annotations.VisibleForTesting;
12 import com.google.common.base.Preconditions;
13 import com.google.common.collect.ImmutableMap;
14 import java.util.Map;
15 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
17 import org.opendaylight.mdsal.dom.spi.shard.ForeignShardModificationContext;
18 import org.opendaylight.mdsal.dom.spi.shard.WriteableModificationNode;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
20
21 /**
22  * Factory for {@link DistributedShardModification}.
23  */
24 public final class DistributedShardModificationFactory {
25     private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards;
26     private final Map<PathArgument, WriteableModificationNode> children;
27     private final DOMDataTreeIdentifier root;
28
29     DistributedShardModificationFactory(final DOMDataTreeIdentifier root,
30                                         final Map<PathArgument, WriteableModificationNode> children,
31                                         final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards) {
32         this.root = Preconditions.checkNotNull(root);
33         this.children = ImmutableMap.copyOf(children);
34         this.childShards = ImmutableMap.copyOf(childShards);
35     }
36
37     @VisibleForTesting
38     Map<PathArgument, WriteableModificationNode> getChildren() {
39         return children;
40     }
41
42     @VisibleForTesting
43     Map<DOMDataTreeIdentifier, ForeignShardModificationContext> getChildShards() {
44         return childShards;
45     }
46
47     DistributedShardModification createModification(final ClientTransaction transaction) {
48         return new DistributedShardModification(
49                 new DistributedShardModificationContext(transaction, root), children, childShards);
50     }
51 }