b73c9466e153aac0a64fa610c369cb20c154621a
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / tx / ProxyReadTransaction.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 org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
19 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22
23 /**
24  * ProxyReadTransaction uses provided {@link ActorRef} to delegate method calls to master
25  * {@link org.opendaylight.netconf.topology.singleton.impl.actors.ReadTransactionActor}.
26  */
27 public class ProxyReadTransaction implements DOMDataReadOnlyTransaction {
28
29     private final ProxyReadAdapter delegate;
30
31     /**
32      * Constructor for {@code ProxyReadTransaction}.
33      *
34      * @param masterTxActor {@link org.opendaylight.netconf.topology.singleton.impl.actors.ReadTransactionActor} ref
35      * @param id            device id
36      * @param actorSystem   system
37      * @param askTimeout    timeout
38      */
39     public ProxyReadTransaction(final ActorRef masterTxActor, final RemoteDeviceId id, final ActorSystem actorSystem,
40                                 final Timeout askTimeout) {
41         delegate = new ProxyReadAdapter(masterTxActor, id, actorSystem, askTimeout);
42     }
43
44     @Override
45     public void close() {
46         delegate.close();
47     }
48
49     @Override
50     public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store,
51                                                                                    final YangInstanceIdentifier path) {
52         return delegate.read(store, path);
53     }
54
55     @Override
56     public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
57                                                               final YangInstanceIdentifier path) {
58         return delegate.exists(store, path);
59     }
60
61
62     @Override
63     public Object getIdentifier() {
64         return this;
65     }
66 }