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
8 package org.opendaylight.openflowplugin.applications.notification.supplier.impl.item.stat;
10 import com.google.common.base.Preconditions;
11 import java.util.Collection;
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.mdsal.binding.api.DataObjectModification;
14 import org.opendaylight.mdsal.binding.api.DataTreeModification;
15 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
16 import org.opendaylight.openflowplugin.applications.notification.supplier.NotificationSupplierForItemStat;
17 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.AbstractNotificationSupplierBase;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.opendaylight.yangtools.yang.binding.Notification;
23 * Class is package protected abstract implementation for all Old Statistics
24 * Notification Suppliers.
26 * @param <O> - Statistics {@link DataObject}
27 * @param <N> - Statistics Notification
29 public abstract class AbstractNotificationSupplierForItemStat<O extends DataObject, N extends Notification> extends
30 AbstractNotificationSupplierBase<O> implements NotificationSupplierForItemStat<O, N> {
32 private final NotificationPublishService notifProviderService;
35 * Default constructor for all Statistic Notification Supplier implementation.
37 * @param notifProviderService - notification publisher
38 * @param db - DataBroker for DataTreeChangeListener registration
39 * @param clazz - Statistics Notification Class
41 public AbstractNotificationSupplierForItemStat(final NotificationPublishService notifProviderService,
42 final DataBroker db, final Class<O> clazz) {
44 this.notifProviderService = Preconditions.checkNotNull(notifProviderService);
48 public void onDataTreeChanged(Collection<DataTreeModification<O>> changes) {
50 Preconditions.checkNotNull(changes, "Changes may not be null!");
52 for (DataTreeModification<O> change : changes) {
53 final InstanceIdentifier<O> key = change.getRootPath().getRootIdentifier();
54 final DataObjectModification<O> mod = change.getRootNode();
55 switch (mod.getModificationType()) {
57 remove(key, mod.getDataBefore());
59 case SUBTREE_MODIFIED:
60 update(key, mod.getDataBefore(), mod.getDataAfter());
63 if (mod.getDataBefore() == null) {
64 add(key, mod.getDataAfter());
66 update(key, mod.getDataBefore(), mod.getDataAfter());
70 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
76 public void add(InstanceIdentifier<O> identifier, O add) {
77 final N notif = createNotification(add, identifier);
80 notifProviderService.putNotification(notif);
81 } catch (InterruptedException e) {
82 throw new IllegalStateException("Interrupted while publishing " + notif, e);
87 public void remove(InstanceIdentifier<O> identifier, O del) {
91 public void update(InstanceIdentifier<O> identifier, O before, O after) {