Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / item / stat / FlowTableStatNotificationSupplierImpl.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.tables.Table;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27
28 /**
29  * Implementation define a contract between {@link FlowTableStatistics} data object
30  * and {@link FlowTableStatisticsUpdate} notification.
31  */
32 public class FlowTableStatNotificationSupplierImpl extends
33         AbstractNotificationSupplierForItemStat<FlowTableStatistics, FlowTableStatisticsUpdate> {
34
35     private static final InstanceIdentifier<FlowTableStatistics> FLOW_TABLE_STATISTICS_INSTANCE_IDENTIFIER
36             = getNodeWildII().augmentation(FlowCapableNode.class).child(Table.class)
37             .augmentation(FlowTableStatisticsData.class).child(FlowTableStatistics.class);
38
39     /**
40      * Constructor register supplier as DataTreeChangeListener and create wildCarded InstanceIdentifier.
41      *
42      * @param notifProviderService - {@link NotificationProviderService}
43      * @param db                   - {@link DataBroker}
44      */
45     public FlowTableStatNotificationSupplierImpl(final NotificationProviderService notifProviderService,
46                                                  final DataBroker db) {
47         super(notifProviderService, db, FlowTableStatistics.class);
48     }
49
50     @Override
51     public InstanceIdentifier<FlowTableStatistics> getWildCardPath() {
52         return FLOW_TABLE_STATISTICS_INSTANCE_IDENTIFIER;
53     }
54
55     @Override
56     public FlowTableStatisticsUpdate createNotification(final FlowTableStatistics flowTableStatistics,
57                                                         final InstanceIdentifier<FlowTableStatistics> path) {
58         Preconditions.checkArgument(flowTableStatistics != null);
59         Preconditions.checkArgument(path != null);
60
61         final FlowTableAndStatisticsMapBuilder ftsmBuilder = new FlowTableAndStatisticsMapBuilder(flowTableStatistics);
62         ftsmBuilder.withKey(new FlowTableAndStatisticsMapKey(
63                 new TableId(path.firstKeyOf(Table.class, TableKey.class).getId())));
64
65         final FlowTableStatisticsUpdateBuilder builder = new FlowTableStatisticsUpdateBuilder();
66         builder.setId(getNodeId(path));
67         builder.setMoreReplies(Boolean.FALSE);
68         // NOTE : fix if it needs, but we have to ask DataStore for the NodeConnector list
69         builder.setNodeConnector(Collections.<NodeConnector>emptyList());
70         builder.setFlowTableAndStatisticsMap(Collections.singletonList(ftsmBuilder.build()));
71         return builder.build();
72     }
73 }
74