Skip to content

Commit

Permalink
Merge pull request #31962 from phillip-kruger/devui-uni
Browse files Browse the repository at this point in the history
Dev UI : use a non blocking response where possible
  • Loading branch information
cescoffier authored Mar 21, 2023
2 parents a53e6d6 + 09ef3dc commit 88dc023
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.quarkus.arc.runtime.devmode.EventInfo;
import io.quarkus.arc.runtime.devmode.EventsMonitor;
import io.quarkus.arc.runtime.devmode.InvocationInfo;
import io.smallrye.common.annotation.NonBlocking;
import io.smallrye.mutiny.Multi;

public class ArcJsonRPCService {
Expand All @@ -25,6 +26,7 @@ public Multi<EventInfo> streamEvents() {
return Multi.createFrom().empty();
}

@NonBlocking
public List<EventInfo> getLastEvents() {
EventsMonitor eventsMonitor = Arc.container().instance(EventsMonitor.class).get();
if (eventsMonitor != null) {
Expand All @@ -33,6 +35,7 @@ public List<EventInfo> getLastEvents() {
return List.of();
}

@NonBlocking
public List<EventInfo> clearLastEvents() {
EventsMonitor eventsMonitor = Arc.container().instance(EventsMonitor.class).get();
if (eventsMonitor != null) {
Expand All @@ -42,6 +45,7 @@ public List<EventInfo> clearLastEvents() {
return List.of();
}

@NonBlocking
public List<InvocationInfo> getLastInvocations() {
InvocationsMonitor invocationsMonitor = Arc.container().instance(InvocationsMonitor.class).get();
if (invocationsMonitor != null) {
Expand All @@ -51,6 +55,7 @@ public List<InvocationInfo> getLastInvocations() {
return List.of();
}

@NonBlocking
public List<InvocationInfo> clearLastInvocations() {
InvocationsMonitor invocationsMonitor = Arc.container().instance(InvocationsMonitor.class).get();
if (invocationsMonitor != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import io.quarkus.cache.CacheManager;
import io.quarkus.cache.CaffeineCache;
import io.quarkus.cache.runtime.caffeine.CaffeineCacheImpl;
import io.smallrye.common.annotation.NonBlocking;
import io.smallrye.mutiny.Uni;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

Expand All @@ -27,6 +29,7 @@ public class CacheJsonRPCService {
@Inject
Logger logger;

@NonBlocking
public JsonArray getAll() {
Collection<String> names = manager.getCacheNames();
List<CaffeineCache> allCaches = new ArrayList<>(names.size());
Expand All @@ -49,17 +52,16 @@ private JsonObject getJsonRepresentationForCache(Cache cc) {
return new JsonObject().put("name", cc.getName()).put("size", ((CaffeineCacheImpl) cc).getSize());
}

public JsonObject clear(String name) {
public Uni<JsonObject> clear(String name) {
Optional<Cache> cache = manager.getCache(name);
if (cache.isPresent()) {
cache.get().invalidateAll().subscribe().asCompletionStage()
.thenAccept(x -> logger.infof("Cache %s cleared", name));
return getJsonRepresentationForCache(cache.get());
return cache.get().invalidateAll().map((t) -> getJsonRepresentationForCache(cache.get()));
} else {
return new JsonObject().put("name", name).put("size", -1);
return Uni.createFrom().item(new JsonObject().put("name", name).put("size", -1));
}
}

@NonBlocking
public JsonObject refresh(String name) {
Optional<Cache> cache = manager.getCache(name);
if (cache.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import org.jboss.resteasy.reactive.server.util.ScoreSystem;

import io.quarkus.resteasy.reactive.server.runtime.ResteasyReactiveRecorder;
import io.smallrye.common.annotation.NonBlocking;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

public class ResteasyReactiveJsonRPCService {

@NonBlocking
public JsonObject getEndpointScores() {
JsonObject endpointScore = new JsonObject();

Expand Down Expand Up @@ -62,6 +64,7 @@ public JsonObject getEndpointScores() {
return endpointScore;
}

@NonBlocking
public JsonArray getExceptionMappers() {
JsonArray all = new JsonArray();
var mappers = RuntimeExceptionMapper.getMappers();
Expand All @@ -75,6 +78,7 @@ public JsonArray getExceptionMappers() {
return all;
}

@NonBlocking
public JsonArray getParamConverterProviders() {
JsonArray all = new JsonArray();
var providers = ResteasyReactiveRecorder.getCurrentDeployment().getParamConverterProviders()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.quarkus.scheduler.common.runtime.SchedulerContext;
import io.quarkus.scheduler.common.runtime.util.SchedulerUtils;
import io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle;
import io.smallrye.common.annotation.NonBlocking;
import io.smallrye.common.vertx.VertxContext;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor;
Expand Down Expand Up @@ -86,6 +87,7 @@ public Multi<JsonObject> streamRunningStatus() {
return runningStatus;
}

@NonBlocking
public JsonObject getData() {
SchedulerContext c = context.get();
Scheduler s = scheduler.get();
Expand Down Expand Up @@ -127,6 +129,7 @@ public JsonObject getData() {
return ret;
}

@NonBlocking
public JsonObject pauseScheduler() {
Scheduler s = scheduler.get();
if (!s.isRunning()) {
Expand All @@ -137,6 +140,7 @@ public JsonObject pauseScheduler() {
return newSuccess("Scheduler was paused");
}

@NonBlocking
public JsonObject resumeScheduler() {
Scheduler s = scheduler.get();
if (s.isRunning()) {
Expand All @@ -147,6 +151,7 @@ public JsonObject resumeScheduler() {
return newSuccess("Scheduler was resumed");
}

@NonBlocking
public JsonObject pauseJob(String identity) {
Scheduler s = scheduler.get();
if (s.isPaused(identity)) {
Expand All @@ -157,6 +162,7 @@ public JsonObject pauseJob(String identity) {
return newSuccess("Job with identity " + identity + " was paused");
}

@NonBlocking
public JsonObject resumeJob(String identity) {
Scheduler s = scheduler.get();
if (!s.isPaused(identity)) {
Expand All @@ -167,6 +173,7 @@ public JsonObject resumeJob(String identity) {
return newSuccess("Job with identity " + identity + " was resumed");
}

@NonBlocking
public JsonObject executeJob(String methodDescription) {
SchedulerContext c = context.get();
for (ScheduledMethod metadata : c.getScheduledMethods()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import io.quarkus.devconsole.runtime.spi.DevConsolePostHandler;
import io.quarkus.devconsole.spi.DevConsoleRouteBuildItem;
import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem;
import io.quarkus.devui.runtime.ConfigJsonRpcService;
import io.quarkus.devui.runtime.config.ConfigJsonRpcService;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.vertx.http.runtime.devmode.ConfigDescription;
import io.quarkus.vertx.http.runtime.devmode.ConfigDescriptionsManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.devui.runtime;
package io.quarkus.devui.runtime.config;

import java.util.Map;

Expand All @@ -14,7 +14,6 @@
public class ConfigJsonRpcService {

public boolean updateProperty(String name, String value) {
System.out.println("setting " + name + " to " + value);
DevConsoleManager.invoke("config-update-property", Map.of("name", name, "value", value));
return true;
}
Expand All @@ -27,5 +26,4 @@ public JsonObject getAllValues() {
}
return values;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.LinkedBlockingQueue;

import io.quarkus.arc.Arc;
import io.smallrye.common.annotation.NonBlocking;
import io.smallrye.mutiny.Multi;
import io.vertx.core.json.JsonObject;

Expand All @@ -13,10 +14,12 @@
*/
public class LogStreamJsonRPCService {

@NonBlocking
public String ping() {
return "pong";
}

@NonBlocking
public List<JsonObject> history() {
LogStreamBroadcaster logStreamBroadcaster = Arc.container().instance(LogStreamBroadcaster.class).get();
LinkedBlockingQueue<JsonObject> history = logStreamBroadcaster.getHistory();
Expand Down

0 comments on commit 88dc023

Please sign in to comment.