ebd4ccd90b84e387f1b67f65cacdf733752c6eec
[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
9 package org.opendaylight.openflowplugin.applications.notification.supplier.impl.item;
10
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdatedBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 /**
27  * Implementation define a contract between {@link Flow} data object
28  * and {@link FlowAdded}, {@link FlowUpdated} and {@link FlowRemoved} notifications.
29  */
30 public class FlowNotificationSupplierImpl extends AbstractNotificationSupplierForItem<Flow, FlowAdded, FlowUpdated,
31         FlowRemoved> {
32
33     private static final InstanceIdentifier<Flow> FLOW_INSTANCE_IDENTIFIER = getNodeWildII()
34             .augmentation(FlowCapableNode.class).child(Table.class).child(Flow.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 FlowNotificationSupplierImpl(final NotificationProviderService notifProviderService, final DataBroker db) {
43         super(notifProviderService, db, Flow.class);
44     }
45
46     @Override
47     public InstanceIdentifier<Flow> getWildCardPath() {
48         return FLOW_INSTANCE_IDENTIFIER;
49     }
50
51     @Override
52     public FlowAdded createNotification(final Flow dataTreeItemObject, final InstanceIdentifier<Flow> path) {
53         Preconditions.checkArgument(dataTreeItemObject != null);
54         Preconditions.checkArgument(path != null);
55         final FlowAddedBuilder builder = new FlowAddedBuilder(dataTreeItemObject);
56         builder.setFlowRef(new FlowRef(path));
57         builder.setNode(createNodeRef(path));
58         return builder.build();
59     }
60
61     @Override
62     public FlowUpdated updateNotification(final Flow flow, final InstanceIdentifier<Flow> path) {
63         Preconditions.checkArgument(flow != null);
64         Preconditions.checkArgument(path != null);
65         final FlowUpdatedBuilder builder = new FlowUpdatedBuilder(flow);
66         builder.setFlowRef(new FlowRef(path));
67         builder.setNode(createNodeRef(path));
68         return builder.build();
69     }
70
71     @Override
72     public FlowRemoved deleteNotification(final InstanceIdentifier<Flow> path) {
73         Preconditions.checkArgument(path != null);
74         final FlowRemovedBuilder builder = new FlowRemovedBuilder();
75         builder.setFlowRef(new FlowRef(path));
76         builder.setNode(createNodeRef(path));
77         return builder.build();
78     }
79 }
80