2 * Copyright (c) 2015 CableLabs 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.unimgr.impl;
10 import java.util.HashMap;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.unimgr.api.IUnimgrDataChangeListener;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class UniDataChangeListener implements IUnimgrDataChangeListener {
27 private static final Logger LOG = LoggerFactory.getLogger(UniDataChangeListener.class);
29 private Map<String, ListenerRegistration<DataChangeListener>> listeners;
30 private DataBroker dataBroker;
32 public UniDataChangeListener(DataBroker dataBroker) {
33 this.dataBroker = dataBroker;
34 listeners = new HashMap<String, ListenerRegistration<DataChangeListener>>();
35 ListenerRegistration<DataChangeListener> uniListener = dataBroker.registerDataChangeListener(
36 LogicalDatastoreType.CONFIGURATION, UnimgrMapper.getUnisIid()
37 , this, DataChangeScope.SUBTREE);
38 // We want to listen for operational store changes on the ovsdb:1 network topology
39 // because this is when we know Southbound has successfully connected to the
41 ListenerRegistration<DataChangeListener> ovsdbListener = dataBroker.registerDataChangeListener(
42 LogicalDatastoreType.OPERATIONAL, UnimgrMapper.getOvsdbTopologyIdentifier()
43 , this, DataChangeScope.SUBTREE);
44 listeners.put("uni", uniListener);
45 listeners.put("ovsdb", ovsdbListener);
50 public void onDataChanged(
51 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
52 create(changes.getCreatedData());
53 update(changes.getUpdatedData());
58 public void create(Map<InstanceIdentifier<?>, DataObject> changes) {
62 public void update(Map<InstanceIdentifier<?>, DataObject> changes) {
67 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
68 // TODO implement delete, verify old data versus new data
72 public void close() throws Exception {
73 for (Map.Entry<String, ListenerRegistration<DataChangeListener>> entry : listeners.entrySet()) {
74 ListenerRegistration<DataChangeListener> value = entry.getValue();