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.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.netconf.node.fields.optional.topology.node.DatastoreLock;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 final class LockChangeListener implements DataTreeChangeListener<DatastoreLock> {
21 private static final Logger LOG = LoggerFactory.getLogger(LockChangeListener.class);
23 private final NetconfDeviceDataBroker netconfDeviceDataBroker;
25 LockChangeListener(final DOMDataBroker netconfDeviceDataBrokder) {
26 this.netconfDeviceDataBroker = (NetconfDeviceDataBroker)netconfDeviceDataBrokder;
30 public void onDataTreeChanged(final Collection<DataTreeModification<DatastoreLock>> changes) {
31 for (final DataTreeModification<DatastoreLock> change : changes) {
32 final DataObjectModification<DatastoreLock> rootNode = change.getRootNode();
33 switch (rootNode.getModificationType()) {
34 case SUBTREE_MODIFIED:
36 if (!rootNode.getDataAfter().isDatastoreLockAllowed()) {
37 LOG.warn("With blocking the lock/unlock operations, the user is coming to"
38 + "operate in a manner which is not supported. It must not exist"
39 + "any concurrent access to the data store - it may interfere with"
40 + "data consistency.");
42 netconfDeviceDataBroker.setLockAllowed(rootNode.getDataAfter().isDatastoreLockAllowed());
45 netconfDeviceDataBroker.setLockAllowed(true);
48 LOG.debug("Unsupported modification type: {}.", rootNode.getModificationType());