2 * Copyright (c) 2013, 2015 Dell, 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.ovsdb.openstack.netvirt.sfc;
11 import java.util.Collection;
13 import com.google.common.base.Preconditions;
14 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
15 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * AbstractChangeListner implemented basic {@link AsyncDataChangeEvent} processing for
24 * netvirt-sfc data change listener.
26 public abstract class AbstractDataTreeListener<T extends DataObject> implements INetvirtSfcDataProcessor<T> {
27 private static final Logger LOG = LoggerFactory.getLogger(AbstractDataTreeListener.class);
28 protected INetvirtSfcOF13Provider provider;
29 protected final Class<T> clazz;
31 public AbstractDataTreeListener(INetvirtSfcOF13Provider provider, Class<T> clazz) {
32 this.provider = Preconditions.checkNotNull(provider, "provider can not be null!");
33 this.clazz = Preconditions.checkNotNull(clazz, "Class can not be null!");
37 public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
38 Preconditions.checkNotNull(changes, "Changes may not be null!");
40 LOG.info("Received Data Tree Changed ...", changes);
41 for (DataTreeModification<T> change : changes) {
42 final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
43 final DataObjectModification<T> mod = change.getRootNode();
44 LOG.info("Received Data Tree Changed Update of Type={} for Key={}", mod.getModificationType(), key);
45 switch (mod.getModificationType()) {
47 remove(key, mod.getDataBefore());
49 case SUBTREE_MODIFIED:
50 update(key, mod.getDataBefore(), mod.getDataAfter());
53 if (mod.getDataBefore() == null) {
54 add(key, mod.getDataAfter());
56 update(key, mod.getDataBefore(), mod.getDataAfter());
60 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());