diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-08-10 14:39:30 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-08-14 07:01:06 +0000 |
commit | 6923420946f05308af6a073d270df41d069dd532 (patch) | |
tree | d5e233246a792d223e92253bcc19f1b9b579cc8b /infra/northbound/bgp/src/main | |
parent | d0688f2883b3231e743dcd53bbf2203ec4639c6e (diff) |
Shutdown closing of resources
Change-Id: If57a5414153cb983138872c7a1ded7c7066b1b6d
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'infra/northbound/bgp/src/main')
3 files changed, 36 insertions, 23 deletions
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BGPExtensionConsumerContextProvider.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BGPExtensionConsumerContextProvider.java index 106a882ec..1bb0c5a1b 100644 --- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BGPExtensionConsumerContextProvider.java +++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BGPExtensionConsumerContextProvider.java @@ -18,6 +18,7 @@ package io.fd.honeycomb.infra.bgp; import com.google.inject.Inject; import io.fd.honeycomb.binding.init.ProviderTrait; +import io.fd.honeycomb.data.init.ShutdownHandler; import java.util.ArrayList; import java.util.Set; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext; @@ -34,6 +35,9 @@ final class BGPExtensionConsumerContextProvider extends ProviderTrait<BGPExtensi @Inject private Set<BGPExtensionProviderActivator> activators; + @Inject + private ShutdownHandler shutdownHandler; + @Override protected BGPExtensionConsumerContext create() { final BGPExtensionProviderContext ctx = new SimpleBGPExtensionProviderContext(); @@ -41,6 +45,7 @@ final class BGPExtensionConsumerContextProvider extends ProviderTrait<BGPExtensi new SimpleBGPExtensionProviderContextActivator(ctx, new ArrayList<>(activators)); LOG.debug("Starting BGPExtensionConsumerContext with activators: {}", activators); activator.start(); + shutdownHandler.register("bgp-extension-context-activator", activator); return ctx; } } diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java index a25808850..60d478325 100644 --- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java +++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java @@ -21,6 +21,7 @@ import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUti import com.google.common.collect.ImmutableList; import com.google.inject.Inject; import io.fd.honeycomb.binding.init.ProviderTrait; +import io.fd.honeycomb.data.init.ShutdownHandler; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -70,6 +71,8 @@ final class BgpRIBProvider extends ProviderTrait<RIB> { private BGPTableTypeRegistryConsumer tableTypeRegistry; @Inject private SchemaService schemaService; + @Inject + private ShutdownHandler shutdownHandler; @Override protected RIB create() { @@ -79,48 +82,49 @@ final class BgpRIBProvider extends ProviderTrait<RIB> { LOG.debug("Creating BGP RIB: routerId={}, asNumber={}", routerId, asNumber); // TODO configure other BGP Multiprotocol extensions: final List<AfiSafi> afiSafi = ImmutableList.of( - new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class) - .addAugmentation(AfiSafi2.class, - new AfiSafi2Builder().setReceive(cfg.isBgpMultiplePathsEnabled()) - .setSendMax(cfg.bgpSendMaxMaths.get().shortValue()).build()) - .build(), - new AfiSafiBuilder().setAfiSafiName(IPV4LABELLEDUNICAST.class) - .addAugmentation(AfiSafi2.class, - new AfiSafi2Builder().setReceive(cfg.isBgpMultiplePathsEnabled()) - .setSendMax(cfg.bgpSendMaxMaths.get().shortValue()).build()) - .build() - ); + new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class) + .addAugmentation(AfiSafi2.class, + new AfiSafi2Builder().setReceive(cfg.isBgpMultiplePathsEnabled()) + .setSendMax(cfg.bgpSendMaxMaths.get().shortValue()).build()) + .build(), + new AfiSafiBuilder().setAfiSafiName(IPV4LABELLEDUNICAST.class) + .addAugmentation(AfiSafi2.class, + new AfiSafi2Builder().setReceive(cfg.isBgpMultiplePathsEnabled()) + .setSendMax(cfg.bgpSendMaxMaths.get().shortValue()).build()) + .build() + ); final Map<TablesKey, PathSelectionMode> pathSelectionModes = - OpenConfigMappingUtil.toPathSelectionMode(afiSafi, tableTypeRegistry) - .entrySet().stream().collect(Collectors.toMap(entry -> - new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue)); + OpenConfigMappingUtil.toPathSelectionMode(afiSafi, tableTypeRegistry) + .entrySet().stream().collect(Collectors.toMap(entry -> + new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue)); // based on org.opendaylight.protocol.bgp.rib.impl.config.RibImpl.createRib + final PingPongDataBroker pingPongDataBroker = new PingPongDataBroker(domBroker); final RIBImpl rib = - new RIBImpl(new NoopClusterSingletonServiceProvider(), new RibId(cfg.bgpProtocolInstanceName.get()), - asNumber, new BgpId(routerId), clusterId, extensions, dispatcher, codec, - new PingPongDataBroker(domBroker), toTableTypes(afiSafi, tableTypeRegistry), pathSelectionModes, - extensions.getClassLoadingStrategy(), null); + new RIBImpl(new NoopClusterSingletonServiceProvider(), new RibId(cfg.bgpProtocolInstanceName.get()), + asNumber, new BgpId(routerId), clusterId, extensions, dispatcher, codec, + pingPongDataBroker, toTableTypes(afiSafi, tableTypeRegistry), pathSelectionModes, + extensions.getClassLoadingStrategy(), null); // required for proper RIB's CodecRegistry initialization (based on RIBImpl.start) schemaService.registerSchemaContextListener(rib); - + shutdownHandler.register("ping-pong-data-broker", pingPongDataBroker); LOG.debug("BGP RIB created successfully: {}", rib); return rib; } /** - * HC does not support clustering, but BGP uses {@link ClusterSingletonServiceProvider} - * to initialize {@link RIBImpl}. Therefore we provide this dummy implementation. + * HC does not support clustering, but BGP uses {@link ClusterSingletonServiceProvider} to initialize {@link + * RIBImpl}. Therefore we provide this dummy implementation. */ private static final class NoopClusterSingletonServiceProvider implements ClusterSingletonServiceProvider { private static final Logger LOG = LoggerFactory.getLogger(NoopClusterSingletonServiceProvider.class); private static final ClusterSingletonServiceRegistration REGISTRATION = - () -> LOG.debug("Closing ClusterSingletonServiceRegistration"); + () -> LOG.debug("Closing ClusterSingletonServiceRegistration"); @Override public ClusterSingletonServiceRegistration registerClusterSingletonService( - final ClusterSingletonService clusterSingletonService) { + final ClusterSingletonService clusterSingletonService) { clusterSingletonService.instantiateServiceInstance(); return REGISTRATION; } diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/RIBExtensionConsumerContextProvider.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/RIBExtensionConsumerContextProvider.java index 696726ac4..07ab86992 100644 --- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/RIBExtensionConsumerContextProvider.java +++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/RIBExtensionConsumerContextProvider.java @@ -18,6 +18,7 @@ package io.fd.honeycomb.infra.bgp; import com.google.inject.Inject; import io.fd.honeycomb.binding.init.ProviderTrait; +import io.fd.honeycomb.data.init.ShutdownHandler; import java.util.ArrayList; import java.util.Set; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext; @@ -32,6 +33,8 @@ public class RIBExtensionConsumerContextProvider extends ProviderTrait<RIBExtens private static final Logger LOG = LoggerFactory.getLogger(RIBExtensionConsumerContextProvider.class); @Inject private Set<RIBExtensionProviderActivator> activators; + @Inject + private ShutdownHandler shutdownHandler; @Override protected RIBExtensionConsumerContext create() { @@ -40,6 +43,7 @@ public class RIBExtensionConsumerContextProvider extends ProviderTrait<RIBExtens new SimpleRIBExtensionProviderContextActivator(ctx, new ArrayList<>(activators)); LOG.debug("Starting RIBExtensionConsumerContext with activators: {}", activators); activator.start(); + shutdownHandler.register("rib-extension-consumer-context-activator", activator); return ctx; } } |