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.controller.cluster.datastore.modification.AbstractModification;
18 import org.opendaylight.mdsal.common.api.DataStoreUnavailableException;
19 import org.opendaylight.mdsal.common.api.ReadFailedException;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import scala.concurrent.Future;
24 final class NoOpTransactionContext extends AbstractTransactionContext {
25 private static final Logger LOG = LoggerFactory.getLogger(NoOpTransactionContext.class);
27 private final Throwable failure;
29 NoOpTransactionContext(final Throwable failure, final TransactionIdentifier identifier) {
31 this.failure = failure;
35 public void closeTransaction() {
36 LOG.debug("NoOpTransactionContext {} closeTransaction called", getIdentifier());
40 public Future<Object> directCommit(final Boolean havePermit) {
41 LOG.debug("Tx {} directCommit called, failure: {}", getIdentifier(), failure);
42 return akka.dispatch.Futures.failed(failure);
46 public Future<ActorSelection> readyTransaction(final Boolean havePermit,
47 final Optional<SortedSet<String>> participatingShardNamess) {
48 LOG.debug("Tx {} readyTransaction called, failure: {}", getIdentifier(), failure);
49 return akka.dispatch.Futures.failed(failure);
53 public void executeModification(final AbstractModification modification, final Boolean havePermit) {
54 LOG.debug("Tx {} executeModification {} called path = {}", getIdentifier(),
55 modification.getClass().getSimpleName(), modification.getPath());
59 public <T> void executeRead(final AbstractRead<T> readCmd, final SettableFuture<T> proxyFuture,
60 final Boolean havePermit) {
61 LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(),
65 if (failure instanceof NoShardLeaderException) {
66 t = new DataStoreUnavailableException(failure.getMessage(), failure);
70 proxyFuture.setException(new ReadFailedException("Error executeRead " + readCmd.getClass().getSimpleName()
71 + " for path " + readCmd.getPath(), t));