2 * Copyright (c) 2015 Brocade Communications 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.controller.cluster.datastore;
10 import akka.actor.ActorSelection;
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import com.google.common.util.concurrent.FutureCallback;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.SettableFuture;
16 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import scala.concurrent.Future;
23 * Processes front-end transaction operations locally before being committed to the destination shard.
24 * Instances of this class are used when the destination shard is local to the caller.
26 * @author Thomas Pantelis
28 final class LocalTransactionContext extends AbstractTransactionContext {
29 private final DOMStoreReadWriteTransaction delegate;
30 private final OperationCompleter completer;
32 LocalTransactionContext(TransactionIdentifier identifier, DOMStoreReadWriteTransaction delegate, OperationCompleter completer) {
34 this.delegate = Preconditions.checkNotNull(delegate);
35 this.completer = Preconditions.checkNotNull(completer);
39 public void writeData(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
40 delegate.write(path, data);
41 completer.onComplete(null, null);
45 public void mergeData(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
46 delegate.merge(path, data);
47 completer.onComplete(null, null);
51 public void deleteData(final YangInstanceIdentifier path) {
52 delegate.delete(path);
53 completer.onComplete(null, null);
57 public void readData(final YangInstanceIdentifier path, final SettableFuture<Optional<NormalizedNode<?, ?>>> proxyFuture) {
59 Futures.addCallback(delegate.read(path), new FutureCallback<Optional<NormalizedNode<?, ?>>>() {
61 public void onSuccess(Optional<NormalizedNode<?, ?>> result) {
62 proxyFuture.set(result);
63 completer.onComplete(null, null);
67 public void onFailure(Throwable t) {
68 proxyFuture.setException(t);
69 completer.onComplete(null, null);
75 public void dataExists(final YangInstanceIdentifier path, final SettableFuture<Boolean> proxyFuture) {
76 Futures.addCallback(delegate.exists(path), new FutureCallback<Boolean>() {
78 public void onSuccess(Boolean result) {
79 proxyFuture.set(result);
80 completer.onComplete(null, null);
84 public void onFailure(Throwable t) {
85 proxyFuture.setException(t);
86 completer.onComplete(null, null);
91 private LocalThreePhaseCommitCohort ready() {
92 LocalThreePhaseCommitCohort ready = (LocalThreePhaseCommitCohort) delegate.ready();
93 completer.onComplete(null, null);
98 public Future<ActorSelection> readyTransaction() {
99 return ready().initiateCoordinatedCommit();
103 public Future<Object> directCommit() {
104 return ready().initiateDirectCommit();
108 public boolean supportsDirectCommit() {
113 public void closeTransaction() {