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.old.notification.supplier.impl.item;
11 import com.google.common.base.Preconditions;
12 import java.util.Map.Entry;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
16 import org.opendaylight.openflowplugin.applications.old.notification.supplier.OldNotifSupplierForItem;
17 import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.AbstractNotifSupplierBase;
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 Root Items
24 * Notification Suppliers
26 * @param <O> - data tree item Object
27 * @param <C> - Create notification
28 * @param <U> - Update notification
29 * @param <D> - Delete notification
31 abstract class AbstractNotifSupplierForItem<O extends DataObject,
32 C extends Notification,
33 U extends Notification,
34 D extends Notification>
35 extends AbstractNotifSupplierBase<O>
36 implements OldNotifSupplierForItem<O, C, U, D> {
38 private final NotificationProviderService notifProviderService;
41 * Default constructor for all item Notification Supplier implementation
43 * @param notifProviderService - notification publisher
44 * @param db - DataBroker for DataChangeEvent registration
45 * @param clazz - Statistics Notification Class
47 public AbstractNotifSupplierForItem(final NotificationProviderService notifProviderService, final DataBroker db,
48 final Class<O> clazz) {
50 this.notifProviderService = Preconditions.checkNotNull(notifProviderService);
54 public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
55 Preconditions.checkArgument(change != null, "ChangeEvent can not be null!");
56 if (change.getCreatedData() != null && !(change.getCreatedData().isEmpty())) {
57 for (final Entry<InstanceIdentifier<?>, DataObject> createDataObj : change.getCreatedData().entrySet()) {
58 if (clazz.isAssignableFrom(createDataObj.getKey().getTargetType())) {
59 final InstanceIdentifier<O> ii = createDataObj.getKey().firstIdentifierOf(clazz);
60 final C notif = createNotification((O) createDataObj.getValue(), ii);
62 notifProviderService.publish(notif);
68 if (change.getUpdatedData() != null && !(change.getUpdatedData().isEmpty())) {
69 for (final Entry<InstanceIdentifier<?>, DataObject> updateDataObj : change.getUpdatedData().entrySet()) {
70 if (clazz.isAssignableFrom(updateDataObj.getKey().getTargetType())) {
71 final InstanceIdentifier<O> ii = updateDataObj.getKey().firstIdentifierOf(clazz);
72 final U notif = updateNotification((O) updateDataObj.getValue(), ii);
74 notifProviderService.publish(notif);
80 if (change.getRemovedPaths() != null && !(change.getRemovedPaths().isEmpty())) {
81 for (final InstanceIdentifier<?> deleteDataPath : change.getRemovedPaths()) {
82 if (clazz.isAssignableFrom(deleteDataPath.getTargetType())) {
83 final D notif = deleteNotification(deleteDataPath.firstIdentifierOf(clazz));
85 notifProviderService.publish(notif);