Bump versions to 4.0.0-SNAPSHOT
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / DistributedShardModification.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 package org.opendaylight.controller.cluster.sharding;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Map;
13 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
15 import org.opendaylight.mdsal.dom.spi.shard.ForeignShardModificationContext;
16 import org.opendaylight.mdsal.dom.spi.shard.WritableNodeOperation;
17 import org.opendaylight.mdsal.dom.spi.shard.WriteCursorStrategy;
18 import org.opendaylight.mdsal.dom.spi.shard.WriteableModificationNode;
19 import org.opendaylight.mdsal.dom.spi.shard.WriteableNodeWithSubshard;
20 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
22
23 /**
24  * Shard modification that consists of the whole shard context, provides cursors which correctly delegate to subshards
25  * if any are present.
26  */
27 @Deprecated(forRemoval = true)
28 public class DistributedShardModification extends WriteableNodeWithSubshard {
29
30     private final DistributedShardModificationContext context;
31     private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards;
32
33     public DistributedShardModification(final DistributedShardModificationContext context,
34                                         final Map<PathArgument, WriteableModificationNode> subshards,
35                                         final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards) {
36         super(subshards);
37         this.context = requireNonNull(context);
38         this.childShards = requireNonNull(childShards);
39     }
40
41     @Override
42     public PathArgument getIdentifier() {
43         return context.getIdentifier().getRootIdentifier().getLastPathArgument();
44     }
45
46     @Override
47     public WriteCursorStrategy createOperation(final DOMDataTreeWriteCursor parentCursor) {
48         return new WritableNodeOperation(this, context.cursor()) {
49             @Override
50             public void exit() {
51                 throw new IllegalStateException("Can not exit data tree root");
52             }
53         };
54     }
55
56     void cursorClosed() {
57         context.closeCursor();
58     }
59
60     DOMStoreThreePhaseCommitCohort seal() {
61         childShards.values().stream().filter(ForeignShardModificationContext::isModified)
62                 .forEach(ForeignShardModificationContext::ready);
63
64         return context.ready();
65     }
66
67     DOMDataTreeIdentifier getPrefix() {
68         return context.getIdentifier();
69     }
70
71     Map<DOMDataTreeIdentifier, ForeignShardModificationContext> getChildShards() {
72         return childShards;
73     }
74 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.