Refactor TransactionContext.executeModification()
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / NoOpTransactionContext.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore;
9
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;
24
25 final class NoOpTransactionContext extends AbstractTransactionContext {
26     private static final Logger LOG = LoggerFactory.getLogger(NoOpTransactionContext.class);
27
28     private final Throwable failure;
29
30     NoOpTransactionContext(final Throwable failure, final TransactionIdentifier identifier) {
31         super(identifier);
32         this.failure = failure;
33     }
34
35     @Override
36     public void closeTransaction() {
37         LOG.debug("NoOpTransactionContext {} closeTransaction called", getIdentifier());
38     }
39
40     @Override
41     public Future<Object> directCommit(final Boolean havePermit) {
42         LOG.debug("Tx {} directCommit called, failure", getIdentifier(), failure);
43         return akka.dispatch.Futures.failed(failure);
44     }
45
46     @Override
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);
51     }
52
53     @Override
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(),
57                 readCmd.getPath());
58
59         final Throwable t;
60         if (failure instanceof NoShardLeaderException) {
61             t = new DataStoreUnavailableException(failure.getMessage(), failure);
62         } else {
63             t = failure;
64         }
65         proxyFuture.setException(new ReadFailedException("Error executeRead " + readCmd.getClass().getSimpleName()
66                 + " for path " + readCmd.getPath(), t));
67     }
68
69     @Override
70     public void executeDelete(final YangInstanceIdentifier path, final Boolean havePermit) {
71         LOG.debug("Tx {} executeDelete called path = {}", getIdentifier(), path);
72     }
73
74     @Override
75     public void executeMerge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
76             final Boolean havePermit) {
77         LOG.debug("Tx {} executeMerge called path = {}", getIdentifier(), path);
78     }
79
80     @Override
81     public void executeWrite(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
82             final Boolean havePermit) {
83         LOG.debug("Tx {} executeWrite called path = {}", getIdentifier(), path);
84     }
85 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.