2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.mdsal.dom.store.inmemory;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import javax.annotation.concurrent.NotThreadSafe;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 final class ForeignShardModificationContext {
21 private static final Logger LOG = LoggerFactory.getLogger(ForeignShardModificationContext.class);
22 private final DOMDataTreeIdentifier identifier;
23 private final DOMDataTreeShardProducer producer;
24 private DOMDataTreeShardWriteTransaction tx;
25 private DOMDataTreeWriteCursor cursor;
26 private volatile boolean notReady = true;
28 ForeignShardModificationContext(final DOMDataTreeIdentifier identifier, final DOMDataTreeShardProducer producer) {
29 this.identifier = Preconditions.checkNotNull(identifier);
30 this.producer = Preconditions.checkNotNull(producer);
33 DOMDataTreeWriteCursor getCursor() {
34 Preconditions.checkState(notReady, "Context %s has been readied", this);
38 tx = producer.createTransaction();
40 cursor = tx.createCursor(getIdentifier());
45 boolean isModified() {
51 // Idempotent, but emit a debug
52 LOG.debug("Duplicate ready() of context {}", this);
63 // TODO: it would be nice if we could clear this reference
68 DOMDataTreeIdentifier getIdentifier() {
72 ListenableFuture<Boolean> validate() {
76 ListenableFuture<Void> prepare() {
80 ListenableFuture<Void> submit() {
81 final ListenableFuture<Void> commit = tx.commit();
86 void closeForeignTransaction() {