BUG-2138: Create DistributedShardFrontend
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / DistributedShardModificationContext.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 org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
12 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
13 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
14 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
15
16 /**
17  * The context for a single shards modification, keeps a ClientTransaction so it can route requests correctly.
18  */
19 public class DistributedShardModificationContext {
20
21     private ClientTransaction transaction;
22     private DOMDataTreeIdentifier identifier;
23     private DOMDataTreeWriteCursor cursor;
24
25     public DistributedShardModificationContext(final ClientTransaction transaction,
26                                                final DOMDataTreeIdentifier identifier) {
27         this.transaction = transaction;
28         this.identifier = identifier;
29     }
30
31     public DOMDataTreeIdentifier getIdentifier() {
32         return identifier;
33     }
34
35     DOMDataTreeWriteCursor cursor() {
36         if (cursor == null) {
37             cursor = transaction.openCursor();
38         }
39
40         return cursor;
41     }
42
43     DOMStoreThreePhaseCommitCohort ready() {
44         if (cursor != null) {
45             cursor.close();
46             cursor = null;
47         }
48
49         return transaction.ready();
50     }
51
52     void closeCursor() {
53         if (cursor != null) {
54             cursor.close();
55             cursor = null;
56         }
57     }
58
59 }

©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.