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