Bug 8153: Enforce check-style rules for netconf - netconf-topology-singleton
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / tx / ProxyReadWriteTransaction.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.netconf.topology.singleton.impl.tx;
10
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSystem;
13 import akka.util.Timeout;
14 import com.google.common.base.Optional;
15 import com.google.common.util.concurrent.CheckedFuture;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
20 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
22 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26
27 /**
28  * ProxyReadWriteTransaction uses provided {@link ActorRef} to delegate method calls to master
29  * {@link org.opendaylight.netconf.topology.singleton.impl.actors.ReadWriteTransactionActor}.
30  */
31 public class ProxyReadWriteTransaction implements DOMDataReadWriteTransaction {
32
33     private final ProxyReadAdapter delegateRead;
34     private final ProxyWriteAdapter delegateWrite;
35
36     /**
37      * Constructor for {@code ProxyReadWriteTransaction}.
38      *
39      * @param masterTxActor
40      * {@link org.opendaylight.netconf.topology.singleton.impl.actors.ReadWriteTransactionActor} ref
41      * @param id            device id
42      * @param actorSystem   system
43      * @param askTimeout    timeout
44      */
45     public ProxyReadWriteTransaction(final ActorRef masterTxActor, final RemoteDeviceId id,
46                                      final ActorSystem actorSystem, final Timeout askTimeout) {
47         delegateRead = new ProxyReadAdapter(masterTxActor, id, actorSystem, askTimeout);
48         delegateWrite = new ProxyWriteAdapter(masterTxActor, id, actorSystem, askTimeout);
49     }
50
51     @Override
52     public boolean cancel() {
53         return delegateWrite.cancel();
54     }
55
56     @Override
57     public ListenableFuture<RpcResult<TransactionStatus>> commit() {
58         return delegateWrite.commit(getIdentifier());
59     }
60
61     @Override
62     public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store,
63                                                                                    final YangInstanceIdentifier path) {
64         return delegateRead.read(store, path);
65     }
66
67     @Override
68     public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
69                                                               final YangInstanceIdentifier path) {
70         return delegateRead.exists(store, path);
71     }
72
73     @Override
74     public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
75         delegateWrite.delete(store, path);
76     }
77
78     @Override
79     public CheckedFuture<Void, TransactionCommitFailedException> submit() {
80         return delegateWrite.submit(getIdentifier());
81     }
82
83     @Override
84     public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
85                     final NormalizedNode<?, ?> data) {
86         delegateWrite.put(store, path, data, getIdentifier());
87     }
88
89     @Override
90     public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
91                       final NormalizedNode<?, ?> data) {
92         delegateWrite.merge(store, path, data, getIdentifier());
93     }
94
95     @Override
96     public Object getIdentifier() {
97         return this;
98     }
99 }