2 * Copyright (c) 2019 Lumina Networks, Inc. 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.sal.connect.netconf.sal;
10 import java.util.Collection;
11 import org.opendaylight.mdsal.binding.api.DataObjectModification;
12 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
13 import org.opendaylight.mdsal.binding.api.DataTreeModification;
14 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
15 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.netconf.node.fields.optional.topology.node.DatastoreLock;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 final class LockChangeListener implements DataTreeChangeListener<DatastoreLock> {
22 private static final Logger LOG = LoggerFactory.getLogger(LockChangeListener.class);
24 private final NetconfDeviceDataBroker netconfDeviceDataBroker;
25 private final NetconfDataTreeServiceImpl netconfDataTreeService;
27 LockChangeListener(final DOMDataBroker netconfDeviceDataBrokder,
28 final NetconfDataTreeService netconfDataTreeService) {
29 this.netconfDeviceDataBroker = (NetconfDeviceDataBroker)netconfDeviceDataBrokder;
30 this.netconfDataTreeService = (NetconfDataTreeServiceImpl) netconfDataTreeService;
34 public void onDataTreeChanged(final Collection<DataTreeModification<DatastoreLock>> changes) {
35 for (final DataTreeModification<DatastoreLock> change : changes) {
36 final DataObjectModification<DatastoreLock> rootNode = change.getRootNode();
37 switch (rootNode.getModificationType()) {
38 case SUBTREE_MODIFIED:
40 if (!rootNode.getDataAfter().isDatastoreLockAllowed()) {
41 LOG.warn("With blocking the lock/unlock operations, the user is coming to "
42 + "operate in a manner which is not supported. Concurrent access to "
43 + "the data store may interfere with data consistency.");
45 netconfDeviceDataBroker.setLockAllowed(rootNode.getDataAfter().isDatastoreLockAllowed());
46 netconfDataTreeService.setLockAllowed(rootNode.getDataAfter().isDatastoreLockAllowed());
49 netconfDeviceDataBroker.setLockAllowed(true);
50 netconfDataTreeService.setLockAllowed(true);
53 LOG.debug("Unsupported modification type: {}.", rootNode.getModificationType());