2 * Copyright © 2015 Red Hat, 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
8 package org.opendaylight.ovsdb.openstack.netvirt.sfc;
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.RenderedServicePaths;
15 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
16 import org.opendaylight.yangtools.concepts.ListenerRegistration;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Data tree listener for {@link RenderedServicePath}
24 public class RspListener extends AbstractDataTreeListener<RenderedServicePath> {
25 private static final Logger LOG = LoggerFactory.getLogger(RspListener.class);
26 private ListenerRegistration<RspListener> listenerRegistration;
28 public RspListener(final INetvirtSfcOF13Provider provider, final DataBroker db) {
29 super(provider, RenderedServicePath.class);
30 Preconditions.checkNotNull(db, "DataBroker can not be null!");
32 registrationListener(db);
35 public InstanceIdentifier<RenderedServicePath> getRspIid() {
36 return InstanceIdentifier.create(RenderedServicePaths.class).child(RenderedServicePath.class);
39 private void registrationListener(final DataBroker db) {
40 final DataTreeIdentifier<RenderedServicePath> treeId =
41 new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, getRspIid());
43 LOG.info("Registering Data Change Listener for NetvirtSfc RenderedServicePath configuration.");
44 listenerRegistration = db.registerDataTreeChangeListener(treeId, this);
45 } catch (final Exception e) {
46 LOG.warn("Netvirt RenderedServicePath DataChange listener registration failed!", e);
47 throw new IllegalStateException("RspListener startup failed! System needs restart.", e);
52 public void remove(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath change) {
53 Preconditions.checkNotNull(change, "Removed object can not be null!");
54 provider.removeRsp(change);
58 public void update(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath original,
59 RenderedServicePath change) {
60 Preconditions.checkNotNull(original, "Updated original object can not be null!");
61 Preconditions.checkNotNull(original, "Updated update object can not be null!");
62 remove(identifier, original);
63 provider.addRsp(change);
67 public void add(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath change) {
68 Preconditions.checkNotNull(change, "Created object can not be null!");
69 provider.addRsp(change);
73 public void close() throws Exception {