From 901c6bb2c8321739b54c4b20c32ef214fe02102e Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 28 Dec 2023 22:27:36 +0100 Subject: [PATCH] Use constructor injection in OSGiDistributedDataStore Upgraded SpotBugs does not like unitialized fields. Use constructor injection to properly set them up. Change-Id: I8d5226a8b0b6b2929eba3d4d9a73ac8e1c72613a Signed-off-by: Robert Varga --- .../datastore/OSGiDistributedDataStore.java | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDistributedDataStore.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDistributedDataStore.java index 0811137efa..d365097f3b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDistributedDataStore.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDistributedDataStore.java @@ -107,26 +107,23 @@ public final class OSGiDistributedDataStore { private static final Logger LOG = LoggerFactory.getLogger(OSGiDistributedDataStore.class); - @Reference - DOMSchemaService schemaService = null; - @Reference - ActorSystemProvider actorSystemProvider = null; - @Reference - DatastoreContextIntrospectorFactory introspectorFactory = null; - @Reference - DatastoreSnapshotRestore snapshotRestore = null; - @Reference - ModuleShardConfigProvider configProvider = null; - @Reference(target = "(component.factory=" + OSGiDOMStore.FACTORY_NAME + ")") - ComponentFactory datastoreFactory = null; - + private final ComponentFactory datastoreFactory; private DatastoreState configDatastore; private DatastoreState operDatastore; @Activate - void activate(final Map properties) { - configDatastore = createDatastore(LogicalDatastoreType.CONFIGURATION, "distributed-config", properties, null); - operDatastore = createDatastore(LogicalDatastoreType.OPERATIONAL, "distributed-operational", properties, + public OSGiDistributedDataStore(@Reference final DOMSchemaService schemaService, + @Reference final ActorSystemProvider actorSystemProvider, + @Reference final DatastoreContextIntrospectorFactory introspectorFactory, + @Reference final DatastoreSnapshotRestore snapshotRestore, + @Reference final ModuleShardConfigProvider configProvider, + @Reference(target = "(component.factory=" + OSGiDOMStore.FACTORY_NAME + ")") + final ComponentFactory datastoreFactory, final Map properties) { + this.datastoreFactory = requireNonNull(datastoreFactory); + configDatastore = createDatastore(schemaService, actorSystemProvider, snapshotRestore, introspectorFactory, + LogicalDatastoreType.CONFIGURATION, "distributed-config", properties, null); + operDatastore = createDatastore(schemaService, actorSystemProvider, snapshotRestore, introspectorFactory, + LogicalDatastoreType.OPERATIONAL, "distributed-operational", properties, new ConfigurationImpl(configProvider)); } @@ -145,14 +142,16 @@ public final class OSGiDistributedDataStore { configDatastore = null; } - private DatastoreState createDatastore(final LogicalDatastoreType datastoreType, final String serviceType, - final Map properties, final Configuration config) { + private DatastoreState createDatastore(final DOMSchemaService schemaService, + final ActorSystemProvider actorSystemProvider, final DatastoreSnapshotRestore snapshotRestore, + final DatastoreContextIntrospectorFactory introspectorFactory, final LogicalDatastoreType datastoreType, + final String serviceType, final Map properties,final Configuration config) { LOG.info("Distributed Datastore type {} starting", datastoreType); - final DatastoreContextIntrospector introspector = introspectorFactory.newInstance(datastoreType, properties); - final AbstractDataStore datastore = DistributedDataStoreFactory.createInstance(actorSystemProvider, + final var introspector = introspectorFactory.newInstance(datastoreType, properties); + final var datastore = DistributedDataStoreFactory.createInstance(actorSystemProvider, introspector.getContext(), introspector, snapshotRestore, config); datastore.setCloseable(schemaService.registerSchemaContextListener(datastore)); - final DatastoreState state = new DatastoreState(introspector, datastoreType, datastore, serviceType); + final var state = new DatastoreState(introspector, datastoreType, datastore, serviceType); Futures.addCallback(datastore.initialSettleFuture(), state, // Note we are invoked from shard manager and therefore could block it, hence the round-trip to executor -- 2.36.6