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
8 package org.opendaylight.mdsal.dom.spi.shard;
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
17 import org.opendaylight.yangtools.concepts.Identifiable;
18 import org.opendaylight.yangtools.concepts.Mutable;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * A handle for a transaction being done on a different shard. This class is not thread-safe.
25 * @deprecated This interface is scheduled for removal in the next major release.
27 @Deprecated(forRemoval = true)
29 public final class ForeignShardModificationContext implements Identifiable<DOMDataTreeIdentifier>, Mutable {
30 private static final Logger LOG = LoggerFactory.getLogger(ForeignShardModificationContext.class);
32 private final DOMDataTreeIdentifier identifier;
33 private final DOMDataTreeShardProducer producer;
35 private DOMDataTreeShardWriteTransaction tx;
36 private DOMDataTreeWriteCursor cursor;
38 private volatile boolean ready = false;
40 public ForeignShardModificationContext(final DOMDataTreeIdentifier identifier,
41 final DOMDataTreeShardProducer producer) {
42 this.identifier = requireNonNull(identifier);
43 this.producer = requireNonNull(producer);
46 public DOMDataTreeWriteCursor getCursor() {
47 checkState(!ready, "Context %s has been readied", this);
51 tx = producer.createTransaction();
53 cursor = tx.createCursor(getIdentifier());
58 public boolean isModified() {
64 // Idempotent, but emit a debug
65 LOG.debug("Duplicate ready() of context {}", this);
76 // TODO: it would be nice if we could clear this reference
82 public DOMDataTreeIdentifier getIdentifier() {
86 public DOMDataTreeShardProducer getProducer() {
90 public ListenableFuture<Boolean> validate() {
94 public ListenableFuture<Void> prepare() {
98 public ListenableFuture<Void> submit() {
99 checkState(ready, "Modification context %s has to be ready before submit", this);
100 final ListenableFuture<Void> commit = tx.commit();
106 public void closeForeignTransaction() {
107 if (cursor != null) {