Search in sources :

Example 1 with ExitService

use of io.helidon.tests.integration.dbclient.appl.tools.ExitService 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;
}
Also used : TransactionGetService(io.helidon.tests.integration.dbclient.appl.transaction.TransactionGetService) LogConfig(io.helidon.common.LogConfig) Config(io.helidon.config.Config) HealthSupport(io.helidon.health.HealthSupport) TransactionQueriesService(io.helidon.tests.integration.dbclient.appl.transaction.TransactionQueriesService) DmlStatementService(io.helidon.tests.integration.dbclient.appl.statement.DmlStatementService) TransactionUpdateService(io.helidon.tests.integration.dbclient.appl.transaction.TransactionUpdateService) SimpleQueryService(io.helidon.tests.integration.dbclient.appl.simple.SimpleQueryService) TransactionInsertService(io.helidon.tests.integration.dbclient.appl.transaction.TransactionInsertService) GetStatementService(io.helidon.tests.integration.dbclient.appl.statement.GetStatementService) QueryStatementService(io.helidon.tests.integration.dbclient.appl.statement.QueryStatementService) DbClient(io.helidon.dbclient.DbClient) HealthCheckService(io.helidon.tests.integration.dbclient.appl.health.HealthCheckService) SimpleInsertService(io.helidon.tests.integration.dbclient.appl.simple.SimpleInsertService) Routing(io.helidon.webserver.Routing) SimpleGetService(io.helidon.tests.integration.dbclient.appl.simple.SimpleGetService) SimpleDeleteService(io.helidon.tests.integration.dbclient.appl.simple.SimpleDeleteService) ExitService(io.helidon.tests.integration.dbclient.appl.tools.ExitService) DbClientService(io.helidon.dbclient.DbClientService) WebServer(io.helidon.webserver.WebServer) TransactionDeleteService(io.helidon.tests.integration.dbclient.appl.transaction.TransactionDeleteService) InterceptorService(io.helidon.tests.integration.dbclient.appl.interceptor.InterceptorService) SimpleUpdateService(io.helidon.tests.integration.dbclient.appl.simple.SimpleUpdateService) FlowControlService(io.helidon.tests.integration.dbclient.appl.result.FlowControlService) MapperService(io.helidon.tests.integration.dbclient.appl.mapping.MapperService)

Aggregations

LogConfig (io.helidon.common.LogConfig)1 Config (io.helidon.config.Config)1 DbClient (io.helidon.dbclient.DbClient)1 DbClientService (io.helidon.dbclient.DbClientService)1 HealthSupport (io.helidon.health.HealthSupport)1 HealthCheckService (io.helidon.tests.integration.dbclient.appl.health.HealthCheckService)1 InterceptorService (io.helidon.tests.integration.dbclient.appl.interceptor.InterceptorService)1 MapperService (io.helidon.tests.integration.dbclient.appl.mapping.MapperService)1 FlowControlService (io.helidon.tests.integration.dbclient.appl.result.FlowControlService)1 SimpleDeleteService (io.helidon.tests.integration.dbclient.appl.simple.SimpleDeleteService)1 SimpleGetService (io.helidon.tests.integration.dbclient.appl.simple.SimpleGetService)1 SimpleInsertService (io.helidon.tests.integration.dbclient.appl.simple.SimpleInsertService)1 SimpleQueryService (io.helidon.tests.integration.dbclient.appl.simple.SimpleQueryService)1 SimpleUpdateService (io.helidon.tests.integration.dbclient.appl.simple.SimpleUpdateService)1 DmlStatementService (io.helidon.tests.integration.dbclient.appl.statement.DmlStatementService)1 GetStatementService (io.helidon.tests.integration.dbclient.appl.statement.GetStatementService)1 QueryStatementService (io.helidon.tests.integration.dbclient.appl.statement.QueryStatementService)1 ExitService (io.helidon.tests.integration.dbclient.appl.tools.ExitService)1 TransactionDeleteService (io.helidon.tests.integration.dbclient.appl.transaction.TransactionDeleteService)1 TransactionGetService (io.helidon.tests.integration.dbclient.appl.transaction.TransactionGetService)1