Skip to content

Commit

Permalink
Use constructor injection in aaa-password-service
Browse files Browse the repository at this point in the history
Clean up OSGiPasswordServiceConfigBootstrap to not leak its
implementation details into the service registry and use constructor
injection to keep upgraded SpotBugs happy.

Change-Id: I15ff8bc4b4af6305bc30a95b71402919501d7164
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
  • Loading branch information
rovarga committed Dec 29, 2023
1 parent f427f23 commit 5453e02
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package org.opendaylight.aaa.impl.password.service;

import static java.util.Objects.requireNonNull;

import com.google.common.annotations.Beta;
import com.google.common.collect.Iterables;
import java.util.Collection;
Expand All @@ -30,22 +32,20 @@
import org.slf4j.LoggerFactory;

@Beta
@Component(immediate = true)
@Component(service = { })
public final class OSGiPasswordServiceConfigBootstrap
implements ClusteredDataTreeChangeListener<PasswordServiceConfig> {
private static final Logger LOG = LoggerFactory.getLogger(OSGiPasswordServiceConfigBootstrap.class);

@Reference
DataBroker dataBroker = null;

@Reference(target = "(component.factory=" + OSGiPasswordServiceConfig.FACTORY_NAME + ")")
ComponentFactory<OSGiPasswordServiceConfig> configFactory = null;

private final ComponentFactory<OSGiPasswordServiceConfig> configFactory;
private ListenerRegistration<?> registration;
private ComponentInstance<?> instance;

@Activate
synchronized void activate() {
public OSGiPasswordServiceConfigBootstrap(@Reference final DataBroker dataBroker,
@Reference(target = "(component.factory=" + OSGiPasswordServiceConfig.FACTORY_NAME + ")")
final ComponentFactory<OSGiPasswordServiceConfig> configFactory) {
this.configFactory = requireNonNull(configFactory);
registration = dataBroker.registerDataTreeChangeListener(
DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
InstanceIdentifier.create(PasswordServiceConfig.class)), this);
Expand Down Expand Up @@ -77,7 +77,7 @@ public synchronized void onDataTreeChanged(final Collection<DataTreeModification
@Holding("this")
private void updateInstance(final PasswordServiceConfig config) {
if (registration != null) {
final ComponentInstance<?> newInstance = configFactory.newInstance(
final var newInstance = configFactory.newInstance(
OSGiPasswordServiceConfig.props(config != null ? config : new PasswordServiceConfigBuilder().build()));
if (instance != null) {
instance.dispose();
Expand Down

0 comments on commit 5453e02

Please sign in to comment.