List of usage examples for io.vertx.core Future future
future
From source file:org.eclipse.hono.service.HealthCheckServer.java
License:Open Source License
/** * Starts the health check server if health check is configured, otherwise does nothing. * * @return a future indicating the output of the operation. *///from w ww . ja v a 2 s.c o m public Future<Void> start() { Future<Void> result = Future.future(); if (router != null) { HttpServerOptions options = new HttpServerOptions().setPort(config.getHealthCheckPort()) .setHost(config.getHealthCheckBindAddress()); server = vertx.createHttpServer(options); router.get(URI_READINESS_PROBE).handler(readinessHandler); router.get(URI_LIVENESS_PROBE).handler(livenessHandler); server.requestHandler(router::accept).listen(startAttempt -> { if (startAttempt.succeeded()) { LOG.info("readiness probe available at http://{}:{}{}", options.getHost(), options.getPort(), URI_READINESS_PROBE); LOG.info("liveness probe available at http://{}:{}{}", options.getHost(), options.getPort(), URI_LIVENESS_PROBE); result.complete(); } else { LOG.warn("failed to start health checks HTTP server:", startAttempt.cause().getMessage()); result.fail(startAttempt.cause()); } }); } else { // health check port not configured result.complete(); } return result; }
From source file:org.eclipse.hono.service.HealthCheckServer.java
License:Open Source License
/** * Closes the HTTP server if it exists./*from ww w . java 2 s . co m*/ * * @return A Future indicating the outcome of the operation. */ public Future<Void> stop() { Future<Void> result = Future.future(); if (server != null) { server.close(result.completer()); } else { result.complete(); } return result; }
From source file:org.eclipse.hono.service.http.HttpServiceBase.java
License:Open Source License
private Future<HttpServer> bindSecureHttpServer(final Router router) { if (isSecurePortEnabled()) { Future<HttpServer> result = Future.future(); final String bindAddress = server == null ? getConfig().getBindAddress() : "?"; if (server == null) { server = vertx.createHttpServer(getHttpServerOptions()); }/*from w w w. ja v a 2 s . c o m*/ server.requestHandler(router::accept).listen(bindAttempt -> { if (bindAttempt.succeeded()) { if (getPort() == getPortDefaultValue()) { LOG.info("server listens on standard secure port [{}:{}]", bindAddress, server.actualPort()); } else { LOG.warn("server listens on non-standard secure port [{}:{}], default is {}", bindAddress, server.actualPort(), getPortDefaultValue()); } result.complete(bindAttempt.result()); } else { LOG.error("cannot bind to secure port", bindAttempt.cause()); result.fail(bindAttempt.cause()); } }); return result; } else { return Future.succeededFuture(); } }
From source file:org.eclipse.hono.service.http.HttpServiceBase.java
License:Open Source License
private Future<HttpServer> bindInsecureHttpServer(final Router router) { if (isInsecurePortEnabled()) { Future<HttpServer> result = Future.future(); final String bindAddress = insecureServer == null ? getConfig().getInsecurePortBindAddress() : "?"; if (insecureServer == null) { insecureServer = vertx.createHttpServer(getInsecureHttpServerOptions()); }/*from ww w . j ava 2 s. co m*/ insecureServer.requestHandler(router::accept).listen(bindAttempt -> { if (bindAttempt.succeeded()) { if (getInsecurePort() == getInsecurePortDefaultValue()) { LOG.info("server listens on standard insecure port [{}:{}]", bindAddress, insecureServer.actualPort()); } else { LOG.warn("server listens on non-standard insecure port [{}:{}], default is {}", bindAddress, insecureServer.actualPort(), getInsecurePortDefaultValue()); } result.complete(bindAttempt.result()); } else { LOG.error("cannot bind to insecure port", bindAttempt.cause()); result.fail(bindAttempt.cause()); } }); return result; } else { return Future.succeededFuture(); } }
From source file:org.eclipse.hono.service.http.HttpServiceBase.java
License:Open Source License
private Future<Router> startEndpoints() { final Future<Router> startFuture = Future.future(); final Router router = createRouter(); if (router == null) { startFuture.fail("no router configured"); } else {/*www . jav a2 s .co m*/ addEndpointRoutes(router); addCustomRoutes(router); @SuppressWarnings("rawtypes") List<Future> endpointFutures = new ArrayList<>(endpoints.size()); for (HttpEndpoint ep : endpoints) { LOG.info("starting endpoint [name: {}, class: {}]", ep.getName(), ep.getClass().getName()); Future<Void> endpointFuture = Future.future(); endpointFutures.add(endpointFuture); ep.start(endpointFuture); } CompositeFuture.all(endpointFutures).setHandler(startup -> { if (startup.succeeded()) { startFuture.complete(router); } else { startFuture.fail(startup.cause()); } }); } return startFuture; }
From source file:org.eclipse.hono.service.http.HttpServiceBase.java
License:Open Source License
private Future<Void> stopServer() { Future<Void> serverStopTracker = Future.future(); if (server != null) { server.close(serverStopTracker.completer()); } else {/*w w w . jav a 2 s.c o m*/ serverStopTracker.complete(); } return serverStopTracker; }
From source file:org.eclipse.hono.service.http.HttpServiceBase.java
License:Open Source License
private Future<Void> stopInsecureServer() { Future<Void> insecureServerStopTracker = Future.future(); if (insecureServer != null) { insecureServer.close(insecureServerStopTracker.completer()); } else {//from ww w. j a va 2 s .c o m insecureServerStopTracker.complete(); } return insecureServerStopTracker; }
From source file:org.eclipse.hono.service.registration.impl.FileBasedRegistrationService.java
License:Open Source License
@Override protected void doStart(Future<Void> startFuture) { if (!running) { if (!isModificationEnabled) { log.info("modification of registered devices has been disabled"); }/*from w w w . j a v a 2s. c o m*/ if (filename != null) { loadRegistrationData(); if (saveToFile) { log.info("saving device identities to file every 3 seconds"); vertx.setPeriodic(3000, saveIdentities -> { saveToFile(Future.future()); }); } else { log.info("persistence is disabled, will not safe device identities to file"); } } } running = true; startFuture.complete(); }
From source file:org.eclipse.hono.service.registration.impl.FileBasedRegistrationService.java
License:Open Source License
@Override protected void doStop(Future<Void> stopFuture) { if (running) { Future<Void> stopTracker = Future.future(); stopTracker.setHandler(stopAttempt -> { running = false;/*from www.java2s . co m*/ stopFuture.complete(); }); if (saveToFile) { saveToFile(stopTracker); } else { stopTracker.complete(); } } else { stopFuture.complete(); } }
From source file:org.eclipse.hono.service.tenant.BaseTenantService.java
License:Open Source License
private Future<EventBusMessage> processGetByIdRequest(final EventBusMessage request, final String tenantId) { final Future<TenantResult<JsonObject>> getResult = Future.future(); get(tenantId, getResult.completer()); return getResult.map(tr -> { return request.getResponse(tr.getStatus()).setJsonPayload(tr.getPayload()).setTenant(tenantId) .setCacheDirective(tr.getCacheDirective()); });/*from w w w .j a v a2 s .c o m*/ }