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.ArrayList;
11 import java.util.HashSet;
12 import java.util.List;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
18 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
19 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.unimgr.api.IUnimgrDataChangeListener;
22 import org.opendaylight.unimgr.command.Command;
23 import org.opendaylight.unimgr.command.EvcCreateCommand;
24 import org.opendaylight.unimgr.command.EvcDeleteCommand;
25 import org.opendaylight.unimgr.command.EvcUpdateCommand;
26 import org.opendaylight.unimgr.command.TransactionInvoker;
27 import org.opendaylight.unimgr.command.UniCreateCommand;
28 import org.opendaylight.unimgr.command.UniDeleteCommand;
29 import org.opendaylight.unimgr.command.UniUpdateCommand;
30 import org.opendaylight.yangtools.concepts.ListenerRegistration;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class UnimgrDataChangeListener implements IUnimgrDataChangeListener {
38 private static final Logger LOG = LoggerFactory.getLogger(UnimgrDataChangeListener.class);
39 private Set<ListenerRegistration<DataChangeListener>> listeners;
40 private DataBroker dataBroker;
41 private TransactionInvoker invoker;
43 public UnimgrDataChangeListener(DataBroker dataBroker, TransactionInvoker invoker) {
44 this.dataBroker = dataBroker;
45 this.invoker = invoker;
46 listeners = new HashSet<ListenerRegistration<DataChangeListener>>();
47 listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
48 UnimgrMapper.getUniTopologyIid(),
50 DataChangeScope.SUBTREE));
51 listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
52 UnimgrMapper.getEvcTopologyIid(),
54 DataChangeScope.SUBTREE));
55 listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
56 UnimgrMapper.getOvsdbTopologyIid(),
58 DataChangeScope.SUBTREE));
62 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>,
64 create(change.getCreatedData());
65 update(change.getUpdatedData());
70 public void create(Map<InstanceIdentifier<?>,
71 DataObject> changes) {
72 if (changes != null) {
73 List<Command> commands = new ArrayList<Command>();
74 commands.add(new UniCreateCommand(dataBroker, changes));
75 commands.add(new EvcCreateCommand(dataBroker, changes));
76 invoker.setCommands(commands);
82 public void update(Map<InstanceIdentifier<?>,
83 DataObject> changes) {
84 if (changes != null) {
85 List<Command> commands = new ArrayList<Command>();
86 commands.add(new UniUpdateCommand(dataBroker, changes));
87 commands.add(new EvcUpdateCommand(dataBroker, changes));
88 invoker.setCommands(commands);
94 public void delete(AsyncDataChangeEvent<InstanceIdentifier<?>,
95 DataObject> changes) {
96 if (changes != null) {
97 List<Command> commands = new ArrayList<Command>();
98 commands.add(new UniDeleteCommand(dataBroker, changes));
99 commands.add(new EvcDeleteCommand(dataBroker, changes));
100 invoker.setCommands(commands);
106 public void close() throws Exception {
107 LOG.info("UnimgrDataChangeListener stopped.");
108 for (ListenerRegistration<DataChangeListener> listener : listeners) {
109 if (listener != null) {