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.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.SettableFuture;
15 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import scala.concurrent.Future;
22 * Processes front-end transaction operations locally before being committed to the destination shard.
23 * Instances of this class are used when the destination shard is local to the caller.
25 * @author Thomas Pantelis
27 final class LocalTransactionContext extends AbstractTransactionContext {
28 private final DOMStoreReadWriteTransaction delegate;
30 LocalTransactionContext(TransactionIdentifier identifier, DOMStoreReadWriteTransaction delegate) {
32 this.delegate = delegate;
36 public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
37 delegate.write(path, data);
41 public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
42 delegate.merge(path, data);
46 public void deleteData(YangInstanceIdentifier path) {
47 delegate.delete(path);
51 public void readData(YangInstanceIdentifier path, final SettableFuture<Optional<NormalizedNode<?, ?>>> proxyFuture) {
52 Futures.addCallback(delegate.read(path), new FutureCallback<Optional<NormalizedNode<?, ?>>>() {
54 public void onSuccess(Optional<NormalizedNode<?, ?>> result) {
55 proxyFuture.set(result);
59 public void onFailure(Throwable t) {
60 proxyFuture.setException(t);
66 public void dataExists(YangInstanceIdentifier path, final SettableFuture<Boolean> proxyFuture) {
67 Futures.addCallback(delegate.exists(path), new FutureCallback<Boolean>() {
69 public void onSuccess(Boolean result) {
70 proxyFuture.set(result);
74 public void onFailure(Throwable t) {
75 proxyFuture.setException(t);
80 private LocalThreePhaseCommitCohort ready() {
81 return (LocalThreePhaseCommitCohort) delegate.ready();
85 public Future<ActorSelection> readyTransaction() {
86 return ready().initiateCoordinatedCommit();
90 public Future<Object> directCommit() {
91 return ready().initiateDirectCommit();
95 public boolean supportsDirectCommit() {
100 public void closeTransaction() {