|
15 | 15 | */ |
16 | 16 | package com.hivemq.extensions.core; |
17 | 17 |
|
| 18 | +import com.google.common.collect.ImmutableList; |
18 | 19 | import com.hivemq.bootstrap.services.CompleteBootstrapService; |
19 | 20 | import com.hivemq.bootstrap.services.GeneralBootstrapService; |
20 | 21 | import com.hivemq.bootstrap.services.PersistenceBootstrapService; |
|
23 | 24 | import org.slf4j.Logger; |
24 | 25 | import org.slf4j.LoggerFactory; |
25 | 26 |
|
26 | | -import java.util.ArrayList; |
27 | | -import java.util.List; |
28 | | - |
29 | 27 | public class CommercialModuleLoaderDiscovery { |
30 | 28 |
|
31 | 29 | 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; |
34 | 31 |
|
35 | 32 | public CommercialModuleLoaderDiscovery( |
36 | 33 | final @NotNull ModuleLoader moduleLoader) { |
37 | | - this.moduleLoader = moduleLoader; |
38 | | - } |
39 | | - |
40 | | - public void discoverModuleLoaderMainClasses() { |
41 | 34 | 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 -> { |
46 | 37 | try { |
47 | | - this.instances.add(impl.getDeclaredConstructor().newInstance()); |
| 38 | + builder.add(impl.getDeclaredConstructor().newInstance()); |
48 | 39 | } catch (Exception e) { |
49 | 40 | log.error("Error when instancing '{}':", impl, e); |
50 | 41 | } |
51 | 42 | }); |
| 43 | + this.instances = builder.build(); |
52 | 44 | } |
53 | 45 |
|
54 | 46 | public void generalBootstrap(final @NotNull GeneralBootstrapService generalBootstrapService) { |
55 | 47 | try { |
56 | | - for (ModuleLoaderMain instance : instances) { |
57 | | - instance.generalBootstrap(generalBootstrapService); |
58 | | - } |
| 48 | + instances.forEach(instance -> instance.generalBootstrap(generalBootstrapService)); |
59 | 49 | } catch (Exception e) { |
60 | 50 | log.error("Error when bootstrapping general information", e); |
61 | 51 | } |
|
0 commit comments