Skip to content

Commit 06ea513

Browse files
control plane > use immutable lists for module dicovery
1 parent f3107b3 commit 06ea513

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

hivemq-edge/src/main/java/com/hivemq/HiveMQEdgeBootstrap.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ private void bootstrapCoreComponents() {
163163

164164
try {
165165
commercialModuleLoaderDiscovery = new CommercialModuleLoaderDiscovery(moduleLoader);
166-
commercialModuleLoaderDiscovery.discoverModuleLoaderMainClasses();
167166
generalBootstrapService =
168167
new GeneralBootstrapServiceImpl(shutdownHooks, metricRegistry, systemInformation, configService, hivemqId);
169168
commercialModuleLoaderDiscovery.generalBootstrap(generalBootstrapService);

hivemq-edge/src/main/java/com/hivemq/extensions/core/CommercialModuleLoaderDiscovery.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.hivemq.extensions.core;
1717

18+
import com.google.common.collect.ImmutableList;
1819
import com.hivemq.bootstrap.services.CompleteBootstrapService;
1920
import com.hivemq.bootstrap.services.GeneralBootstrapService;
2021
import com.hivemq.bootstrap.services.PersistenceBootstrapService;
@@ -23,39 +24,28 @@
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526

26-
import java.util.ArrayList;
27-
import java.util.List;
28-
2927
public class CommercialModuleLoaderDiscovery {
3028

3129
private static final @NotNull Logger log = LoggerFactory.getLogger(CommercialModuleLoaderDiscovery.class);
32-
private final @NotNull ModuleLoader moduleLoader;
33-
private final List<ModuleLoaderMain> instances = new ArrayList<>();
30+
private final @NotNull ImmutableList<ModuleLoaderMain> instances;
3431

3532
public CommercialModuleLoaderDiscovery(
3633
final @NotNull ModuleLoader moduleLoader) {
37-
this.moduleLoader = moduleLoader;
38-
}
39-
40-
public void discoverModuleLoaderMainClasses() {
4134
moduleLoader.loadModules();
42-
final List<Class<? extends ModuleLoaderMain>> implementations =
43-
moduleLoader.findImplementations(ModuleLoaderMain.class);
44-
45-
implementations.forEach(impl -> {
35+
final ImmutableList.Builder<ModuleLoaderMain> builder = ImmutableList.builder();
36+
moduleLoader.findImplementations(ModuleLoaderMain.class).forEach(impl -> {
4637
try {
47-
this.instances.add(impl.getDeclaredConstructor().newInstance());
38+
builder.add(impl.getDeclaredConstructor().newInstance());
4839
} catch (Exception e) {
4940
log.error("Error when instancing '{}':", impl, e);
5041
}
5142
});
43+
this.instances = builder.build();
5244
}
5345

5446
public void generalBootstrap(final @NotNull GeneralBootstrapService generalBootstrapService) {
5547
try {
56-
for (ModuleLoaderMain instance : instances) {
57-
instance.generalBootstrap(generalBootstrapService);
58-
}
48+
instances.forEach(instance -> instance.generalBootstrap(generalBootstrapService));
5949
} catch (Exception e) {
6050
log.error("Error when bootstrapping general information", e);
6151
}

0 commit comments

Comments
 (0)