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
8 package org.opendaylight.netconf.topology.singleton.impl;
10 import akka.actor.ActorRef;
11 import akka.pattern.Patterns;
12 import akka.util.Timeout;
13 import com.google.common.collect.ClassToInstanceMap;
14 import com.google.common.collect.ImmutableClassToInstanceMap;
15 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
16 import org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension;
17 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
18 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
20 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
21 import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
22 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
23 import org.opendaylight.netconf.topology.singleton.impl.tx.ProxyReadTransaction;
24 import org.opendaylight.netconf.topology.singleton.impl.tx.ProxyReadWriteTransaction;
25 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadTransactionRequest;
26 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadWriteTransactionRequest;
27 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionRequest;
28 import scala.concurrent.ExecutionContext;
29 import scala.concurrent.Future;
31 public class ProxyDOMDataBroker implements DOMDataBroker {
33 private final Timeout askTimeout;
34 private final RemoteDeviceId id;
35 private final ActorRef masterNode;
36 private final ExecutionContext executionContext;
39 * Constructor for {@code ProxyDOMDataBroker}.
42 * @param masterNode {@link org.opendaylight.netconf.topology.singleton.impl.actors.NetconfNodeActor} ref
43 * @param executionContext ExecutionContext
44 * @param askTimeout ask timeout
46 public ProxyDOMDataBroker(final RemoteDeviceId id, final ActorRef masterNode,
47 final ExecutionContext executionContext, final Timeout askTimeout) {
49 this.masterNode = masterNode;
50 this.executionContext = executionContext;
51 this.askTimeout = askTimeout;
54 @SuppressWarnings("checkstyle:IllegalCatch")
56 public DOMDataTreeReadTransaction newReadOnlyTransaction() {
57 final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewReadTransactionRequest(), askTimeout);
58 return new ProxyReadTransaction(id, txActorFuture, executionContext, askTimeout);
61 @SuppressWarnings("checkstyle:IllegalCatch")
63 public DOMDataTreeReadWriteTransaction newReadWriteTransaction() {
64 final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewReadWriteTransactionRequest(), askTimeout);
65 return new ProxyReadWriteTransaction(id, txActorFuture, executionContext, askTimeout);
68 @SuppressWarnings("checkstyle:IllegalCatch")
70 public DOMDataTreeWriteTransaction newWriteOnlyTransaction() {
71 final Future<Object> txActorFuture = Patterns.ask(masterNode, new NewWriteTransactionRequest(), askTimeout);
72 return new ProxyReadWriteTransaction(id, txActorFuture, executionContext, askTimeout);
76 public DOMTransactionChain createTransactionChain(final DOMTransactionChainListener listener) {
77 throw new UnsupportedOperationException(id + ": Transaction chains not supported for netconf mount point");
81 public ClassToInstanceMap<DOMDataBrokerExtension> getExtensions() {
82 return ImmutableClassToInstanceMap.of();