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.util.concurrent.SettableFuture;
12 import java.util.Optional;
13 import java.util.SortedSet;
14 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
15 import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
16 import org.opendaylight.controller.cluster.datastore.messages.AbstractRead;
17 import org.opendaylight.mdsal.common.api.DataStoreUnavailableException;
18 import org.opendaylight.mdsal.common.api.ReadFailedException;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import scala.concurrent.Future;
25 final class NoOpTransactionContext extends AbstractTransactionContext {
26 private static final Logger LOG = LoggerFactory.getLogger(NoOpTransactionContext.class);
28 private final Throwable failure;
30 NoOpTransactionContext(final Throwable failure, final TransactionIdentifier identifier) {
32 this.failure = failure;
36 public void closeTransaction() {
37 LOG.debug("NoOpTransactionContext {} closeTransaction called", getIdentifier());
41 public Future<Object> directCommit(final Boolean havePermit) {
42 LOG.debug("Tx {} directCommit called, failure", getIdentifier(), failure);
43 return akka.dispatch.Futures.failed(failure);
47 public Future<ActorSelection> readyTransaction(final Boolean havePermit,
48 final Optional<SortedSet<String>> participatingShardNamess) {
49 LOG.debug("Tx {} readyTransaction called, failure", getIdentifier(), failure);
50 return akka.dispatch.Futures.failed(failure);
54 public <T> void executeRead(final AbstractRead<T> readCmd, final SettableFuture<T> proxyFuture,
55 final Boolean havePermit) {
56 LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(),
60 if (failure instanceof NoShardLeaderException) {
61 t = new DataStoreUnavailableException(failure.getMessage(), failure);
65 proxyFuture.setException(new ReadFailedException("Error executeRead " + readCmd.getClass().getSimpleName()
66 + " for path " + readCmd.getPath(), t));
70 public void executeDelete(final YangInstanceIdentifier path, final Boolean havePermit) {
71 LOG.debug("Tx {} executeDelete called path = {}", getIdentifier(), path);
75 public void executeMerge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
76 final Boolean havePermit) {
77 LOG.debug("Tx {} executeMerge called path = {}", getIdentifier(), path);
81 public void executeWrite(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
82 final Boolean havePermit) {
83 LOG.debug("Tx {} executeWrite called path = {}", getIdentifier(), path);