f4070682482df676bb918851aef03b2751bf1a2b
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / listener / VppEndpointListener.java
1 /*
2  * Copyright (c) 2016 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.groupbasedpolicy.renderer.vpp.listener;
10
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.groupbasedpolicy.renderer.vpp.event.VppEndpointConfEvent;
16 import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import com.google.common.base.Preconditions;
24 import com.google.common.eventbus.EventBus;
25
26 public class VppEndpointListener extends DataTreeChangeHandler<VppEndpoint> {
27
28     private static final Logger LOG = LoggerFactory.getLogger(VppEndpointListener.class);
29     private EventBus eventBus;
30
31     public VppEndpointListener(DataBroker dataProvider, EventBus eventBus) {
32         super(dataProvider);
33         this.eventBus = Preconditions.checkNotNull(eventBus);
34         registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
35                 InstanceIdentifier.builder(Config.class).child(VppEndpoint.class).build()));
36     }
37
38     @Override
39     protected void onWrite(DataObjectModification<VppEndpoint> rootNode,
40             InstanceIdentifier<VppEndpoint> rootIdentifier) {
41         VppEndpointConfEvent event =
42                 new VppEndpointConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
43         LOG.trace("Dispatching event on write: {}", event.getClass());
44         eventBus.post(event);
45     }
46
47     @Override
48     protected void onDelete(DataObjectModification<VppEndpoint> rootNode,
49             InstanceIdentifier<VppEndpoint> rootIdentifier) {
50         VppEndpointConfEvent event =
51                 new VppEndpointConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
52         LOG.trace("Dispatching event on delete: {}", event.getClass());
53         eventBus.post(event);
54     }
55
56     @Override
57     protected void onSubtreeModified(DataObjectModification<VppEndpoint> rootNode,
58             InstanceIdentifier<VppEndpoint> rootIdentifier) {
59         VppEndpointConfEvent event =
60                 new VppEndpointConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
61         LOG.trace("Dispatching event on subtree modified: {}", event.getClass());
62         eventBus.post(event);
63     }
64
65 }