545b65fdd2da85eb46985fa70b0d25a50abecbd2
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / item / stat / MeterStatNotificationSupplierImpl.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
9 package org.opendaylight.openflowplugin.applications.notification.supplier.impl.item.stat;
10
11 import com.google.common.base.Preconditions;
12 import java.util.Collections;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdatedBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatistics;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24
25 /**
26  * Implementation define a contract between {@link MeterStatistics} data object
27  * and {@link MeterStatisticsUpdated} notification.
28  */
29 public class MeterStatNotificationSupplierImpl extends AbstractNotificationSupplierForItemStat<MeterStatistics,
30         MeterStatisticsUpdated> {
31
32     private static final InstanceIdentifier<MeterStatistics> METER_STATISTICS_INSTANCE_IDENTIFIER = getNodeWildII()
33             .augmentation(FlowCapableNode.class).child(Meter.class).augmentation(NodeMeterStatistics.class)
34             .child(MeterStatistics.class);
35
36     /**
37      * Constructor register supplier as DataTreeChangeListener and create wildCarded InstanceIdentifier.
38      *
39      * @param notifProviderService - {@link NotificationProviderService}
40      * @param db                   - {@link DataBroker}
41      */
42     public MeterStatNotificationSupplierImpl(final NotificationProviderService notifProviderService,
43                                              final DataBroker db) {
44         super(notifProviderService, db, MeterStatistics.class);
45     }
46
47     @Override
48     public InstanceIdentifier<MeterStatistics> getWildCardPath() {
49         return METER_STATISTICS_INSTANCE_IDENTIFIER;
50     }
51
52     @Override
53     public MeterStatisticsUpdated createNotification(final MeterStatistics meterStatistics,
54                                                      final InstanceIdentifier<MeterStatistics> path) {
55         Preconditions.checkArgument(meterStatistics != null);
56         Preconditions.checkArgument(path != null);
57
58         final MeterStatisticsUpdatedBuilder builder = new MeterStatisticsUpdatedBuilder();
59         builder.setId(getNodeId(path));
60         builder.setMoreReplies(Boolean.FALSE);
61         // TODO : fix if it needs, but we have to ask DataStore for the NodeConnector list
62         builder.setNodeConnector(Collections.<NodeConnector>emptyList());
63         builder.setMeterStats(Collections.singletonList(new MeterStatsBuilder(meterStatistics).build()));
64         return builder.build();
65     }
66 }
67