Switch to MD-SAL APIs
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / NodeNotificationSupplierImpl.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;
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.FlowCapableNodeUpdated;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdatedBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemovedBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdatedBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23
24 /**
25  * Implementation define a contract between {@link FlowCapableNode} data object
26  * and {@link NodeUpdated} and {@link NodeRemoved} notifications.
27  */
28 public class NodeNotificationSupplierImpl extends AbstractNotificationSupplierForItemRoot<FlowCapableNode,
29         NodeUpdated, NodeRemoved> {
30
31     private static final InstanceIdentifier<FlowCapableNode> FLOW_CAPABLE_NODE_INSTANCE_IDENTIFIER = getNodeWildII()
32             .augmentation(FlowCapableNode.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 NodeNotificationSupplierImpl(final NotificationPublishService notifProviderService, final DataBroker db) {
41         super(notifProviderService, db, FlowCapableNode.class);
42     }
43
44     @Override
45     public InstanceIdentifier<FlowCapableNode> getWildCardPath() {
46         return FLOW_CAPABLE_NODE_INSTANCE_IDENTIFIER;
47     }
48
49     @Override
50     public NodeUpdated createNotification(final FlowCapableNode flowCapableNode,
51                                           final InstanceIdentifier<FlowCapableNode> ii) {
52         Preconditions.checkArgument(flowCapableNode != null);
53         Preconditions.checkArgument(ii != null);
54         final FlowCapableNodeUpdatedBuilder flowNodeNotifBuilder = new FlowCapableNodeUpdatedBuilder(flowCapableNode);
55         final NodeUpdatedBuilder notifBuilder = new NodeUpdatedBuilder();
56         notifBuilder.setId(ii.firstKeyOf(Node.class).getId());
57         notifBuilder.setNodeRef(new NodeRef(getNodeII(ii)));
58         notifBuilder.addAugmentation(FlowCapableNodeUpdated.class, flowNodeNotifBuilder.build());
59         return notifBuilder.build();
60     }
61
62     @Override
63     public NodeRemoved deleteNotification(final InstanceIdentifier<FlowCapableNode> path) {
64         Preconditions.checkArgument(path != null);
65         final NodeRemovedBuilder delNodeNotifBuilder = new NodeRemovedBuilder();
66         delNodeNotifBuilder.setNodeRef(new NodeRef(path));
67         return delNodeNotifBuilder.build();
68     }
69 }
70