Merge "Fixed the log level."
[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
9 package org.opendaylight.openflowplugin.applications.notification.supplier.impl;
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.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.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 /**
27  * Implementation define a contract between {@link FlowCapableNode} data object
28  * and {@link NodeUpdated} and {@link NodeRemoved} notifications.
29  */
30 public class NodeNotificationSupplierImpl extends
31         AbstractNotificationSupplierForItemRoot<FlowCapableNode, NodeUpdated, NodeRemoved> {
32
33     private static final InstanceIdentifier<FlowCapableNode> wildCardedInstanceIdent = getNodeWildII().augmentation(FlowCapableNode.class);
34
35     /**
36      * Constructor register supplier as DataChangeLister and create wildCarded InstanceIdentifier.
37      *
38      * @param notifProviderService - {@link NotificationProviderService}
39      * @param db                   - {@link DataBroker}
40      */
41     public NodeNotificationSupplierImpl(final NotificationProviderService notifProviderService, final DataBroker db) {
42         super(notifProviderService, db, FlowCapableNode.class);
43     }
44
45     @Override
46     public InstanceIdentifier<FlowCapableNode> getWildCardPath() {
47         return wildCardedInstanceIdent;
48     }
49
50     @Override
51     public NodeUpdated createNotification(final FlowCapableNode o, final InstanceIdentifier<FlowCapableNode> ii) {
52         Preconditions.checkArgument(o != null);
53         Preconditions.checkArgument(ii != null);
54         final FlowCapableNodeUpdatedBuilder flowNodeNotifBuilder = new FlowCapableNodeUpdatedBuilder(o);
55         final NodeUpdatedBuilder notifBuilder = new NodeUpdatedBuilder();
56         notifBuilder.setId(ii.firstKeyOf(Node.class, NodeKey.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