2 * Copyright (c) 2015 Cisco Systems, Inc. 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.openflowplugin.applications.notification.supplier.impl.item;
11 import com.google.common.base.Preconditions;
13 import java.util.Collection;
14 import java.util.Map.Entry;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
17 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
18 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
19 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
20 import org.opendaylight.openflowplugin.applications.notification.supplier.NotificationSupplierForItem;
21 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.AbstractNotificationSupplierBase;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.opendaylight.yangtools.yang.binding.Notification;
27 * Class is package protected abstract implementation for all Old Root Items
28 * Notification Suppliers
30 * @param <O> - data tree item Object
31 * @param <C> - Create notification
32 * @param <U> - Update notification
33 * @param <D> - Delete notification
35 abstract class AbstractNotificationSupplierForItem<O extends DataObject,
36 C extends Notification,
37 U extends Notification,
38 D extends Notification>
39 extends AbstractNotificationSupplierBase<O>
40 implements NotificationSupplierForItem<O, C, U, D> {
42 private final NotificationProviderService notificationProviderService;
45 * Default constructor for all item Notification Supplier implementation
47 * @param notifProviderService - notification publisher
48 * @param db - DataBroker for DataChangeEvent registration
49 * @param clazz - Statistics Notification Class
51 public AbstractNotificationSupplierForItem(final NotificationProviderService notifProviderService, final DataBroker db,
52 final Class<O> clazz) {
54 this.notificationProviderService = Preconditions.checkNotNull(notifProviderService);
58 public void onDataTreeChanged(Collection<DataTreeModification<O>> changes) {
60 Preconditions.checkNotNull(changes, "Changes may not be null!");
62 for (DataTreeModification<O> change : changes) {
63 final InstanceIdentifier<O> key = change.getRootPath().getRootIdentifier();
64 final DataObjectModification<O> mod = change.getRootNode();
65 switch (mod.getModificationType()) {
67 remove(key, mod.getDataBefore());
69 case SUBTREE_MODIFIED:
70 update(key, mod.getDataBefore(), mod.getDataAfter());
73 if (mod.getDataBefore() == null) {
74 add(key, mod.getDataAfter());
76 update(key, mod.getDataBefore(), mod.getDataAfter());
80 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
86 public void add(InstanceIdentifier<O> identifier , O add ){
87 final C notif = createNotification(add, identifier);
89 notificationProviderService.publish(notif);
94 public void remove(InstanceIdentifier<O> identifier , O del){
95 final D notif = deleteNotification(identifier.firstIdentifierOf(clazz));
97 notificationProviderService.publish(notif);
102 public void update(InstanceIdentifier<O> identifier , O before, O after){
104 final U notif = updateNotification(after, identifier);
106 notificationProviderService.publish(notif);