Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forward to 3.2.7 #18

Merged
merged 11 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A Java framework with VERT.X eco, for projects for web, job and more.
<dependency>
<groupId>io.github.sinri</groupId>
<artifactId>Keel</artifactId>
<version>3.2.2</version>
<version>3.2.6</version>
</dependency>
```

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<groupId>io.github.sinri</groupId>
<artifactId>Keel</artifactId>
<!-- <version>3.2.4-SNAPSHOT</version>-->
<version>3.2.4</version>
<!-- <version>3.2.7-SNAPSHOT</version>-->
<version>3.2.7</version>

<name>Keel</name>
<description>
Expand Down Expand Up @@ -309,7 +309,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ static <R> Future<R> vertxizedRawFuture(@Nonnull java.util.concurrent.Future<R>
static <T> Future<T> executeBlocking(@Nonnull Handler<Promise<T>> blockingCodeHandler) {
Promise<T> promise = Promise.promise();
KeelVerticle verticle = new KeelVerticleImplPure() {

@Override
public void start() {
protected void startAsPureKeelVerticle() {
blockingCodeHandler.handle(promise);
promise.future().onComplete(ar -> this.undeployMe());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ public JsonObject toJsonObject() {

private static final Set<String> minorGCNames;
private static final Set<String> majorGCNames;
private static final Set<String> ignoreGCNames;

static {
minorGCNames = new HashSet<>();
majorGCNames = new HashSet<>();
ignoreGCNames = new HashSet<>();

// Serial Collector: "Copy"(年轻代),"MarkSweepCompact"(老年代)
minorGCNames.add("Copy");
Expand All @@ -136,7 +138,10 @@ public JsonObject toJsonObject() {
minorGCNames.add("G1 Young Generation");
majorGCNames.add("G1 Old Generation");
// ZGC (Z Garbage Collector): "ZGC"
minorGCNames.add("ZGC");
// @see https://armsword.com/2023/08/10/es-jdk17-and-zgc/
//minorGCNames.add("ZGC");
ignoreGCNames.add("ZGC Pauses"); // since 3.2.5 统计的是ZGC在GC过程中暂停的次数及暂停时间,这是JDK17新增的指标bean,无法统计Allocation Stall导致的线程挂起时间
minorGCNames.add("ZGC Cycles"); // since 3.2.5 统计的是ZGC发生的次数以及总耗时
// Shenandoah: "Shenandoah Pauses"
minorGCNames.add("Shenandoah Pauses");
}
Expand All @@ -155,7 +160,7 @@ public GCStatResult refreshWithGC(@Nonnull GarbageCollectorMXBean gc) {
if (gc.getCollectionTime() >= 0) {
this.addGCTimeAsOld(gc.getCollectionTime());
}
} else {
} else if (!ignoreGCNames.contains(gc.getName())) {
Keel.getLogger().error(log -> log
.message("Found Unknown GarbageCollectorMXBean Name")
.context(new JsonObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ static KeelEventLogger from(@Nonnull KeelIssueRecorder<KeelEventLog> issueRecord
@Nullable
Handler<KeelEventLog> templateEventLogEditor();

/**
* @since 3.2.7
*/
void setDynamicEventLogFormatter(@Nullable Handler<KeelEventLog> formatter);

/**
* @return Logs of this level or higher are visible.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class KeelEventLoggerImpl implements KeelEventLogger {
private final @Nonnull KeelIssueRecorder<KeelEventLog> issueRecorder;
private final @Nullable Handler<KeelEventLog> templateEventLogEditor;
private final @Nonnull List<KeelEventLogger> bypassLoggers;
private @Nullable Handler<KeelEventLog> dynamicFormatter;

KeelEventLoggerImpl(@Nonnull KeelIssueRecorder<KeelEventLog> issueRecorder, @Nullable Handler<KeelEventLog> templateEventLogEditor) {
this.issueRecorder = issueRecorder;
Expand All @@ -29,6 +30,14 @@ public Handler<KeelEventLog> templateEventLogEditor() {
return templateEventLogEditor;
}

/**
* @since 3.2.7
*/
@Override
public void setDynamicEventLogFormatter(@Nullable Handler<KeelEventLog> formatter) {
this.dynamicFormatter = formatter;
}

@Nonnull
private KeelIssueRecorder<KeelEventLog> getIssueRecorder() {
return issueRecorder;
Expand Down Expand Up @@ -64,22 +73,22 @@ public String getPresetTopic() {

@Override
public void log(@Nonnull Handler<KeelEventLog> eventLogHandler) {
this.getIssueRecorder().record(r -> {
Handler<KeelEventLog> h = r -> {
var x = templateEventLogEditor();
if (x != null) {
x.handle(r);
}
eventLogHandler.handle(r);
});
// since 3.2.7
if (dynamicFormatter != null) {
dynamicFormatter.handle(r);
}
};

this.getIssueRecorder().record(h);

getBypassLoggers().forEach(bypassLogger -> {
bypassLogger.log(r -> {
var x = templateEventLogEditor();
if (x != null) {
x.handle(r);
}
eventLogHandler.handle(r);
});
bypassLogger.log(h);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/
@TechnicalPreview(since = "3.1.10")
public interface KeelIssueRecordCenter {
/**
* @since 3.2.7 Use a static singleton impl.
*/
static KeelIssueRecordCenter outputCenter() {
return new KeelIssueRecordCenterAsSync(SyncStdoutAdapter.getInstance());
return KeelIssueRecordCenterAsSync.getInstanceWithStdout();
}

static KeelIssueRecordCenter silentCenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.sinri.keel.core.TechnicalPreview;
import io.github.sinri.keel.logger.issue.recorder.adapter.KeelIssueRecorderAdapter;
import io.github.sinri.keel.logger.issue.recorder.adapter.SyncStdoutAdapter;

import javax.annotation.Nonnull;

Expand All @@ -21,4 +22,16 @@ public KeelIssueRecordCenterAsSync(@Nonnull KeelIssueRecorderAdapter adapter) {
public KeelIssueRecorderAdapter getAdapter() {
return adapter;
}

/**
* @since 3.2.7
*/
private static final KeelIssueRecordCenterAsSync outputCenter = new KeelIssueRecordCenterAsSync(SyncStdoutAdapter.getInstance());

/**
* @since 3.2.7
*/
public static KeelIssueRecordCenter getInstanceWithStdout() {
return outputCenter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected Future<Void> rest() {
}

@Override
public void start() throws Exception {
protected void startAsKeelVerticle() {
barrelUsed.set(0);
KeelAsyncKit.repeatedlyCall(routineResult -> {
return fireOnce();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public Integer getPoolMaxSize() {
return x.getValueAsInteger();
}

/**
* This data source name would be used in MySQL client pool name.
* Use different name for actually different data sources.
*/
@Nonnull
public String getDataSourceName() {
return getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ public String build() {
}
code
.append("\tpublic ").append(looseEnum.looseEnumName()).append(" ").append(getter).append("() {\n")
.append("\t\treturn ").append(looseEnum.looseEnumName()).append(".valueOf(\n")
.append("\t\t\t")
.append(nullable ? "" : "Objects.requireNonNull(")
.append(readMethod).append("(\"").append(field).append("\")")
.append(nullable ? "" : ")").append("\n")
.append("\t\t);\n")
.append("\t\t@Nullable String enumExpression=").append(readMethod).append("(\"").append(field).append("\");\n");
if (nullable) {
code.append("\t\tif (enumExpression==null) return null;\n");
} else {
code.append("\t\tObjects.requireNonNull(enumExpression,\"The Enum Field `").append(field).append("` should not be null!\");\n");
}
code
.append("\t\treturn ").append(looseEnum.looseEnumName()).append(".valueOf(enumExpression);\n")
.append("\t}\n");
} else if (strictEnum != null) {
code.append("\t/*\n")
Expand All @@ -185,12 +187,14 @@ public String build() {
}
code
.append("\tpublic ").append(strictEnum.fullEnumRef()).append(" ").append(getter).append("() {\n")
.append("\t\treturn ").append(strictEnum.fullEnumRef()).append(".valueOf(\n")
.append("\t\t\t")
.append(nullable ? "" : "Objects.requireNonNull(")
.append(readMethod).append("(\"").append(field).append("\")")
.append(nullable ? "" : ")").append("\n")
.append("\t\t);\n")
.append("\t\t@Nullable String enumExpression=").append(readMethod).append("(\"").append(field).append("\");\n");
if (nullable) {
code.append("\t\tif (enumExpression==null) return null;\n");
} else {
code.append("\t\tObjects.requireNonNull(enumExpression,\"The Enum Field `").append(field).append("` should not be null!\");\n");
}
code
.append("\t\treturn ").append(strictEnum.fullEnumRef()).append(".valueOf(enumExpression);\n")
.append("\t}\n");
} else {
code.append("\t/*\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private Promise<Void> getCurrentInterrupt() {
}

@Override
public void start() throws Exception {
protected void startAsKeelVerticle() {
KeelAsyncKit.endless(promise -> {
this.interruptRef.set(null);
//System.out.println("ENDLESS "+System.currentTimeMillis());
Expand Down Expand Up @@ -95,6 +95,7 @@ public void start() throws Exception {
});
}


// @Deprecated
// public static void main(String[] args) {
// Keel.initializeVertxStandalone(new VertxOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private Promise<Void> getCurrentInterrupt() {
}

@Override
public void start() {
protected void startAsKeelVerticle() {
queueAcceptTask = true;

int configuredBatchSize = getBatchSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import io.github.sinri.keel.logger.event.KeelEventLogger;
import io.github.sinri.keel.logger.issue.center.KeelIssueRecordCenter;
import io.github.sinri.keel.verticles.KeelVerticleImplWithEventLogger;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.ThreadingModel;
import io.vertx.core.json.JsonObject;

import java.util.*;
Expand All @@ -30,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());
Expand All @@ -48,7 +49,11 @@ private void handleEveryMinute(Calendar now) {
.put("plan_cron", plan.cronExpression())
.put("now", parsedCalenderElements.toString())
);
plan.execute(now);

// since 3.2.5
new KeelSundialVerticle(plan, now).deployMe(new DeploymentOptions()
.setThreadingModel(ThreadingModel.WORKER)
);
} else {
getLogger().debug("Sundial Plan Not Match", new JsonObject()
.put("plan_key", plan.key())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @since 3.2.4
* @since 3.2.5 Used in KeelSundial
*/
public class KeelSundialVerticle extends KeelVerticleImplPure {
private final KeelSundialPlan sundialPlan;
Expand All @@ -19,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);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/github/sinri/keel/tesuto/KeelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public static void main(String[] args) throws ClassNotFoundException, NoSuchMeth
String calledClass = System.getProperty("sun.java.command");

eventLogger = KeelIssueRecordCenter.outputCenter().generateEventLogger("KeelTest");
eventLogger.setDynamicEventLogFormatter(eventLog -> {
eventLog.classification("preparing");
});

eventLogger.debug(r -> r.message("Keel Test Class: " + calledClass));

Expand Down Expand Up @@ -77,13 +80,19 @@ public static void main(String[] args) throws ClassNotFoundException, NoSuchMeth
eventLogger.info(r -> r.message("RUNNING TEST UNITS..."));

return KeelAsyncKit.iterativelyCall(testUnits, testUnit -> {
eventLogger.setDynamicEventLogFormatter(eventLogger -> {
eventLogger.classification(testUnit.getName());
});
return testUnit.runTest((KeelTest) testInstance)
.compose(testUnitResult -> {
testUnitResults.add(testUnitResult);
return Future.succeededFuture();
});
})
.onComplete(vv -> {
eventLogger.setDynamicEventLogFormatter(eventLogger -> {
eventLogger.classification("conclusion");
});
AtomicInteger totalNonSkippedRef = new AtomicInteger(0);
testUnitResults.forEach(testUnitResult -> {
if (testUnitResult.isSkipped()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public Future<TestUnitResult> runTest(KeelTest testInstance) {
} else {
return Future.succeededFuture()
.compose(vv -> {
// testInstance.getLogger().setDynamicEventLogFormatter(keelEventLog -> {
// keelEventLog.classification(this.getName());
// });
try {
return (Future<?>) this.method.invoke(testInstance);
} catch (Throwable e) {
Expand Down
Loading