1515import io .vertx .core .impl .transports .NioTransport ;
1616import io .vertx .core .internal .VertxBootstrap ;
1717import io .vertx .core .eventbus .impl .clustered .DefaultNodeSelector ;
18+ import io .vertx .core .spi .*;
1819import io .vertx .core .spi .context .executor .EventExecutorProvider ;
1920import io .vertx .core .spi .file .FileResolver ;
2021import io .vertx .core .file .impl .FileResolverImpl ;
2122import io .vertx .core .internal .logging .Logger ;
2223import io .vertx .core .internal .logging .LoggerFactory ;
2324import io .vertx .core .json .JsonObject ;
2425import io .vertx .core .spi .transport .Transport ;
25- import io .vertx .core .spi .ExecutorServiceFactory ;
26- import io .vertx .core .spi .VertxMetricsFactory ;
27- import io .vertx .core .spi .VertxServiceProvider ;
28- import io .vertx .core .spi .VertxThreadFactory ;
29- import io .vertx .core .spi .VertxTracerFactory ;
3026import io .vertx .core .spi .cluster .ClusterManager ;
3127import io .vertx .core .eventbus .impl .clustered .NodeSelector ;
3228import io .vertx .core .spi .metrics .VertxMetrics ;
3329import io .vertx .core .spi .tracing .VertxTracer ;
3430
31+ import java .util .ArrayList ;
3532import java .util .Collection ;
3633import java .util .List ;
3734
@@ -51,13 +48,15 @@ public class VertxBootstrapImpl implements VertxBootstrap {
5148 private EventExecutorProvider eventExecutorProvider ;
5249 private ClusterManager clusterManager ;
5350 private NodeSelector clusterNodeSelector ;
51+ private List <VertxServiceProvider > serviceProviders ;
5452 private VertxTracerFactory tracerFactory ;
5553 private VertxTracer tracer ;
5654 private VertxThreadFactory threadFactory ;
5755 private ExecutorServiceFactory executorServiceFactory ;
5856 private VertxMetricsFactory metricsFactory ;
5957 private VertxMetrics metrics ;
6058 private FileResolver fileResolver ;
59+ private List <VerticleFactory > verticleFactories ;
6160
6261 public VertxBootstrapImpl (JsonObject config ) {
6362 this (new VertxOptions (config ));
@@ -85,7 +84,7 @@ public VertxBootstrap options(VertxOptions options) {
8584 }
8685
8786 @ Override
88- public VertxBootstrap enableShadowContext (boolean option ) {
87+ public VertxBootstrapImpl enableShadowContext (boolean option ) {
8988 this .enableShadowContext = option ;
9089 return this ;
9190 }
@@ -98,7 +97,7 @@ public JsonObject config() {
9897 }
9998
10099 @ Override
101- public VertxBootstrap eventExecutorProvider (EventExecutorProvider provider ) {
100+ public VertxBootstrapImpl eventExecutorProvider (EventExecutorProvider provider ) {
102101 this .eventExecutorProvider = provider ;
103102 return this ;
104103 }
@@ -163,6 +162,25 @@ public VertxBootstrapImpl tracerFactory(VertxTracerFactory factory) {
163162 return this ;
164163 }
165164
165+ /**
166+ * @return the list of service providers to use
167+ */
168+ public List <VertxServiceProvider > serviceProviders () {
169+ return serviceProviders ;
170+ }
171+
172+ /**
173+ * Set the list of service providers to use, when the list is {@code null}, Java's service loader
174+ * mechanism will be used to discover service providers.
175+ *
176+ * @param providers the service providers
177+ * @return this builder instance
178+ */
179+ public VertxBootstrapImpl serviceProviders (List <VertxServiceProvider > providers ) {
180+ this .serviceProviders = providers ;
181+ return this ;
182+ }
183+
166184 public VertxTracer tracer () {
167185 return tracer ;
168186 }
@@ -245,7 +263,7 @@ private VertxImpl instantiateVertx(ClusterManager clusterManager, NodeSelector n
245263
246264 public Vertx vertx () {
247265 VertxImpl vertx = instantiateVertx (null , null );
248- vertx .init ();
266+ vertx .init (verticleFactories );
249267 return vertx ;
250268 }
251269
@@ -261,27 +279,48 @@ public Future<Vertx> clusteredVertx() {
261279 nodeSelector = new DefaultNodeSelector ();
262280 }
263281 VertxImpl vertx = instantiateVertx (clusterManager , nodeSelector );
264- return vertx .initClustered (options );
282+ return vertx .initClustered (options , verticleFactories );
265283 }
266284
267285 /**
268- * Initialize the service providers.
269- * @return this builder instance
286+ * @return the verticle factories to use
287+ */
288+ public List <VerticleFactory > verticleFactories () {
289+ return verticleFactories ;
290+ }
291+
292+ /**
293+ * Set the list of {@code VerticleFactory} to use.
294+ *
295+ * @param verticleFactories the verticle factories
296+ * @return the builder instance
270297 */
298+ public VertxBootstrapImpl verticleFactories (List <VerticleFactory > verticleFactories ) {
299+ this .verticleFactories = verticleFactories ;
300+ return this ;
301+ }
302+
303+ @ Override
271304 public VertxBootstrapImpl init () {
305+ List <VertxServiceProvider > providers = new ArrayList <>();
272306 initTransport ();
273307 initMetrics ();
274308 initTracing ();
275- List <VertxServiceProvider > providers = ServiceHelper .loadFactories (VertxServiceProvider .class );
276309 initProviders (providers );
277310 initThreadFactory ();
278311 initExecutorServiceFactory ();
279312 initFileResolver ();
313+ initVerticleFactories ();
280314 return this ;
281315 }
282316
283- private void initProviders (Collection <VertxServiceProvider > providers ) {
284- for (VertxServiceProvider provider : providers ) {
317+ private void initProviders (Collection <VertxServiceProvider > toInit ) {
318+ List <VertxServiceProvider > serviceProviders = this .serviceProviders ;
319+ if (serviceProviders == null ) {
320+ serviceProviders = new ArrayList <>(ServiceHelper .loadFactories (VertxServiceProvider .class ));
321+ }
322+ toInit .addAll (serviceProviders );
323+ for (VertxServiceProvider provider : toInit ) {
285324 if (provider instanceof VertxMetricsFactory && (options .getMetricsOptions () == null || !options .getMetricsOptions ().isEnabled ())) {
286325 continue ;
287326 } else if (provider instanceof VertxTracerFactory && (options .getTracingOptions () == null )) {
@@ -329,6 +368,13 @@ private void initExecutorServiceFactory() {
329368 executorServiceFactory = ExecutorServiceFactory .INSTANCE ;
330369 }
331370
371+ private void initVerticleFactories () {
372+ if (verticleFactories != null ) {
373+ return ;
374+ }
375+ verticleFactories = new ArrayList <>(ServiceHelper .loadFactories (VerticleFactory .class ));
376+ }
377+
332378 private void checkBeforeInstantiating () {
333379 checkTracing ();
334380 checkMetrics ();
0 commit comments