Refactor TransactionProxy
[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.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;
21
22 final class NoOpTransactionContext extends AbstractTransactionContext {
23     private static final Logger LOG = LoggerFactory.getLogger(NoOpTransactionContext.class);
24
25     private final Throwable failure;
26     private final Semaphore operationLimiter;
27
28     public NoOpTransactionContext(Throwable failure, TransactionIdentifier identifier, Semaphore operationLimiter) {
29         super(identifier);
30         this.failure = failure;
31         this.operationLimiter = operationLimiter;
32     }
33
34     @Override
35     public void closeTransaction() {
36         LOG.debug("NoOpTransactionContext {} closeTransaction called", identifier);
37     }
38
39     @Override
40     public Future<ActorSelection> readyTransaction() {
41         LOG.debug("Tx {} readyTransaction called", identifier);
42         operationLimiter.release();
43         return akka.dispatch.Futures.failed(failure);
44     }
45
46     @Override
47     public void deleteData(YangInstanceIdentifier path) {
48         LOG.debug("Tx {} deleteData called path = {}", identifier, path);
49         operationLimiter.release();
50     }
51
52     @Override
53     public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
54         LOG.debug("Tx {} mergeData called path = {}", identifier, path);
55         operationLimiter.release();
56     }
57
58     @Override
59     public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
60         LOG.debug("Tx {} writeData called path = {}", identifier, path);
61         operationLimiter.release();
62     }
63
64     @Override
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));
69     }
70
71     @Override
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));
76     }
77 }

©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.