2 * Copyright (c) 2016 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.groupbasedpolicy.renderer.vpp.listener;
11 import javax.annotation.Nonnull;
13 import org.opendaylight.controller.config.yang.config.vpp_provider.impl.VppRenderer;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
16 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.groupbasedpolicy.renderer.vpp.event.RendererPolicyConfEvent;
19 import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
20 import org.opendaylight.groupbasedpolicy.util.IidFactory;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicy;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.Preconditions;
27 import com.google.common.eventbus.EventBus;
29 public class RendererPolicyListener extends DataTreeChangeHandler<RendererPolicy> {
31 private static final Logger LOG = LoggerFactory.getLogger(RendererPolicyListener.class);
32 private EventBus eventBus;
34 public RendererPolicyListener(@Nonnull DataBroker dataProvider, @Nonnull EventBus eventBus) {
36 this.eventBus = Preconditions.checkNotNull(eventBus);
37 registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
38 IidFactory.rendererIid(VppRenderer.NAME).child(RendererPolicy.class)));
42 protected void onWrite(DataObjectModification<RendererPolicy> rootNode,
43 InstanceIdentifier<RendererPolicy> rootIdentifier) {
44 RendererPolicyConfEvent event =
45 new RendererPolicyConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
46 LOG.trace("Dispatching event on write: {}", event.getClass());
51 protected void onDelete(DataObjectModification<RendererPolicy> rootNode,
52 InstanceIdentifier<RendererPolicy> rootIdentifier) {
53 RendererPolicyConfEvent event =
54 new RendererPolicyConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
55 LOG.trace("Dispatching event on delete: {}", event.getClass());
60 protected void onSubtreeModified(DataObjectModification<RendererPolicy> rootNode,
61 InstanceIdentifier<RendererPolicy> rootIdentifier) {
62 RendererPolicyConfEvent event =
63 new RendererPolicyConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
64 LOG.trace("Dispatching event on subtree modified: {}", event.getClass());