2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.netconf.topology.singleton.impl;
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSystem;
13 import akka.pattern.Patterns;
14 import akka.util.Timeout;
15 import com.google.common.base.Preconditions;
16 import java.util.Collections;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
22 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
23 import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
24 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
25 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
26 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
27 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
28 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
29 import org.opendaylight.netconf.topology.singleton.impl.tx.ProxyReadTransaction;
30 import org.opendaylight.netconf.topology.singleton.impl.tx.ProxyReadWriteTransaction;
31 import org.opendaylight.netconf.topology.singleton.impl.tx.ProxyWriteTransaction;
32 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadTransactionReply;
33 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadTransactionRequest;
34 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadWriteTransactionReply;
35 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadWriteTransactionRequest;
36 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionReply;
37 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionRequest;
38 import org.opendaylight.yangtools.concepts.ListenerRegistration;
39 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
40 import scala.concurrent.Await;
41 import scala.concurrent.Future;
43 public class ProxyDOMDataBroker implements DOMDataBroker {
45 private final Timeout askTimeout;
46 private final RemoteDeviceId id;
47 private final ActorRef masterNode;
48 private final ActorSystem actorSystem;
51 * @param actorSystem system
53 * @param masterNode {@link org.opendaylight.netconf.topology.singleton.impl.actors.NetconfNodeActor} ref
54 * @param askTimeout ask timeout
56 public ProxyDOMDataBroker(final ActorSystem actorSystem, final RemoteDeviceId id,
57 final ActorRef masterNode, final Timeout askTimeout) {
59 this.masterNode = masterNode;
60 this.actorSystem = actorSystem;
61 this.askTimeout = askTimeout;
65 public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
66 final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewReadTransactionRequest(), askTimeout);
68 final Object msg = Await.result(txActorFuture, askTimeout.duration());
69 if (msg instanceof Throwable) {
70 throw (Throwable) msg;
72 Preconditions.checkState(msg instanceof NewReadTransactionReply);
73 final NewReadTransactionReply reply = (NewReadTransactionReply) msg;
74 return new ProxyReadTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
75 } catch (final Throwable t) {
76 throw new IllegalStateException("Can't create ProxyReadTransaction", t);
81 public DOMDataReadWriteTransaction newReadWriteTransaction() {
82 final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewReadWriteTransactionRequest(), askTimeout);
84 final Object msg = Await.result(txActorFuture, askTimeout.duration());
85 if (msg instanceof Throwable) {
86 throw (Throwable) msg;
88 Preconditions.checkState(msg instanceof NewReadWriteTransactionReply);
89 final NewReadWriteTransactionReply reply = (NewReadWriteTransactionReply) msg;
90 return new ProxyReadWriteTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
91 } catch (final Throwable t) {
92 throw new IllegalStateException("Can't create ProxyReadTransaction", t);
97 public DOMDataWriteTransaction newWriteOnlyTransaction() {
98 final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewWriteTransactionRequest(), askTimeout);
100 final Object msg = Await.result(txActorFuture, askTimeout.duration());
101 if (msg instanceof Throwable) {
102 throw (Throwable) msg;
104 Preconditions.checkState(msg instanceof NewWriteTransactionReply);
105 final NewWriteTransactionReply reply = (NewWriteTransactionReply) msg;
106 return new ProxyWriteTransaction(reply.getTxActor(), id, actorSystem, askTimeout);
107 } catch (final Throwable t) {
108 throw new IllegalStateException("Can't create ProxyWriteTransaction", t);
113 public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(
114 final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener,
115 final DataChangeScope triggeringScope) {
116 throw new UnsupportedOperationException(id + ": Data change listeners not supported for netconf mount point");
120 public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
121 throw new UnsupportedOperationException(id + ": Transaction chains not supported for netconf mount point");
126 public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
127 return Collections.emptyMap();