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));
59 LOG.info("UnimgrDataChangeListener initialized");
63 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>,
65 create(change.getCreatedData());
66 update(change.getUpdatedData());
71 public void create(Map<InstanceIdentifier<?>,
72 DataObject> changes) {
73 if (changes != null) {
74 List<Command> commands = new ArrayList<Command>();
75 Command uniCreate = new UniCreateCommand(dataBroker, changes);
76 Command evcCreate = new EvcCreateCommand(dataBroker, changes);
77 commands.add(uniCreate);
78 commands.add(evcCreate);
79 invoker.setCommands(commands);
85 public void update(Map<InstanceIdentifier<?>,
86 DataObject> changes) {
87 if (changes != null) {
88 List<Command> commands = new ArrayList<Command>();
89 Command uniUpdate = new UniUpdateCommand(dataBroker, changes);
90 Command evcUpdate = new EvcUpdateCommand(dataBroker, changes);
91 commands.add(uniUpdate);
92 commands.add(evcUpdate);
93 invoker.setCommands(commands);
99 public void delete(AsyncDataChangeEvent<InstanceIdentifier<?>,
100 DataObject> changes) {
101 if (changes != null) {
102 List<Command> commands = new ArrayList<Command>();
103 Command uniDelete = new UniDeleteCommand(dataBroker, changes);
104 Command evcDelete = new EvcDeleteCommand(dataBroker, changes);
105 commands.add(uniDelete);
106 commands.add(evcDelete);
107 invoker.setCommands(commands);
113 public void close() throws Exception {
114 LOG.info("UnimgrDataChangeListener stopped.");
115 for (ListenerRegistration<DataChangeListener> listener : listeners) {
116 if (listener != null) {