use of io.helidon.dbclient.DbClientService in project helidon by oracle.
the class DbClientTracingProvider method create.
@Override
public Collection<DbClientService> create(Config config) {
List<Config> tracingConfigs = config.asNodeList().orElseGet(List::of);
List<DbClientService> result = new LinkedList<>();
for (Config tracingConfig : tracingConfigs) {
result.add(fromConfig(tracingConfig));
}
if (result.isEmpty()) {
LOGGER.info("DB Client tracing is enabled, yet none is configured in config.");
}
return result;
}
use of io.helidon.dbclient.DbClientService in project helidon by oracle.
the class DbClientMetricsProvider method create.
@Override
public Collection<DbClientService> create(Config config) {
List<Config> metricConfigs = config.asNodeList().orElseGet(List::of);
List<DbClientService> result = new LinkedList<>();
for (Config metricConfig : metricConfigs) {
result.add(fromConfig(metricConfig));
}
if (result.isEmpty()) {
LOGGER.info("DB Client metrics are enabled, yet none are configured in config.");
}
return result;
}
use of io.helidon.dbclient.DbClientService in project helidon by oracle.
the class ApplMain method startServer.
private static WebServer startServer(final String configFile) {
final Config config = Config.create(ConfigSources.classpath(configFile));
final Config dbConfig = config.get("db");
// Client services are added through a service loader - see mongoDB example for explicit services
final DbClient dbClient = DbClient.builder(dbConfig).addService(DbClientMetrics.counter().statementNames("select-pokemon-named-arg", "select-pokemon-order-arg", "insert-pokemon")).addService(DbClientMetrics.timer().statementTypes(DbStatementType.GET)).build();
final HealthSupport health = HealthSupport.builder().addLiveness(DbClientHealthCheck.builder(dbClient).statementName("ping").build()).build();
final Map<String, String> statements = dbConfig.get("statements").detach().asMap().get();
final ExitService exitResource = new ExitService();
final DbClientService interceptorTestService = new InterceptorService.TestClientService();
final Routing routing = Routing.builder().register(// Metrics at "/metrics"
MetricsSupport.create()).register(// Health at "/health"
health).register("/Init", new InitService(dbClient, dbConfig)).register("/Exit", exitResource).register("/Verify", new VerifyService(dbClient, config)).register("/SimpleGet", new SimpleGetService(dbClient, statements)).register("/SimpleQuery", new SimpleQueryService(dbClient, statements)).register("/SimpleUpdate", new SimpleUpdateService(dbClient, statements)).register("/SimpleInsert", new SimpleInsertService(dbClient, statements)).register("/SimpleDelete", new SimpleDeleteService(dbClient, statements)).register("/TransactionGet", new TransactionGetService(dbClient, statements)).register("/TransactionQueries", new TransactionQueriesService(dbClient, statements)).register("/TransactionUpdate", new TransactionUpdateService(dbClient, statements)).register("/TransactionInsert", new TransactionInsertService(dbClient, statements)).register("/TransactionDelete", new TransactionDeleteService(dbClient, statements)).register("/DmlStatement", new DmlStatementService(dbClient, statements)).register("/GetStatement", new GetStatementService(dbClient, statements)).register("/QueryStatement", new QueryStatementService(dbClient, statements)).register("/FlowControl", new FlowControlService(dbClient, statements)).register("/Mapper", new MapperService(dbClient, statements)).register("/Interceptor", new InterceptorService(DbClient.builder(dbConfig).addService(interceptorTestService).build(), statements, interceptorTestService)).register("/HealthCheck", new HealthCheckService(dbClient, dbConfig, statements)).build();
// Prepare routing for the server
final WebServer.Builder serverBuilder = WebServer.builder().routing(routing).config(config.get("server"));
final WebServer server = serverBuilder.addMediaSupport(JsonpSupport.create()).addMediaSupport(JsonbSupport.create()).build();
exitResource.setServer(server);
// Start the server and print some info.
server.start().thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port() + "/");
});
// Server threads are not daemon. NO need to block. Just react.
server.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
return server;
}
use of io.helidon.dbclient.DbClientService in project helidon by oracle.
the class DbClientContext method invokeServices.
/**
* Invoke all configured client services and return a single that completes once all the
* client services complete.
*
* @param dbContext context for client services
* @return a single with the same or modified client service context
*/
public Single<DbClientServiceContext> invokeServices(DbClientServiceContext dbContext) {
CompletableFuture<DbClientServiceContext> result = CompletableFuture.completedFuture(dbContext);
dbContext.context(Contexts.context().orElseGet(Context::create));
for (DbClientService service : clientServices) {
result = result.thenCompose(service::statement);
}
return Single.create(result);
}
Aggregations