Switch to MD-SAL APIs
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / item / FlowNotificationSupplierImpl.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.tables.Table;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdatedBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24
25 /**
26  * Implementation define a contract between {@link Flow} data object
27  * and {@link FlowAdded}, {@link FlowUpdated} and {@link FlowRemoved} notifications.
28  */
29 public class FlowNotificationSupplierImpl extends AbstractNotificationSupplierForItem<Flow, FlowAdded, FlowUpdated,
30         FlowRemoved> {
31
32     private static final InstanceIdentifier<Flow> FLOW_INSTANCE_IDENTIFIER = getNodeWildII()
33             .augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class);
34
35     /**
36      * Constructor register supplier as DataTreeChangeListener and create wildCarded InstanceIdentifier.
37      *
38      * @param notifProviderService - {@link NotificationPublishService}
39      * @param db                   - {@link DataBroker}
40      */
41     public FlowNotificationSupplierImpl(final NotificationPublishService notifProviderService, final DataBroker db) {
42         super(notifProviderService, db, Flow.class);
43     }
44
45     @Override
46     public InstanceIdentifier<Flow> getWildCardPath() {
47         return FLOW_INSTANCE_IDENTIFIER;
48     }
49
50     @Override
51     public FlowAdded createNotification(final Flow dataTreeItemObject, final InstanceIdentifier<Flow> path) {
52         Preconditions.checkArgument(dataTreeItemObject != null);
53         Preconditions.checkArgument(path != null);
54         final FlowAddedBuilder builder = new FlowAddedBuilder(dataTreeItemObject);
55         builder.setFlowRef(new FlowRef(path));
56         builder.setNode(createNodeRef(path));
57         return builder.build();
58     }
59
60     @Override
61     public FlowUpdated updateNotification(final Flow flow, final InstanceIdentifier<Flow> path) {
62         Preconditions.checkArgument(flow != null);
63         Preconditions.checkArgument(path != null);
64         final FlowUpdatedBuilder builder = new FlowUpdatedBuilder(flow);
65         builder.setFlowRef(new FlowRef(path));
66         builder.setNode(createNodeRef(path));
67         return builder.build();
68     }
69
70     @Override
71     public FlowRemoved deleteNotification(final InstanceIdentifier<Flow> path) {
72         Preconditions.checkArgument(path != null);
73         final FlowRemovedBuilder builder = new FlowRemovedBuilder();
74         builder.setFlowRef(new FlowRef(path));
75         builder.setNode(createNodeRef(path));
76         return builder.build();
77     }
78 }
79