Listener classes for listening on node inventory data changes were added.
Change-Id: Ia7b61c5a09a7d1d40246e34b80dc466a8dc4ea4c
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
private final static Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyProvider.class);
private ListenerRegistration<NotificationListener> listenerRegistration;
private Thread thread;
+ private LinkChangeListenerImpl linkChangeListener;
+ private NodeChangeListenerImpl nodeChangeListener;
/**
* Gets called on start of a bundle.
final OperationProcessor processor = new OperationProcessor(dataBroker);
final FlowCapableTopologyExporter listener = new FlowCapableTopologyExporter(processor, path);
this.listenerRegistration = notificationService.registerNotificationListener(listener);
+ linkChangeListener = new LinkChangeListenerImpl(dataBroker);
+ nodeChangeListener = new NodeChangeListenerImpl(dataBroker);
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
tx.put(LogicalDatastoreType.OPERATIONAL, path, new TopologyBuilder().setKey(key).build(), true);
}
listenerRegistration = null;
}
+ unregisterListener(linkChangeListener);
+ unregisterListener(nodeChangeListener);
if (thread != null) {
thread.interrupt();
thread.join();
}
}
+ private void unregisterListener(final AutoCloseable listenerToClose) {
+ if (listenerToClose != null) {
+ try {
+ listenerToClose.close();
+ } catch (Exception e) {
+ LOG.error("Failed to close listener registration", e);
+ }
+ }
+ }
+
/**
* Gets called during stop bundle
*
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.applications.topology.manager;
+
+import java.util.Map;
+import java.util.Set;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class LinkChangeListenerImpl implements DataChangeListener, AutoCloseable {
+ private final ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
+
+ public LinkChangeListenerImpl(final DataBroker dataBroker) {
+ dataChangeListenerRegistration = dataBroker.registerDataChangeListener(
+ LogicalDatastoreType.OPERATIONAL,
+ InstanceIdentifier.builder(Nodes.class)
+ .child(Node.class)
+ .child(NodeConnector.class)
+ .augmentation(FlowCapableNodeConnector.class)
+ .build(),
+ this, AsyncDataBroker.DataChangeScope.BASE);
+ }
+
+ @Override
+ public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+ processAddedNodeConnectors(change.getCreatedData());
+ processUpdatedNodeConnectors(change.getUpdatedData());
+ processRemovedNodeConnectors(change.getRemovedPaths());
+ }
+
+ /**
+ * @param removedPaths
+ */
+ private void processRemovedNodeConnectors(Set<InstanceIdentifier<?>> removedPaths) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @param updatedData
+ */
+ private void processUpdatedNodeConnectors(Map<InstanceIdentifier<?>, DataObject> updatedData) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @param createdData
+ */
+ private void processAddedNodeConnectors(Map<InstanceIdentifier<?>, DataObject> createdData) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void close() throws Exception {
+ dataChangeListenerRegistration.close();
+ }
+
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.applications.topology.manager;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import java.util.Map;
+import java.util.Set;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
+
+ public class NodeChangeListenerImpl implements DataChangeListener, AutoCloseable {
+ private final ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
+
+ public NodeChangeListenerImpl(final DataBroker dataBroker) {
+ dataChangeListenerRegistration = dataBroker.registerDataChangeListener(
+ LogicalDatastoreType.OPERATIONAL,
+ InstanceIdentifier.builder(Nodes.class)
+ .child(Node.class)
+ .augmentation(FlowCapableNode.class)
+ .build(),
+ this, AsyncDataBroker.DataChangeScope.BASE);
+ }
+
+ @Override
+ public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+ processAddedNode(change.getCreatedData());
+ processUpdatedNode(change.getUpdatedData());
+ processRemovedNode(change.getRemovedPaths());
+ }
+
+ /**
+ * @param removedPaths
+ */
+ private void processRemovedNode(Set<InstanceIdentifier<?>> removedPaths) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @param updatedData
+ */
+ private void processUpdatedNode(Map<InstanceIdentifier<?>, DataObject> updatedData) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @param createdData
+ */
+ private void processAddedNode(Map<InstanceIdentifier<?>, DataObject> createdData) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void close() throws Exception {
+ dataChangeListenerRegistration.close();
+ }
+
+ }
\ No newline at end of file