From 242b2107596d00034b5e384b1c8f734e5b71d9ee Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 1 Aug 2024 21:42:20 +0200 Subject: [PATCH] Do not rely on registration Use explicit boolean and improve overall synchronization, so that we do not end up ignoring the DTCL event. JIRA: AAA-281 Change-Id: I789a51ebb97e5b8943dfe0e6a7df3c9c1ce4c26c Signed-off-by: Robert Varga (cherry picked from commit 25f2dbcbd3982131c7f3f0b452ccbb61df21c324) --- .../OSGiPasswordServiceConfigBootstrap.java | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/OSGiPasswordServiceConfigBootstrap.java b/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/OSGiPasswordServiceConfigBootstrap.java index 6f8dae183..d028fd4f2 100644 --- a/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/OSGiPasswordServiceConfigBootstrap.java +++ b/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/OSGiPasswordServiceConfigBootstrap.java @@ -33,7 +33,9 @@ public final class OSGiPasswordServiceConfigBootstrap implements DataListener configFactory; - private Registration registration; + private final Registration registration; + + private boolean active; private ComponentInstance instance; @Activate @@ -41,6 +43,11 @@ public OSGiPasswordServiceConfigBootstrap(@Reference final DataBroker dataBroker @Reference(target = "(component.factory=" + OSGiPasswordServiceConfig.FACTORY_NAME + ")") final ComponentFactory configFactory) { this.configFactory = requireNonNull(configFactory); + + synchronized (this) { + active = true; + } + registration = dataBroker.registerDataListener( DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(PasswordServiceConfig.class)), this); @@ -49,25 +56,38 @@ public OSGiPasswordServiceConfigBootstrap(@Reference final DataBroker dataBroker @Deactivate synchronized void deactivate() { + active = false; registration.close(); - registration = null; - if (instance != null) { - instance.dispose(); - instance = null; - } LOG.info("No longer listening for password service configuration"); + + final var oldInstance = instance; + instance = null; + disposeInstance(oldInstance); } @Override public synchronized void dataChangedTo(final PasswordServiceConfig data) { + LOG.debug("Data changed to {}", data); + + if (!active) { + LOG.debug("Ignoring change after shutdown"); + return; + } + // FIXME: at this point we need to populate default values -- from the XML file - if (registration != null) { - final var newInstance = configFactory.newInstance( - OSGiPasswordServiceConfig.props(data != null ? data : new PasswordServiceConfigBuilder().build())); - if (instance != null) { - instance.dispose(); - } - instance = newInstance; + final var newInstance = configFactory.newInstance( + OSGiPasswordServiceConfig.props(data != null ? data : new PasswordServiceConfigBuilder().build())); + LOG.debug("Instantiated configuration {}", newInstance); + + final var oldInstance = instance; + instance = newInstance; + disposeInstance(oldInstance); + } + + private static void disposeInstance(final ComponentInstance instance) { + if (instance != null) { + LOG.debug("Disposing of configuration {}", instance); + instance.dispose(); } } }