import static java.util.Collections.emptyList;
-import java.math.BigInteger;
import java.util.List;
-import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.infrautils.utils.concurrent.Executors;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
import org.opendaylight.netvirt.elan.utils.ElanUtils;
+import org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
public class ElanDpnInterfacesListener
- extends AsyncDataTreeChangeListenerBase<DpnInterfaces, ElanDpnInterfacesListener> {
+ extends AbstractAsyncDataTreeChangeListener<DpnInterfaces> {
private static final Logger LOG = LoggerFactory.getLogger(ElanDpnInterfacesListener.class);
private final DataBroker dataBroker;
public ElanDpnInterfacesListener(final DataBroker dataBroker, final IInterfaceManager interfaceManager,
final ElanServiceProvider elanService, final JobCoordinator jobCoordinator,
final ElanInstanceCache elanInstanceCache) {
+ super(dataBroker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ElanDpnInterfaces.class)
+ .child(ElanDpnInterfacesList.class).child(DpnInterfaces.class),
+ Executors.newListeningSingleThreadExecutor("ElanDpnInterfacesListener", LOG));
this.dataBroker = dataBroker;
this.interfaceManager = interfaceManager;
this.elanService = elanService;
this.elanInstanceCache = elanInstanceCache;
}
- @PostConstruct
public void start() {
- registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
+ LOG.info("{} start", getClass().getSimpleName());
}
@Override
- public InstanceIdentifier<DpnInterfaces> getWildCardPath() {
- return InstanceIdentifier.builder(ElanDpnInterfaces.class).child(ElanDpnInterfacesList.class)
- .child(DpnInterfaces.class).build();
- }
-
- @Override
- protected void remove(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces dpnInterfaces) {
+ public void remove(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces dpnInterfaces) {
}
@Override
- protected void update(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces original,
+ public void update(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces original,
DpnInterfaces update) {
LOG.debug("received Dpninterfaces update event for dpn {}", update.getDpId());
- BigInteger dpnId = update.getDpId();
+ Uint64 dpnId = update.getDpId();
String elanInstanceName = identifier.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
- ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
+ ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orElse(null);
if (elanInstance != null && !elanInstance.isExternal() && ElanUtils.isVlan(elanInstance)) {
List<String> interfaces = update.getInterfaces();
}
@Override
- protected void add(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces dpnInterfaces) {
+ public void add(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces dpnInterfaces) {
LOG.debug("received Dpninterfaces add event for dpn {}", dpnInterfaces.getDpId());
- BigInteger dpnId = dpnInterfaces.getDpId();
+ Uint64 dpnId = dpnInterfaces.getDpId();
String elanInstanceName = identifier.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
- ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
+ ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orElse(null);
// trigger creation of vlan provider intf for the vlan provider network
// on br-int patch port for this DPN
}
@Override
- protected ElanDpnInterfacesListener getDataTreeChangeListener() {
- return ElanDpnInterfacesListener.this;
+ @PreDestroy
+ public void close() {
+ super.close();
+ Executors.shutdownAndAwaitTermination(getExecutorService());
}
}