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.stat;
11 import com.google.common.base.Preconditions;
12 import java.util.Collection;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
15 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
16 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
17 import org.opendaylight.openflowplugin.applications.notification.supplier.NotificationSupplierForItemStat;
18 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.AbstractNotificationSupplierBase;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.yangtools.yang.binding.Notification;
24 * Class is package protected abstract implementation for all Old Statistics
25 * Notification Suppliers.
27 * @param <O> - Statistics {@link DataObject}
28 * @param <N> - Statistics Notification
30 public abstract class AbstractNotificationSupplierForItemStat<O extends DataObject, N extends Notification> extends
31 AbstractNotificationSupplierBase<O> implements NotificationSupplierForItemStat<O, N> {
33 private final NotificationProviderService notifProviderService;
36 * Default constructor for all Statistic Notification Supplier implementation.
38 * @param notifProviderService - notification publisher
39 * @param db - DataBroker for DataTreeChangeListener registration
40 * @param clazz - Statistics Notification Class
42 public AbstractNotificationSupplierForItemStat(final NotificationProviderService notifProviderService,
43 final DataBroker db, final Class<O> clazz) {
45 this.notifProviderService = Preconditions.checkNotNull(notifProviderService);
49 public void onDataTreeChanged(Collection<DataTreeModification<O>> changes) {
51 Preconditions.checkNotNull(changes, "Changes may not be null!");
53 for (DataTreeModification<O> change : changes) {
54 final InstanceIdentifier<O> key = change.getRootPath().getRootIdentifier();
55 final DataObjectModification<O> mod = change.getRootNode();
56 switch (mod.getModificationType()) {
58 remove(key, mod.getDataBefore());
60 case SUBTREE_MODIFIED:
61 update(key, mod.getDataBefore(), mod.getDataAfter());
64 if (mod.getDataBefore() == null) {
65 add(key, mod.getDataAfter());
67 update(key, mod.getDataBefore(), mod.getDataAfter());
71 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
77 public void add(InstanceIdentifier<O> identifier, O add) {
78 final N notif = createNotification(add, identifier);
80 notifProviderService.publish(notif);
84 public void remove(InstanceIdentifier<O> identifier, O del) {
88 public void update(InstanceIdentifier<O> identifier, O before, O after) {