Skip to content

Commit

Permalink
Merge pull request #15616 from gsmet/1.12.2-backports-3
Browse files Browse the repository at this point in the history
1.12.2 backports 3
  • Loading branch information
gsmet authored Mar 11, 2021
2 parents 83cb710 + 06e4ab8 commit 1c0139e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 45 deletions.
4 changes: 2 additions & 2 deletions docs/src/main/asciidoc/building-my-first-extension.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ Your extension is a multi-module project. So let's start by checking out the par
</project>
----

<1> Quarkus requires a recent version of the Maven compiler plugin supporting the annotationProcessorPaths configuration.
<2> Your extension declares 2 sub-modules `deployment` and `runtime`.
<1> Your extension declares 2 sub-modules `deployment` and `runtime`.
<2> Quarkus requires a recent version of the Maven compiler plugin supporting the annotationProcessorPaths configuration.
<3> The `quarkus-bom` aligns your dependencies with those used by Quarkus during the augmentation phase.
<4> Quarkus requires these configs to run tests properly

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ public static class Builder {
/**
* Use HttpRootPathBuildItem and NonApplicationRootPathBuildItem to
* ensure paths are constructed/normalized correctly
*
*
* @deprecated
* @see HttpRootPathBuildItem#routeBuilder()
* @see NonApplicationRootPathBuildItem#routeBuilder()
*/
@Deprecated
Builder() {
public Builder() {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ public void runtimeTemplates(List<DevConsoleRuntimeTemplateInfoBuildItem> items,
}
}

@BuildStep
@BuildStep(onlyIf = IsDevelopment.class)
@Record(ExecutionTime.STATIC_INIT)
public HistoryHandlerBuildItem handler(BuildProducer<LogHandlerBuildItem> logHandlerBuildItemBuildProducer,
LogStreamRecorder recorder) {
RuntimeValue<Optional<HistoryHandler>> handler = recorder.handler();
LogStreamRecorder recorder, DevUIConfig devUiConfig) {
RuntimeValue<Optional<HistoryHandler>> handler = recorder.handler(devUiConfig.historySize);
logHandlerBuildItemBuildProducer.produce(new LogHandlerBuildItem((RuntimeValue) handler));
return new HistoryHandlerBuildItem(handler);
}
Expand Down Expand Up @@ -296,21 +296,37 @@ public ServiceStartBuildItem setupDeploymentSideHandling(List<DevTemplatePathBui
@Record(ExecutionTime.RUNTIME_INIT)
@Consume(LoggingSetupBuildItem.class)
@BuildStep(onlyIf = IsDevelopment.class)
public void setupDevConsoleRoutes(List<DevConsoleRouteBuildItem> routes,
BuildProducer<RouteBuildItem> routeBuildItemBuildProducer,
LogStreamRecorder recorder,
public void setupDevConsoleRoutes(
DevConsoleRecorder recorder,
LogStreamRecorder logStreamRecorder,
List<DevConsoleRouteBuildItem> routes,
CurateOutcomeBuildItem curateOutcomeBuildItem,
HistoryHandlerBuildItem historyHandlerBuildItem,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
LaunchModeBuildItem launchModeBuildItem) {
LaunchModeBuildItem launchModeBuildItem,
ShutdownContextBuildItem shutdownContext,
BuildProducer<RouteBuildItem> routeBuildItemBuildProducer) throws IOException {
if (launchModeBuildItem.getDevModeType().orElse(null) != DevModeType.LOCAL) {
return;
}

// Add the static resources
AppArtifact devConsoleResourcesArtifact = WebJarUtil.getAppArtifact(curateOutcomeBuildItem, "io.quarkus",
"quarkus-vertx-http-deployment");

Path devConsoleStaticResourcesDeploymentPath = WebJarUtil.copyResourcesForDevOrTest(curateOutcomeBuildItem,
launchModeBuildItem,
devConsoleResourcesArtifact, STATIC_RESOURCES_PATH);

routeBuildItemBuildProducer.produce(nonApplicationRootPathBuildItem.routeBuilder()
.route("dev/resources/*")
.handler(recorder.devConsoleHandler(devConsoleStaticResourcesDeploymentPath.toString(), shutdownContext))
.build());

// Add the log stream
routeBuildItemBuildProducer.produce(nonApplicationRootPathBuildItem.routeBuilder()
.route("dev/logstream")
.handler(recorder.websocketHandler(historyHandlerBuildItem.value))
.handler(logStreamRecorder.websocketHandler(historyHandlerBuildItem.value))
.build());

for (DevConsoleRouteBuildItem i : routes) {
Expand Down Expand Up @@ -340,29 +356,6 @@ public void setupDevConsoleRoutes(List<DevConsoleRouteBuildItem> routes,
.build());
}

@BuildStep(onlyIf = IsDevelopment.class)
@Record(ExecutionTime.RUNTIME_INIT)
public void deployStaticResources(DevConsoleRecorder recorder, CurateOutcomeBuildItem curateOutcomeBuildItem,
LaunchModeBuildItem launchMode, ShutdownContextBuildItem shutdownContext,
BuildProducer<RouteBuildItem> routeBuildItemBuildProducer,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
LaunchModeBuildItem launchModeBuildItem) throws IOException {

if (launchModeBuildItem.getDevModeType().orElse(DevModeType.LOCAL) != DevModeType.LOCAL) {
return;
}
AppArtifact devConsoleResourcesArtifact = WebJarUtil.getAppArtifact(curateOutcomeBuildItem, "io.quarkus",
"quarkus-vertx-http-deployment");

Path devConsoleStaticResourcesDeploymentPath = WebJarUtil.copyResourcesForDevOrTest(curateOutcomeBuildItem, launchMode,
devConsoleResourcesArtifact, STATIC_RESOURCES_PATH);

routeBuildItemBuildProducer.produce(nonApplicationRootPathBuildItem.routeBuilder()
.route("dev/resources/*")
.handler(recorder.devConsoleHandler(devConsoleStaticResourcesDeploymentPath.toString(), shutdownContext))
.build());
}

private Engine buildEngine(List<DevTemplatePathBuildItem> devTemplatePaths,
List<RouteBuildItem> allRoutes,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.vertx.http.deployment.devmode.console;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot(name = "dev-ui")
public class DevUIConfig {

/**
* The number of history log entries to remember.
*/
@ConfigItem(defaultValue = "50")
public int historySize;

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.quarkus.vertx.http.runtime.logstream;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;

import org.jboss.logmanager.ExtHandler;
Expand All @@ -12,11 +12,14 @@
* Log handler for Logger Manager
*/
public class HistoryHandler extends ExtHandler {

private final int size = 50;
private final List<ExtLogRecord> history = new LinkedList<>();
private final LinkedBlockingQueue<ExtLogRecord> history;

public HistoryHandler() {
this(50);
}

public HistoryHandler(int size) {
this.history = new LinkedBlockingQueue<>(size);
setLevel(Level.INFO);
setFormatter(new JsonFormatter());
}
Expand All @@ -29,11 +32,17 @@ public final void doPublish(final ExtLogRecord record) {
}

if (isLoggable(record)) {
history.add(record);

while (history.size() > size) {
history.remove(0);
synchronized (this) {
try {
if (history.remainingCapacity() == 0) {
history.take();
}
history.add(record);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
@Recorder
public class LogStreamRecorder {

public RuntimeValue<Optional<HistoryHandler>> handler() {
return new RuntimeValue<>(Optional.of(new HistoryHandler()));
public RuntimeValue<Optional<HistoryHandler>> handler(int size) {
return new RuntimeValue<>(Optional.of(new HistoryHandler(size)));
}

public Handler<RoutingContext> websocketHandler(RuntimeValue<Optional<HistoryHandler>> historyHandler) {
Expand Down

0 comments on commit 1c0139e

Please sign in to comment.