2 * Copyright (c) 2016 Hewlett Packard Enterprise, Co. 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
9 package org.opendaylight.unimgr.mef.netvirt;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.unimgr.api.UnimgrDataTreeChangeListener;
16 import org.opendaylight.yang.gen.v1.http.metroethernetforum.org.ns.yang.mef.interfaces.rev150526.mef.interfaces.unis.Uni;
17 import org.opendaylight.yangtools.concepts.ListenerRegistration;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class UniAwareListener extends UnimgrDataTreeChangeListener<Uni> {
22 private static final Logger Log = LoggerFactory.getLogger(UniAwareListener.class);
23 private ListenerRegistration<UniAwareListener> uniListenerRegistration;
24 IUniAwareService serviceSubscribe;
26 public UniAwareListener(final DataBroker dataBroker, final IUniAwareService serviceSubscribe) {
28 this.serviceSubscribe = serviceSubscribe;
32 public void registerListener() {
34 final DataTreeIdentifier<Uni> dataTreeIid = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
35 MefInterfaceUtils.getUniListInstanceIdentifier());
36 uniListenerRegistration = dataBroker.registerDataTreeChangeListener(dataTreeIid, this);
37 Log.info("UniAwareListener created and registered for service {}", serviceSubscribe);
38 } catch (final Exception e) {
39 Log.error("UniAwareListener registration failed !", e);
40 throw new IllegalStateException("UniAwareListener failed.", e);
45 public void close() throws Exception {
46 uniListenerRegistration.close();
50 public void add(DataTreeModification<Uni> newDataObject) {
51 if (newDataObject.getRootPath() != null && newDataObject.getRootNode() != null) {
52 Log.info("Uni {} is operational", newDataObject.getRootNode().getIdentifier());
53 // Uni Id is same in interface and service
54 serviceSubscribe.connectUni(newDataObject.getRootNode().getDataAfter().getUniId().getValue());
59 public void remove(DataTreeModification<Uni> removedDataObject) {
60 if (removedDataObject.getRootPath() != null && removedDataObject.getRootNode() != null) {
61 Log.info("Remove Uni {} from operational", removedDataObject.getRootNode().getIdentifier());
62 // Uni Id is same in interface and service
63 serviceSubscribe.disconnectUni(removedDataObject.getRootNode().getDataBefore().getUniId().getValue());
68 public void update(DataTreeModification<Uni> modifiedDataObject) {