use of io.helidon.common.reactive.Single in project helidon by oracle.
the class DbClientTracing method apply.
@Override
protected Single<DbClientServiceContext> apply(DbClientServiceContext serviceContext) {
SpanTracingConfig spanConfig = TracingConfigUtil.spanConfig("dbclient", "statement");
if (!spanConfig.enabled()) {
return Single.just(serviceContext);
}
Context context = serviceContext.context();
Tracer tracer = context.get(Tracer.class).orElseGet(GlobalTracer::get);
// now if span context is missing, we build a span without a parent
Tracer.SpanBuilder spanBuilder = tracer.buildSpan(serviceContext.statementName());
context.get(SpanContext.class).ifPresent(spanBuilder::asChildOf);
Span span = spanBuilder.start();
span.setTag("db.operation", serviceContext.statementType().toString());
if (spanConfig.logEnabled("statement", true)) {
Tags.DB_STATEMENT.set(span, serviceContext.statement());
}
Tags.COMPONENT.set(span, "dbclient");
Tags.DB_TYPE.set(span, serviceContext.dbType());
serviceContext.statementFuture().thenAccept(nothing -> {
if (spanConfig.logEnabled("statement-finish", true)) {
span.log(Map.of("type", "statement"));
}
});
serviceContext.resultFuture().thenAccept(count -> {
if (spanConfig.logEnabled("result-finish", true)) {
span.log(Map.of("type", "result", "count", count));
}
span.finish();
}).exceptionally(throwable -> {
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Map.of("event", "error", "error.kind", "Exception", "error.object", throwable, "message", throwable.getMessage()));
span.finish();
return null;
});
return Single.just(serviceContext);
}
use of io.helidon.common.reactive.Single in project helidon by oracle.
the class Main method startServer.
/**
* Start the server.
* @return the created WebServer instance
*/
public static Single<WebServer> startServer() {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
Single<WebServer> server = WebServer.builder(createRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).addMediaSupport(JsonbSupport.create()).build().start();
server.thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port() + "/api/movies");
ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
return server;
}
use of io.helidon.common.reactive.Single in project helidon by oracle.
the class Main method startServer.
/**
* Start the server.
*
* @return the created {@link WebServer} instance
*/
static Single<WebServer> startServer(Config config) {
// load logging configuration
LogConfig.configureRuntime();
// Build server using three ports:
// default public port, admin port, private port
WebServer server = WebServer.builder(createPublicRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).build();
Single<WebServer> webServerSingle = server.start();
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
webServerSingle.thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port());
ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}).exceptionallyAccept(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
});
return webServerSingle;
}
use of io.helidon.common.reactive.Single in project helidon by oracle.
the class BulkheadTest method testBulkheadQueue.
@Test
void testBulkheadQueue() throws InterruptedException {
Bulkhead bulkhead = Bulkhead.builder().limit(1).queueLength(1000).build();
Request inProgress = new Request(0);
bulkhead.invoke(inProgress::invoke);
Request[] aLotRequests = new Request[999];
Single[] aLotResults = new Single[999];
for (int i = 0; i < aLotRequests.length; i++) {
Request req = new Request(i);
aLotRequests[i] = req;
aLotResults[i] = bulkhead.invoke(req::invoke);
}
for (Request req : aLotRequests) {
req.releaseCdl.countDown();
}
inProgress.releaseCdl.countDown();
if (inProgress.invokedCdl.await(1, TimeUnit.SECONDS)) {
for (Single result : aLotResults) {
result.await(1, TimeUnit.SECONDS);
}
} else {
fail("Should have invoked the first");
}
}
use of io.helidon.common.reactive.Single in project helidon by oracle.
the class Main method startServer.
/**
* Start the server.
* @return the created {@link WebServer} instance
*/
static Single<WebServer> startServer(Config config) {
// load logging configuration
LogConfig.configureRuntime();
// Build server using three ports:
// default public port, admin port, private port
WebServer server = WebServer.builder(createPublicRouting()).config(config.get("server")).addNamedRouting("admin", createAdminRouting()).addNamedRouting("private", createPrivateRouting()).build();
Single<WebServer> webserver = server.start();
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
webserver.thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port());
ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
return webserver;
}
Aggregations