Skip to content

Commit

Permalink
Do not rely on registration
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit 25f2dbc)
  • Loading branch information
rovarga committed Aug 1, 2024
1 parent 20d45f8 commit 242b210
Showing 1 changed file with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ public final class OSGiPasswordServiceConfigBootstrap implements DataListener<Pa
private static final Logger LOG = LoggerFactory.getLogger(OSGiPasswordServiceConfigBootstrap.class);

private final ComponentFactory<OSGiPasswordServiceConfig> configFactory;
private Registration registration;
private final Registration registration;

private boolean active;
private ComponentInstance<?> instance;

@Activate
public OSGiPasswordServiceConfigBootstrap(@Reference final DataBroker dataBroker,
@Reference(target = "(component.factory=" + OSGiPasswordServiceConfig.FACTORY_NAME + ")")
final ComponentFactory<OSGiPasswordServiceConfig> configFactory) {
this.configFactory = requireNonNull(configFactory);

synchronized (this) {
active = true;
}

registration = dataBroker.registerDataListener(
DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
InstanceIdentifier.create(PasswordServiceConfig.class)), this);
Expand All @@ -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();
}
}
}

0 comments on commit 242b210

Please sign in to comment.