From eb5159c0ece201c186b155e71c78db62a89e793a Mon Sep 17 00:00:00 2001 From: sinri Date: Mon, 20 May 2024 17:49:43 +0800 Subject: [PATCH] 3.2.7-SNAPSHOT Fix Bug: Logging initialization is too early in KeelVerticle Impls. Signed-off-by: sinri --- .../sinri/keel/facade/async/KeelAsyncKit.java | 3 ++- .../sinri/keel/maids/gatling/KeelGatling.java | 2 +- .../keel/maids/watchman/KeelCronWatchman.java | 2 +- .../keel/maids/watchman/KeelWatchmanImpl.java | 2 +- .../sinri/keel/servant/funnel/KeelFunnel.java | 3 ++- .../intravenous/KeelIntravenousBase.java | 2 +- .../sinri/keel/servant/queue/KeelQueue.java | 3 ++- .../keel/servant/queue/KeelQueueTask.java | 4 ++-- .../keel/servant/sundial/KeelSundial.java | 3 +-- .../servant/sundial/KeelSundialVerticle.java | 2 +- .../keel/verticles/KeelVerticleImplPure.java | 17 +++++++++++++ .../KeelVerticleImplWithEventLogger.java | 24 +++++++++++++++++-- .../KeelVerticleImplWithIssueRecorder.java | 24 +++++++++++++++++-- .../sinri/keel/web/http/KeelHttpServer.java | 2 +- .../lab/blocking/BlockingVerticlePlanA.java | 4 +++- .../lab/blocking/BlockingVerticlePlanB.java | 3 +-- .../test/lab/launcher/TestMainVerticle.java | 2 +- 17 files changed, 81 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/github/sinri/keel/facade/async/KeelAsyncKit.java b/src/main/java/io/github/sinri/keel/facade/async/KeelAsyncKit.java index e060f04d..8761da58 100644 --- a/src/main/java/io/github/sinri/keel/facade/async/KeelAsyncKit.java +++ b/src/main/java/io/github/sinri/keel/facade/async/KeelAsyncKit.java @@ -216,8 +216,9 @@ static Future vertxizedRawFuture(@Nonnull java.util.concurrent.Future static Future executeBlocking(@Nonnull Handler> blockingCodeHandler) { Promise promise = Promise.promise(); KeelVerticle verticle = new KeelVerticleImplPure() { + @Override - public void start() { + protected void startAsPureKeelVerticle() { blockingCodeHandler.handle(promise); promise.future().onComplete(ar -> this.undeployMe()); } diff --git a/src/main/java/io/github/sinri/keel/maids/gatling/KeelGatling.java b/src/main/java/io/github/sinri/keel/maids/gatling/KeelGatling.java index aa59beaa..42cc09b1 100644 --- a/src/main/java/io/github/sinri/keel/maids/gatling/KeelGatling.java +++ b/src/main/java/io/github/sinri/keel/maids/gatling/KeelGatling.java @@ -42,7 +42,7 @@ protected Future rest() { } @Override - public void start() throws Exception { + protected void startAsKeelVerticle() { barrelUsed.set(0); KeelAsyncKit.repeatedlyCall(routineResult -> { return fireOnce(); diff --git a/src/main/java/io/github/sinri/keel/maids/watchman/KeelCronWatchman.java b/src/main/java/io/github/sinri/keel/maids/watchman/KeelCronWatchman.java index 4efd3eba..d3e07ed1 100644 --- a/src/main/java/io/github/sinri/keel/maids/watchman/KeelCronWatchman.java +++ b/src/main/java/io/github/sinri/keel/maids/watchman/KeelCronWatchman.java @@ -207,7 +207,7 @@ public final KeelWatchmanEventHandler regularHandler() { } @Override - public void start() { + protected void startAsKeelVerticle() { Future.succeededFuture() .compose(v -> cronTabUpdateStartup.apply(eventBusAddress())) .onSuccess(v -> super.start()) diff --git a/src/main/java/io/github/sinri/keel/maids/watchman/KeelWatchmanImpl.java b/src/main/java/io/github/sinri/keel/maids/watchman/KeelWatchmanImpl.java index 6c30c978..09870e05 100644 --- a/src/main/java/io/github/sinri/keel/maids/watchman/KeelWatchmanImpl.java +++ b/src/main/java/io/github/sinri/keel/maids/watchman/KeelWatchmanImpl.java @@ -29,7 +29,7 @@ protected String eventBusAddress() { } @Override - public void start() { + protected void startAsKeelVerticle() { this.consumer = Keel.getVertx().eventBus().consumer(eventBusAddress()); this.consumer.handler(this::consumeHandleMassage); this.consumer.exceptionHandler(throwable -> getLogger() diff --git a/src/main/java/io/github/sinri/keel/servant/funnel/KeelFunnel.java b/src/main/java/io/github/sinri/keel/servant/funnel/KeelFunnel.java index ae25f713..6ffa99f8 100644 --- a/src/main/java/io/github/sinri/keel/servant/funnel/KeelFunnel.java +++ b/src/main/java/io/github/sinri/keel/servant/funnel/KeelFunnel.java @@ -58,7 +58,7 @@ private Promise getCurrentInterrupt() { } @Override - public void start() throws Exception { + protected void startAsKeelVerticle() { KeelAsyncKit.endless(promise -> { this.interruptRef.set(null); //System.out.println("ENDLESS "+System.currentTimeMillis()); @@ -95,6 +95,7 @@ public void start() throws Exception { }); } + // @Deprecated // public static void main(String[] args) { // Keel.initializeVertxStandalone(new VertxOptions()); diff --git a/src/main/java/io/github/sinri/keel/servant/intravenous/KeelIntravenousBase.java b/src/main/java/io/github/sinri/keel/servant/intravenous/KeelIntravenousBase.java index f593427f..00adff43 100644 --- a/src/main/java/io/github/sinri/keel/servant/intravenous/KeelIntravenousBase.java +++ b/src/main/java/io/github/sinri/keel/servant/intravenous/KeelIntravenousBase.java @@ -48,7 +48,7 @@ private Promise getCurrentInterrupt() { } @Override - public void start() { + protected void startAsKeelVerticle() { queueAcceptTask = true; int configuredBatchSize = getBatchSize(); diff --git a/src/main/java/io/github/sinri/keel/servant/queue/KeelQueue.java b/src/main/java/io/github/sinri/keel/servant/queue/KeelQueue.java index acc8b83b..caf77beb 100644 --- a/src/main/java/io/github/sinri/keel/servant/queue/KeelQueue.java +++ b/src/main/java/io/github/sinri/keel/servant/queue/KeelQueue.java @@ -54,7 +54,8 @@ protected KeelQueue setQueueStatus(QueueStatus queueStatus) { */ abstract protected @Nonnull SignalReader getSignalReader(); - public void start() { + @Override + protected void startAsKeelVerticle() { this.queueStatus = QueueStatus.RUNNING; try { diff --git a/src/main/java/io/github/sinri/keel/servant/queue/KeelQueueTask.java b/src/main/java/io/github/sinri/keel/servant/queue/KeelQueueTask.java index 3acf7812..4ff6e229 100644 --- a/src/main/java/io/github/sinri/keel/servant/queue/KeelQueueTask.java +++ b/src/main/java/io/github/sinri/keel/servant/queue/KeelQueueTask.java @@ -21,8 +21,8 @@ final void setQueueWorkerPoolManager(QueueWorkerPoolManager queueWorkerPoolManag @Nonnull abstract public String getTaskCategory(); - // as verticle - public final void start() { + @Override + protected final void startAsKeelVerticle() { this.queueWorkerPoolManager.whenOneWorkerStarts(); Future.succeededFuture() diff --git a/src/main/java/io/github/sinri/keel/servant/sundial/KeelSundial.java b/src/main/java/io/github/sinri/keel/servant/sundial/KeelSundial.java index d0c3cfc2..281429a1 100644 --- a/src/main/java/io/github/sinri/keel/servant/sundial/KeelSundial.java +++ b/src/main/java/io/github/sinri/keel/servant/sundial/KeelSundial.java @@ -32,8 +32,7 @@ protected KeelEventLogger buildEventLogger() { } @Override - - public void start() throws Exception { + protected void startAsKeelVerticle() { int delaySeconds = 61 - KeelCronExpression.parseCalenderToElements(Calendar.getInstance()).second; this.timerID = Keel.getVertx().setPeriodic(delaySeconds * 1000L, 60_000L, timerID -> { handleEveryMinute(Calendar.getInstance()); diff --git a/src/main/java/io/github/sinri/keel/servant/sundial/KeelSundialVerticle.java b/src/main/java/io/github/sinri/keel/servant/sundial/KeelSundialVerticle.java index d0d60e88..2fc53389 100644 --- a/src/main/java/io/github/sinri/keel/servant/sundial/KeelSundialVerticle.java +++ b/src/main/java/io/github/sinri/keel/servant/sundial/KeelSundialVerticle.java @@ -20,7 +20,7 @@ public KeelSundialVerticle(@Nonnull KeelSundialPlan sundialPlan, Calendar now) { } @Override - public void start() throws Exception { + protected void startAsPureKeelVerticle() { Future.succeededFuture() .compose(v -> { return sundialPlan.execute(now); diff --git a/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplPure.java b/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplPure.java index 45afddc9..1456532d 100644 --- a/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplPure.java +++ b/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplPure.java @@ -1,9 +1,26 @@ package io.github.sinri.keel.verticles; import io.vertx.core.AbstractVerticle; +import io.vertx.core.Promise; /** * @since 3.2.0 */ public abstract class KeelVerticleImplPure extends AbstractVerticle implements KeelVerticle { + @Override + public final void start(Promise startPromise) { + this.startAsPureKeelVerticle(startPromise); + } + + @Override + public final void start() { + this.startAsPureKeelVerticle(); + } + + protected void startAsPureKeelVerticle(Promise startPromise) { + startAsPureKeelVerticle(); + startPromise.complete(); + } + + abstract protected void startAsPureKeelVerticle(); } diff --git a/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplWithEventLogger.java b/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplWithEventLogger.java index 9977925e..90a125a8 100644 --- a/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplWithEventLogger.java +++ b/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplWithEventLogger.java @@ -1,14 +1,16 @@ package io.github.sinri.keel.verticles; import io.github.sinri.keel.logger.event.KeelEventLogger; +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Promise; import javax.annotation.Nonnull; /** * @since 3.2.0 */ -abstract public class KeelVerticleImplWithEventLogger extends KeelVerticleImplPure { - private final @Nonnull KeelEventLogger logger; +abstract public class KeelVerticleImplWithEventLogger extends AbstractVerticle implements KeelVerticle { + private @Nonnull KeelEventLogger logger; public KeelVerticleImplWithEventLogger() { super(); @@ -22,4 +24,22 @@ public KeelEventLogger getLogger() { abstract protected KeelEventLogger buildEventLogger(); + @Override + public final void start(Promise startPromise) { + this.logger = buildEventLogger(); + start(); + startPromise.complete(); + } + + @Override + public final void start() { + this.startAsKeelVerticle(); + } + + protected void startAsKeelVerticle(Promise startPromise) { + startAsKeelVerticle(); + startPromise.complete(); + } + + abstract protected void startAsKeelVerticle(); } diff --git a/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplWithIssueRecorder.java b/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplWithIssueRecorder.java index 2412386e..e8bfa4c5 100644 --- a/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplWithIssueRecorder.java +++ b/src/main/java/io/github/sinri/keel/verticles/KeelVerticleImplWithIssueRecorder.java @@ -2,11 +2,13 @@ import io.github.sinri.keel.logger.issue.record.KeelIssueRecord; import io.github.sinri.keel.logger.issue.recorder.KeelIssueRecorder; +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Promise; import javax.annotation.Nonnull; -abstract public class KeelVerticleImplWithIssueRecorder> extends KeelVerticleImplPure { - private final @Nonnull KeelIssueRecorder issueRecorder; +abstract public class KeelVerticleImplWithIssueRecorder> extends AbstractVerticle implements KeelVerticle { + private @Nonnull KeelIssueRecorder issueRecorder; public KeelVerticleImplWithIssueRecorder() { this.issueRecorder = buildIssueRecorder(); @@ -18,4 +20,22 @@ public KeelIssueRecorder getIssueRecorder() { } abstract protected @Nonnull KeelIssueRecorder buildIssueRecorder(); + + @Override + public final void start(Promise startPromise) { + this.issueRecorder = buildIssueRecorder(); + this.start(); + } + + @Override + public final void start() { + this.startAsKeelVerticle(); + } + + protected void startAsKeelVerticle(Promise startPromise) { + startAsKeelVerticle(); + startPromise.complete(); + } + + abstract protected void startAsKeelVerticle(); } diff --git a/src/main/java/io/github/sinri/keel/web/http/KeelHttpServer.java b/src/main/java/io/github/sinri/keel/web/http/KeelHttpServer.java index 06785864..205174e6 100644 --- a/src/main/java/io/github/sinri/keel/web/http/KeelHttpServer.java +++ b/src/main/java/io/github/sinri/keel/web/http/KeelHttpServer.java @@ -38,7 +38,7 @@ protected boolean isMainService() { protected abstract void configureRoutes(Router router); @Override - public void start() throws Exception { + protected void startAsKeelVerticle() { this.server = Keel.getVertx().createHttpServer(getHttpServerOptions()); Router router = Router.router(Keel.getVertx()); diff --git a/src/test/java/io/github/sinri/keel/test/lab/blocking/BlockingVerticlePlanA.java b/src/test/java/io/github/sinri/keel/test/lab/blocking/BlockingVerticlePlanA.java index 3210f217..48756962 100644 --- a/src/test/java/io/github/sinri/keel/test/lab/blocking/BlockingVerticlePlanA.java +++ b/src/test/java/io/github/sinri/keel/test/lab/blocking/BlockingVerticlePlanA.java @@ -91,9 +91,11 @@ private static Future blockPiece(BlockingVerticlePlanA futureForBlocking, } @Override - public void start() throws Exception { + protected void startAsKeelVerticle() { + } + public Future executeBlocking(Handler> promiseHandler) { Promise promise = Promise.promise(); this.context.runOnContext(new Handler() { diff --git a/src/test/java/io/github/sinri/keel/test/lab/blocking/BlockingVerticlePlanB.java b/src/test/java/io/github/sinri/keel/test/lab/blocking/BlockingVerticlePlanB.java index 7d67a39e..b943a31e 100644 --- a/src/test/java/io/github/sinri/keel/test/lab/blocking/BlockingVerticlePlanB.java +++ b/src/test/java/io/github/sinri/keel/test/lab/blocking/BlockingVerticlePlanB.java @@ -26,8 +26,7 @@ public KeelIssueRecorder buildIssueRecorder() { } @Override - public void start() throws Exception { - + protected void startAsKeelVerticle() { getIssueRecorder().info(r -> r.message("in verticle " + deploymentID())); blockCode.handle(promise); diff --git a/src/test/java/io/github/sinri/keel/test/lab/launcher/TestMainVerticle.java b/src/test/java/io/github/sinri/keel/test/lab/launcher/TestMainVerticle.java index 84a390b4..b92b3f3c 100644 --- a/src/test/java/io/github/sinri/keel/test/lab/launcher/TestMainVerticle.java +++ b/src/test/java/io/github/sinri/keel/test/lab/launcher/TestMainVerticle.java @@ -10,7 +10,7 @@ public class TestMainVerticle extends KeelVerticleImplWithEventLogger { @Override - public void start() throws Exception { + protected void startAsKeelVerticle() { KeelAsyncKit.endless(() -> { getLogger().info(r -> r.message("X")); return Future.succeededFuture();