Merge "BUG 2854 : Do not add empty read write transactions to the replicable journal"
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / sal / NetconfDeviceDataBroker.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.controller.sal.connect.netconf.sal;
10
11 import java.util.Collections;
12 import java.util.Map;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
20 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
21 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
22 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
23 import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionPreferences;
24 import org.opendaylight.controller.sal.connect.netconf.sal.tx.ReadOnlyTx;
25 import org.opendaylight.controller.sal.connect.netconf.sal.tx.ReadWriteTx;
26 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteCandidateRunningTx;
27 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteCandidateTx;
28 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteRunningTx;
29 import org.opendaylight.controller.sal.connect.netconf.util.NetconfBaseOps;
30 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
31 import org.opendaylight.yangtools.concepts.ListenerRegistration;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
33 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
34
35 final class NetconfDeviceDataBroker implements DOMDataBroker {
36     private final RemoteDeviceId id;
37     private final NetconfBaseOps netconfOps;
38     private final NetconfSessionPreferences netconfSessionPreferences;
39
40     public NetconfDeviceDataBroker(final RemoteDeviceId id, final SchemaContext schemaContext, final DOMRpcService rpc, final NetconfSessionPreferences netconfSessionPreferences) {
41         this.id = id;
42         this.netconfOps = new NetconfBaseOps(rpc, schemaContext);
43         this.netconfSessionPreferences = netconfSessionPreferences;
44     }
45
46     @Override
47     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
48         return new ReadOnlyTx(netconfOps, id);
49     }
50
51     @Override
52     public DOMDataReadWriteTransaction newReadWriteTransaction() {
53         return new ReadWriteTx(newReadOnlyTransaction(), newWriteOnlyTransaction());
54     }
55
56     @Override
57     public DOMDataWriteTransaction newWriteOnlyTransaction() {
58         if(netconfSessionPreferences.isCandidateSupported()) {
59             if(netconfSessionPreferences.isRunningWritable()) {
60                 return new WriteCandidateRunningTx(id, netconfOps, netconfSessionPreferences);
61             } else {
62                 return new WriteCandidateTx(id, netconfOps, netconfSessionPreferences);
63             }
64         } else {
65             return new WriteRunningTx(id, netconfOps, netconfSessionPreferences);
66         }
67     }
68
69     @Override
70     public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
71         throw new UnsupportedOperationException(id + ": Data change listeners not supported for netconf mount point");
72     }
73
74     @Override
75     public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
76         throw new UnsupportedOperationException(id + ": Transaction chains not supported for netconf mount point");
77     }
78
79     @Override
80     public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
81         return Collections.emptyMap();
82     }
83
84 }