2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.applications.notification.supplier.impl;
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.FlowCapableNodeUpdated;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdatedBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemovedBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdatedBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 * Implementation define a contract between {@link FlowCapableNode} data object
27 * and {@link NodeUpdated} and {@link NodeRemoved} notifications.
29 public class NodeNotificationSupplierImpl extends AbstractNotificationSupplierForItemRoot<FlowCapableNode,
30 NodeUpdated, NodeRemoved> {
32 private static final InstanceIdentifier<FlowCapableNode> FLOW_CAPABLE_NODE_INSTANCE_IDENTIFIER = getNodeWildII()
33 .augmentation(FlowCapableNode.class);
36 * Constructor register supplier as DataTreeChangeListener and create wildCarded InstanceIdentifier.
38 * @param notifProviderService - {@link NotificationProviderService}
39 * @param db - {@link DataBroker}
41 public NodeNotificationSupplierImpl(final NotificationProviderService notifProviderService, final DataBroker db) {
42 super(notifProviderService, db, FlowCapableNode.class);
46 public InstanceIdentifier<FlowCapableNode> getWildCardPath() {
47 return FLOW_CAPABLE_NODE_INSTANCE_IDENTIFIER;
51 public NodeUpdated createNotification(final FlowCapableNode flowCapableNode,
52 final InstanceIdentifier<FlowCapableNode> ii) {
53 Preconditions.checkArgument(flowCapableNode != null);
54 Preconditions.checkArgument(ii != null);
55 final FlowCapableNodeUpdatedBuilder flowNodeNotifBuilder = new FlowCapableNodeUpdatedBuilder(flowCapableNode);
56 final NodeUpdatedBuilder notifBuilder = new NodeUpdatedBuilder();
57 notifBuilder.setId(ii.firstKeyOf(Node.class).getId());
58 notifBuilder.setNodeRef(new NodeRef(getNodeII(ii)));
59 notifBuilder.addAugmentation(FlowCapableNodeUpdated.class, flowNodeNotifBuilder.build());
60 return notifBuilder.build();
64 public NodeRemoved deleteNotification(final InstanceIdentifier<FlowCapableNode> path) {
65 Preconditions.checkArgument(path != null);
66 final NodeRemovedBuilder delNodeNotifBuilder = new NodeRemovedBuilder();
67 delNodeNotifBuilder.setNodeRef(new NodeRef(path));
68 return delNodeNotifBuilder.build();