Java Code Examples for io.vertx.core.Vertx#setPeriodic()
The following examples show how to use
io.vertx.core.Vertx#setPeriodic() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertTest.java From jdk-source-analysis with Apache License 2.0 | 8 votes |
@Test public void test() { Vertx vertx = Vertx.vertx(); // request.response().putHeader("Content-Type", "text/plain").write("some text").end(); vertx.setPeriodic(1000, id -> { System.out.println(id); }); vertx.executeBlocking(promise -> { }, asyncResult -> { }); HttpServer server = vertx.createHttpServer(); Handler<HttpServerRequest> requestHandler = server.requestHandler(); }
Example 2
Source File: AccountServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
public AccountServiceVertxProxyHandler(Vertx vertx, AccountService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 3
Source File: StoreCRUDServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
public StoreCRUDServiceVertxProxyHandler(Vertx vertx, StoreCRUDService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 4
Source File: RegistryInspector.java From vertx-micrometer-metrics with Apache License 2.0 | 6 votes |
public static void waitForValue(Vertx vertx, TestContext context, String regName, String fullName, Predicate<Double> p) { Async ready = context.async(); vertx.setPeriodic(200, id -> { try { RegistryInspector.listDatapoints(regName, m -> true).stream() .filter(dp -> fullName.equals(dp.id())) .filter(dp -> p.test(dp.value())) .findAny() .ifPresent(dp -> { vertx.cancelTimer(id); ready.complete(); }); } catch (NoRegistryException e) { context.fail(e); vertx.cancelTimer(id); } }); ready.awaitSuccess(10000); }
Example 5
Source File: ProductServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
public ProductServiceVertxProxyHandler(Vertx vertx, ProductService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 6
Source File: PortfolioServiceVertxProxyHandler.java From vertx-kubernetes-workshop with Apache License 2.0 | 6 votes |
public PortfolioServiceVertxProxyHandler(Vertx vertx, PortfolioService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 7
Source File: PortfolioServiceVertxProxyHandler.java From vertx-microservices-workshop with Apache License 2.0 | 6 votes |
public PortfolioServiceVertxProxyHandler(Vertx vertx, PortfolioService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 8
Source File: PortfolioServiceVertxProxyHandler.java From microtrader with MIT License | 6 votes |
public PortfolioServiceVertxProxyHandler(Vertx vertx, PortfolioService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 9
Source File: EchoServiceVertxProxyHandler.java From weld-vertx with Apache License 2.0 | 6 votes |
public EchoServiceVertxProxyHandler(Vertx vertx, EchoService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 10
Source File: HelloServiceVertxProxyHandler.java From vertx-rx with Apache License 2.0 | 6 votes |
public HelloServiceVertxProxyHandler(Vertx vertx, HelloService service, boolean topLevel, long timeoutSeconds, boolean includeDebugInfo) { this.vertx = vertx; this.service = service; this.includeDebugInfo = includeDebugInfo; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 11
Source File: JobServiceVertxProxyHandler.java From vertx-kue with Apache License 2.0 | 6 votes |
public JobServiceVertxProxyHandler(Vertx vertx, JobService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) { } if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 12
Source File: PortfolioServiceVertxProxyHandler.java From vertx-microservices-workshop with Apache License 2.0 | 6 votes |
public PortfolioServiceVertxProxyHandler(Vertx vertx, PortfolioService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 13
Source File: QueryableVertxProxyHandler.java From vertx-graphql-service-discovery with Apache License 2.0 | 6 votes |
public QueryableVertxProxyHandler(Vertx vertx, Queryable service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 14
Source File: PaymentQueryServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
public PaymentQueryServiceVertxProxyHandler(Vertx vertx, PaymentQueryService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 15
Source File: CounterServiceVertxProxyHandler.java From vertx-blueprint-microservice with Apache License 2.0 | 6 votes |
public CounterServiceVertxProxyHandler(Vertx vertx, CounterService service, boolean topLevel, long timeoutSeconds) { this.vertx = vertx; this.service = service; this.timeoutSeconds = timeoutSeconds; try { this.vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec()); } catch (IllegalStateException ex) {} if (timeoutSeconds != -1 && !topLevel) { long period = timeoutSeconds * 1000 / 2; if (period > 10000) { period = 10000; } this.timerID = vertx.setPeriodic(period, this::checkTimedOut); } else { this.timerID = -1; } accessed(); }
Example 16
Source File: WaitForCluster.java From sfs with Apache License 2.0 | 5 votes |
@Override public Observable<Void> call(Void aVoid) { ObservableFuture<Void> handler = RxHelper.observableFuture(); Vertx vertx = vertxContext.vertx(); vertx.setPeriodic(100, timerId -> { TransientServiceDef masterNode = vertxContext.verticle().getClusterInfo().getCurrentMasterNode(); if (masterNode != null) { vertx.cancelTimer(timerId); handler.complete(null); } }); return handler; }
Example 17
Source File: CurrencyConversionService.java From prebid-server-java with Apache License 2.0 | 5 votes |
/** * Sets timer for periodic currency rates updates and starts initial population. * <p> * Must be called on Vertx event loop thread. */ @Override public void initialize() { if (externalConversionProperties != null) { final Long refreshPeriod = externalConversionProperties.getRefreshPeriod(); final Long defaultTimeout = externalConversionProperties.getDefaultTimeout(); final HttpClient httpClient = externalConversionProperties.getHttpClient(); final Vertx vertx = externalConversionProperties.getVertx(); vertx.setPeriodic(refreshPeriod, ignored -> populatesLatestCurrencyRates(currencyServerUrl, defaultTimeout, httpClient)); populatesLatestCurrencyRates(currencyServerUrl, defaultTimeout, httpClient); } }
Example 18
Source File: VertxEcho.java From vertx-in-action with MIT License | 5 votes |
public static void main(String[] args) { Vertx vertx = Vertx.vertx(); vertx.createNetServer() .connectHandler(VertxEcho::handleNewClient) .listen(3000); vertx.setPeriodic(5000, id -> System.out.println(howMany())); vertx.createHttpServer() .requestHandler(request -> request.response().end(howMany())) .listen(8080); }
Example 19
Source File: DockerServiceImporter.java From vertx-service-discovery with Apache License 2.0 | 4 votes |
/** * Starts the bridge. * * @param vertx the vert.x instance * @param publisher the service discovery instance * @param configuration the bridge configuration if any * @param completion future to assign with completion status */ @Override public void start(Vertx vertx, ServicePublisher publisher, JsonObject configuration, Promise<Void> completion) { this.publisher = publisher; this.vertx = vertx; DefaultDockerClientConfig.Builder builder = DefaultDockerClientConfig.createDefaultConfigBuilder(); String dockerCertPath = configuration.getString("docker-cert-path"); String dockerCfgPath = configuration.getString("docker-cfg-path"); String email = configuration.getString("docker-registry-email"); String password = configuration.getString("docker-registry-password"); String username = configuration.getString("docker-registry-username"); String host = configuration.getString("docker-host"); boolean tlsVerify = configuration.getBoolean("docker-tls-verify", true); String registry = configuration.getString("docker-registry-url", "https://index.docker.io/v1/"); String version = configuration.getString("version"); if (dockerCertPath != null) { builder.withDockerCertPath(dockerCertPath); } if (dockerCfgPath != null) { builder.withDockerConfig(dockerCfgPath); } if (email != null) { builder.withRegistryEmail(email); } if (password != null) { builder.withRegistryPassword(password); } if (username != null) { builder.withRegistryUsername(username); } if (host != null) { builder.withDockerHost(host); } if (registry != null) { builder.withRegistryUrl(registry); } if (version != null) { builder.withApiVersion(version); } builder.withDockerTlsVerify(tlsVerify); DockerClientConfig config = builder.build(); if (config.getDockerHost().getScheme().equalsIgnoreCase("unix")) { try { this.host = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { completion.fail(e); } } else { this.host = config.getDockerHost().getHost(); } client = DockerClientBuilder.getInstance(config).build(); long period = configuration.getLong("scan-period", 3000L); if (period > 0) { timer = vertx.setPeriodic(period, l -> { scan(null); }); } scan(completion); }
Example 20
Source File: DefaultClientEndpointMetricManager.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
public void setVertx(Vertx vertx) { vertx.setPeriodic(metricsOptionsEx.getCheckClientEndpointMetricIntervalInMilliseconds(), this::onCheckClientEndpointMetricExpired); }