Add UnsignedLongBitmap
[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 TransactionContext {
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     void closeTransaction() {
37         LOG.debug("NoOpTransactionContext {} closeTransaction called", getIdentifier());
38     }
39
40     @Override
41     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     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     <T> void executeRead(final AbstractRead<T> readCmd, final SettableFuture<T> proxyFuture, final Boolean havePermit) {
55         LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(),
56                 readCmd.getPath());
57
58         final Throwable t;
59         if (failure instanceof NoShardLeaderException) {
60             t = new DataStoreUnavailableException(failure.getMessage(), failure);
61         } else {
62             t = failure;
63         }
64         proxyFuture.setException(new ReadFailedException("Error executeRead " + readCmd.getClass().getSimpleName()
65                 + " for path " + readCmd.getPath(), t));
66     }
67
68     @Override
69     void executeDelete(final YangInstanceIdentifier path, final Boolean havePermit) {
70         LOG.debug("Tx {} executeDelete called path = {}", getIdentifier(), path);
71     }
72
73     @Override
74     void executeMerge(final YangInstanceIdentifier path, final NormalizedNode data, final Boolean havePermit) {
75         LOG.debug("Tx {} executeMerge called path = {}", getIdentifier(), path);
76     }
77
78     @Override
79     void executeWrite(final YangInstanceIdentifier path, final NormalizedNode data, final Boolean havePermit) {
80         LOG.debug("Tx {} executeWrite called path = {}", getIdentifier(), path);
81     }
82 }