2 * Copyright (c) 2015 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.controller.cluster.datastore;
10 import akka.actor.ActorSelection;
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.SettableFuture;
13 import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
14 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
15 import org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableException;
16 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import scala.concurrent.Future;
23 final class NoOpTransactionContext extends AbstractTransactionContext {
24 private static final Logger LOG = LoggerFactory.getLogger(NoOpTransactionContext.class);
26 private final Throwable failure;
27 private final OperationLimiter operationLimiter;
29 public NoOpTransactionContext(Throwable failure, TransactionIdentifier identifier, OperationLimiter operationLimiter) {
31 this.failure = failure;
32 this.operationLimiter = operationLimiter;
36 public void closeTransaction() {
37 LOG.debug("NoOpTransactionContext {} closeTransaction called", getIdentifier());
41 public boolean supportsDirectCommit() {
46 public Future<Object> directCommit() {
47 LOG.debug("Tx {} directCommit called, failure: {}", getIdentifier(), failure);
48 operationLimiter.release();
49 return akka.dispatch.Futures.failed(failure);
53 public Future<ActorSelection> readyTransaction() {
54 LOG.debug("Tx {} readyTransaction called, failure: {}", getIdentifier(), failure);
55 operationLimiter.release();
56 return akka.dispatch.Futures.failed(failure);
60 public void deleteData(YangInstanceIdentifier path) {
61 LOG.debug("Tx {} deleteData called path = {}", getIdentifier(), path);
62 operationLimiter.release();
66 public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
67 LOG.debug("Tx {} mergeData called path = {}", getIdentifier(), path);
68 operationLimiter.release();
72 public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
73 LOG.debug("Tx {} writeData called path = {}", getIdentifier(), path);
74 operationLimiter.release();
78 public void readData(final YangInstanceIdentifier path, SettableFuture<Optional<NormalizedNode<?, ?>>> proxyFuture) {
79 LOG.debug("Tx {} readData called path = {}", getIdentifier(), path);
80 operationLimiter.release();
82 if(failure instanceof NoShardLeaderException) {
83 t = new DataStoreUnavailableException(failure.getMessage(), failure);
87 proxyFuture.setException(new ReadFailedException("Error reading data for path " + path, t));
91 public void dataExists(YangInstanceIdentifier path, SettableFuture<Boolean> proxyFuture) {
92 LOG.debug("Tx {} dataExists called path = {}", getIdentifier(), path);
93 operationLimiter.release();
94 proxyFuture.setException(new ReadFailedException("Error checking exists for path " + path, failure));