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 java.util.concurrent.Semaphore;
14 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
15 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import scala.concurrent.Future;
22 final class NoOpTransactionContext extends AbstractTransactionContext {
23 private static final Logger LOG = LoggerFactory.getLogger(NoOpTransactionContext.class);
25 private final Throwable failure;
26 private final Semaphore operationLimiter;
28 public NoOpTransactionContext(Throwable failure, TransactionIdentifier identifier, Semaphore operationLimiter) {
30 this.failure = failure;
31 this.operationLimiter = operationLimiter;
35 public void closeTransaction() {
36 LOG.debug("NoOpTransactionContext {} closeTransaction called", identifier);
40 public Future<ActorSelection> readyTransaction() {
41 LOG.debug("Tx {} readyTransaction called", identifier);
42 operationLimiter.release();
43 return akka.dispatch.Futures.failed(failure);
47 public void deleteData(YangInstanceIdentifier path) {
48 LOG.debug("Tx {} deleteData called path = {}", identifier, path);
49 operationLimiter.release();
53 public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
54 LOG.debug("Tx {} mergeData called path = {}", identifier, path);
55 operationLimiter.release();
59 public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
60 LOG.debug("Tx {} writeData called path = {}", identifier, path);
61 operationLimiter.release();
65 public void readData(final YangInstanceIdentifier path, SettableFuture<Optional<NormalizedNode<?, ?>>> proxyFuture) {
66 LOG.debug("Tx {} readData called path = {}", identifier, path);
67 operationLimiter.release();
68 proxyFuture.setException(new ReadFailedException("Error reading data for path " + path, failure));
72 public void dataExists(YangInstanceIdentifier path, SettableFuture<Boolean> proxyFuture) {
73 LOG.debug("Tx {} dataExists called path = {}", identifier, path);
74 operationLimiter.release();
75 proxyFuture.setException(new ReadFailedException("Error checking exists for path " + path, failure));