import java.util.List;
import java.util.Map;
import java.util.Set;
-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.AsyncClusteredDataTreeChangeListenerBase;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
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.mdsal.eos.binding.api.EntityOwnershipService;
import org.opendaylight.netvirt.elan.l2gw.recovery.impl.L2GatewayInstanceRecoveryHandler;
import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayUtils;
import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
import org.opendaylight.serviceutils.srm.RecoverableListener;
import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
+import org.opendaylight.serviceutils.tools.listener.AbstractClusteredAsyncDataTreeChangeListener;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
import org.slf4j.LoggerFactory;
@Singleton
-public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<L2gateway, L2GatewayListener>
+public class L2GatewayListener extends AbstractClusteredAsyncDataTreeChangeListener<L2gateway>
implements RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(L2GatewayListener.class);
private final DataBroker dataBroker;
final JobCoordinator jobCoordinator, final L2GatewayCache l2GatewayCache,
L2GatewayInstanceRecoveryHandler l2GatewayInstanceRecoveryHandler,
ServiceRecoveryRegistry serviceRecoveryRegistry) {
+ super(dataBroker, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Neutron.class)
+ .child(L2gateways.class).child(L2gateway.class),
+ Executors.newListeningSingleThreadExecutor("L2GatewayListener", LOG));
this.dataBroker = dataBroker;
this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
this.entityOwnershipUtils = new EntityOwnershipUtils(entityOwnershipService);
this.l2GatewayCache = l2GatewayCache;
serviceRecoveryRegistry.addRecoverableListener(l2GatewayInstanceRecoveryHandler.buildServiceRegistryKey(),
this);
+ init();
}
- @PostConstruct
public void init() {
LOG.info("{} init", getClass().getSimpleName());
- registerListener();
+ }
+
+ @Override
+ @PreDestroy
+ public void close() {
+ super.close();
+ Executors.shutdownAndAwaitTermination(getExecutorService());
}
public void registerListener() {
+ super.register();
LOG.info("Registering L2Gateway Listener");
- registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
}
public void deregisterListener() {
+ super.close();
LOG.info("Deregistering L2GatewayListener");
- super.deregisterListener();
}
@Override
- protected InstanceIdentifier<L2gateway> getWildCardPath() {
- return InstanceIdentifier.create(Neutron.class).child(L2gateways.class).child(L2gateway.class);
- }
-
- @Override
- protected void add(final InstanceIdentifier<L2gateway> identifier, final L2gateway input) {
+ public void add(final InstanceIdentifier<L2gateway> identifier, final L2gateway input) {
LOG.info("Adding L2gateway with ID: {}", input.getUuid());
for (Devices l2Device : input.nonnullDevices()) {
}
@Override
- protected void remove(final InstanceIdentifier<L2gateway> identifier, final L2gateway input) {
+ public void remove(final InstanceIdentifier<L2gateway> identifier, final L2gateway input) {
LOG.info("Removing L2gateway with ID: {}", input.getUuid());
List<L2gatewayConnection> connections = l2gwService
.getL2GwConnectionsByL2GatewayId(input.getUuid());
}
@Override
- protected void update(InstanceIdentifier<L2gateway> identifier, L2gateway original, L2gateway update) {
+ public void update(InstanceIdentifier<L2gateway> identifier, L2gateway original, L2gateway update) {
LOG.trace("Updating L2gateway : key: {}, original value={}, update value={}", identifier, original, update);
List<L2gatewayConnection> connections = l2gwService.getAssociatedL2GwConnections(
Sets.newHashSet(update.getUuid()));
}
}
- @Override
- protected L2GatewayListener getDataTreeChangeListener() {
- return this;
- }
-
static class DeviceInterfaces {
Map<String, Map<String, Interfaces>> deviceInterfacesMap = new HashMap<>();