Merge remote-tracking branch 'liblldp/master'
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / NodeConnectorNotificationSupplierImpl.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.FlowCapableNodeConnector;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdated;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdatedBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemovedBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdatedBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 /**
27  * Implementation define a contract between {@link FlowCapableNodeConnector} data object
28  * and {@link NodeConnectorUpdated} and {@link NodeConnectorRemoved} notifications.
29  */
30 public class NodeConnectorNotificationSupplierImpl extends
31         AbstractNotificationSupplierForItemRoot<FlowCapableNodeConnector, NodeConnectorUpdated, NodeConnectorRemoved> {
32
33     private static final InstanceIdentifier<FlowCapableNodeConnector> FLOW_CAPABLE_NODE_CONNECTOR_INSTANCE_IDENTIFIER
34             = getNodeWildII().child(NodeConnector.class).augmentation(FlowCapableNodeConnector.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 NodeConnectorNotificationSupplierImpl(final NotificationProviderService notifProviderService,
43                                                  final DataBroker db) {
44         super(notifProviderService, db, FlowCapableNodeConnector.class);
45     }
46
47     @Override
48     public InstanceIdentifier<FlowCapableNodeConnector> getWildCardPath() {
49         return FLOW_CAPABLE_NODE_CONNECTOR_INSTANCE_IDENTIFIER;
50     }
51
52     @Override
53     public NodeConnectorUpdated createNotification(final FlowCapableNodeConnector flowCapableNodeConnector,
54                                                    final InstanceIdentifier<FlowCapableNodeConnector> path) {
55         Preconditions.checkArgument(flowCapableNodeConnector != null);
56         Preconditions.checkArgument(path != null);
57         final NodeConnectorUpdatedBuilder notifBuilder = new NodeConnectorUpdatedBuilder();
58         final FlowCapableNodeConnectorUpdatedBuilder connNotifBuilder = new FlowCapableNodeConnectorUpdatedBuilder(
59                 flowCapableNodeConnector);
60         notifBuilder.setId(path.firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId());
61         notifBuilder.setNodeConnectorRef(new NodeConnectorRef(path));
62         notifBuilder.addAugmentation(FlowCapableNodeConnectorUpdated.class, connNotifBuilder.build());
63         return notifBuilder.build();
64     }
65
66     @Override
67     public NodeConnectorRemoved deleteNotification(final InstanceIdentifier<FlowCapableNodeConnector> path) {
68         Preconditions.checkArgument(path != null);
69         final NodeConnectorRemovedBuilder notifBuilder = new NodeConnectorRemovedBuilder();
70         notifBuilder.setNodeConnectorRef(new NodeConnectorRef(path));
71         return notifBuilder.build();
72     }
73 }
74