Skip to content

Commit

Permalink
Hook for VertxBuilder customization
Browse files Browse the repository at this point in the history
Given methods like TracingOptions#setTracer have been deprecated, a new hook can help users configure the Vert.x instance.

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
  • Loading branch information
tsegismont committed Aug 26, 2024
1 parent 6ddbde4 commit 3f930dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/main/java/io/vertx/core/impl/launcher/VertxLifecycleHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.impl.VertxBuilder;
import io.vertx.core.json.JsonObject;
import io.vertx.core.spi.tracing.VertxTracer;

/**
* Interface that let sub-classes of launcher to be notified on different events.
Expand All @@ -31,6 +33,18 @@ public interface VertxLifecycleHooks {
*/
void afterConfigParsed(JsonObject config);

/**
* Default implementation for the {@link VertxBuilder} creation.
* <p>
* This can be overridden in order to customize, for example, the tracer, with {@link VertxBuilder#tracer(VertxTracer)}.
*
* @param config the Vert.x options to use, in JSON format
* @return the Vert.x builder instance
*/
default VertxBuilder createVertxBuilder(JsonObject config) {
return config == null ? new VertxBuilder() : new VertxBuilder(config);
}

/**
* Hook for sub-classes of the {@link io.vertx.core.Launcher} class before the vertx instance is started. Options
* can still be updated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,8 @@ public void run(Runnable action) {
protected Vertx startVertx() {
JsonObject optionsJson = getJsonFromFileOrString(vertxOptions, "options");

EventBusOptions eventBusOptions;
VertxBuilder builder;
if (optionsJson == null) {
eventBusOptions = getEventBusOptions();
builder = new VertxBuilder();
} else {
eventBusOptions = getEventBusOptions(optionsJson.getJsonObject("eventBusOptions"));
builder = new VertxBuilder(optionsJson);
}
EventBusOptions eventBusOptions = optionsJson == null ? getEventBusOptions() : getEventBusOptions(optionsJson.getJsonObject("eventBusOptions"));
VertxBuilder builder = createVertxBuilder(optionsJson);
options = builder.options();
options.setEventBusOptions(eventBusOptions);

Expand Down Expand Up @@ -338,6 +331,14 @@ protected void beforeStartingVertx(VertxOptions options) {
}
}

protected VertxBuilder createVertxBuilder(JsonObject config) {
Object main = executionContext.main();
if (main instanceof VertxLifecycleHooks) {
return ((VertxLifecycleHooks) main).createVertxBuilder(config);
}
return new VertxBuilder(config);
}

/**
* @return the event bus options.
*/
Expand Down

0 comments on commit 3f930dc

Please sign in to comment.