Switch to MD-SAL APIs
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / item / MeterNotificationSupplierImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.applications.notification.supplier.impl.item;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.mdsal.binding.api.DataBroker;
12 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAdded;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAddedBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemoved;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemovedBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdated;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdatedBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23
24 /**
25  * Implementation define a contract between {@link Meter} data object
26  * and {@link MeterAdded}, {@link MeterUpdated} and {@link MeterRemoved} notifications.
27  */
28 public class MeterNotificationSupplierImpl extends
29         AbstractNotificationSupplierForItem<Meter, MeterAdded, MeterUpdated, MeterRemoved> {
30
31     private static final InstanceIdentifier<Meter> METER_INSTANCE_IDENTIFIER
32             = getNodeWildII().augmentation(FlowCapableNode.class).child(Meter.class);
33
34     /**
35      * Constructor register supplier as DataTreeChangeListener and create wildCarded InstanceIdentifier.
36      *
37      * @param notifProviderService - {@link NotificationPublishService}
38      * @param db - {@link DataBroker}
39      */
40     public MeterNotificationSupplierImpl(final NotificationPublishService notifProviderService, final DataBroker db) {
41         super(notifProviderService, db, Meter.class);
42     }
43
44     @Override
45     public InstanceIdentifier<Meter> getWildCardPath() {
46         return METER_INSTANCE_IDENTIFIER;
47     }
48
49     @Override
50     public MeterAdded createNotification(final Meter dataTreeItemObject, final InstanceIdentifier<Meter> path) {
51         Preconditions.checkArgument(dataTreeItemObject != null);
52         Preconditions.checkArgument(path != null);
53         final MeterAddedBuilder builder = new MeterAddedBuilder(dataTreeItemObject);
54         builder.setMeterRef(new MeterRef(path));
55         builder.setNode(createNodeRef(path));
56         return builder.build();
57     }
58
59     @Override
60     public MeterUpdated updateNotification(final Meter meter, final InstanceIdentifier<Meter> path) {
61         Preconditions.checkArgument(meter != null);
62         Preconditions.checkArgument(path != null);
63         final MeterUpdatedBuilder builder = new MeterUpdatedBuilder(meter);
64         builder.setMeterRef(new MeterRef(path));
65         builder.setNode(createNodeRef(path));
66         return builder.build();
67     }
68
69     @Override
70     public MeterRemoved deleteNotification(final InstanceIdentifier<Meter> path) {
71         Preconditions.checkArgument(path != null);
72         final MeterRemovedBuilder builder = new MeterRemovedBuilder();
73         builder.setMeterId(path.firstKeyOf(Meter.class).getMeterId());
74         builder.setMeterRef(new MeterRef(path));
75         builder.setNode(createNodeRef(path));
76         return builder.build();
77     }
78 }
79