Java Code Examples for io.vertx.core.Vertx#setTimer()
The following examples show how to use
io.vertx.core.Vertx#setTimer() .
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: AsyncBeforeCombinedTest.java From vertx-junit5 with Apache License 2.0 | 5 votes |
@BeforeEach void before_each(VertxTestContext context, Vertx vertx) { assertEquals(1, step); Checkpoint checkpoint = context.checkpoint(); vertx.setTimer(200, id -> { step = 2; checkpoint.flag(); }); }
Example 2
Source File: ProtonReceiverImpl.java From vertx-proton with Apache License 2.0 | 5 votes |
private void setDrainHandlerAndTimeoutTask(long delay, Handler<AsyncResult<Void>> completionHandler) { drainCompleteHandler = completionHandler; if(delay > 0) { Vertx vertx = Vertx.currentContext().owner(); drainTimeoutTaskId = vertx.setTimer(delay, x -> { drainTimeoutTaskId = null; drainCompleteHandler = null; completionHandler.handle(Future.failedFuture("Drain attempt timed out")); }); } }
Example 3
Source File: EventbusBridgeExecution.java From vxms with Apache License 2.0 | 5 votes |
private static void resetLockTimer( VxmsShared vxmsShared, int retryCount, long circuitBreakerTimeout, Counter counter) { final Vertx vertx = vxmsShared.getVertx(); vertx.setTimer( circuitBreakerTimeout, timer -> counter.addAndGet(Integer.valueOf(retryCount + 1).longValue(), val -> {})); }
Example 4
Source File: ResponseExecution.java From vxms with Apache License 2.0 | 5 votes |
private static void setCircuitBreakerReleaseTimer( VxmsShared vxmsShared, int _retry, long _circuitBreakerTimeout, Counter counter) { final Vertx vertx = vxmsShared.getVertx(); vertx.setTimer( _circuitBreakerTimeout, timer -> { final long initialRetryCounterValue = (long) (_retry + 1); counter.addAndGet(initialRetryCounterValue, val -> {}); }); }
Example 5
Source File: AsyncBeforeAllTest.java From vertx-junit5 with Apache License 2.0 | 5 votes |
@BeforeAll static void before1(VertxTestContext context, Vertx vertx) { int c = count.get(); boolean s = started2; if (c == 1) { assertTrue(s); } Checkpoint checkpoint = context.checkpoint(); vertx.setTimer(20, id -> { started1 = true; count.incrementAndGet(); checkpoint.flag(); }); }
Example 6
Source File: NativeExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void observableHandler(Vertx vertx) { ObservableHandler<Long> observable = RxHelper.observableHandler(); observable.subscribe(id -> { // Fired }); vertx.setTimer(1000, observable.toHandler()); }
Example 7
Source File: AsyncBeforeCombinedTest.java From vertx-junit5 with Apache License 2.0 | 5 votes |
@BeforeAll static void before_all(VertxTestContext context, Vertx vertx) { assertEquals(0, step); Checkpoint checkpoint = context.checkpoint(); vertx.setTimer(200, id -> { step = 1; checkpoint.flag(); }); }
Example 8
Source File: EventbusBridgeExecution.java From vxms with Apache License 2.0 | 5 votes |
private static void resetLockTimer( VxmsShared vxmsShared, int retryCount, long circuitBreakerTimeout, Counter counter) { final Vertx vertx = vxmsShared.getVertx(); vertx.setTimer( circuitBreakerTimeout, timer -> counter.addAndGet(Integer.valueOf(retryCount + 1).longValue(), val -> {})); }
Example 9
Source File: AsyncBeforeEachTest.java From vertx-junit5 with Apache License 2.0 | 5 votes |
@BeforeEach void before1(VertxTestContext context, Vertx vertx) { int c = count.get(); boolean s = started2; if (c == 1) { assertTrue(s); } Checkpoint checkpoint = context.checkpoint(); vertx.setTimer(20, id -> { started1 = true; count.incrementAndGet(); checkpoint.flag(); }); }
Example 10
Source File: VxApiRouteHandlerHttpServiceImpl.java From VX-API-Gateway with MIT License | 5 votes |
/** * 当存在坏的后台服务时重试连接后台看后台连接是否可用 * * @param vertx */ public void retryConnServer(Vertx vertx) { if (!policy.isCheckWaiting()) { policy.setCheckWaiting(true); vertx.setTimer(serOptions.getRetryTime(), testConn -> { if (LOG.isDebugEnabled()) { LOG.debug(String.format("应用:%s -> API:%s重试连接后台服务URL...", appName, api.getApiName())); } List<VxApiServerURLInfo> service = policy.getBadService(); if (service != null) { for (VxApiServerURLInfo urlinfo : service) { httpClient.requestAbs(serOptions.getMethod(), urlinfo.getUrl()).setTimeout(serOptions.getTimeOut()).handler(resp -> { int statusCode = resp.statusCode(); if (statusCode != 200) { LOG.warn(String.format("应用:%s -> API:%s重试连接后台服务URL,连接成功但得到一个%d状态码,", appName, api.getApiName(), statusCode)); } else { if (LOG.isDebugEnabled()) { LOG.debug(String.format("应用:%s -> API:%s重试连接后台服务URL,连接成功 !", appName, api.getApiName())); } } policy.reportGreatService(urlinfo.getIndex()); }).exceptionHandler(e -> { if (LOG.isDebugEnabled()) { LOG.debug(String.format("应用:%s -> API:%s重试连接后台服务URL->失败:", appName, api.getApiName()), e); } }).end(); } } policy.setCheckWaiting(false); }); } }
Example 11
Source File: SessionTokenGrantAuthHandler.java From VX-API-Gateway with MIT License | 5 votes |
/** * 当存在坏的后台服务时重试连接后台看后台连接是否可用 * * @param vertx */ public void retryConnServer(Vertx vertx) { if (!policy.isCheckWaiting()) { if (webClient == null) { webClient = WebClient.create(vertx); } policy.setCheckWaiting(true); vertx.setTimer(serOptions.getRetryTime(), testConn -> { List<VxApiServerURLInfo> service = policy.getBadService(); if (service != null) { for (VxApiServerURLInfo urlinfo : service) { webClient.requestAbs(serOptions.getMethod(), urlinfo.getUrl()).timeout(serOptions.getTimeOut()).send(res -> { if (res.succeeded()) { int statusCode = res.result().statusCode(); if (statusCode != 200) { LOG.warn(String.format("应用:%s -> API:%s重试连接后台服务URL,连接成功但得到一个%d状态码,", api.getAppName(), api.getApiName(), statusCode)); } else { if (LOG.isDebugEnabled()) { LOG.debug(String.format("应用:%s -> API:%s重试连接后台服务URL,连接成功!", api.getAppName(), api.getApiName())); } } policy.reportGreatService(urlinfo.getIndex()); } }); } } policy.setCheckWaiting(false); }); } }
Example 12
Source File: DelayFault.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
private void executeDelay(FaultParam faultParam, AsyncResponse asynResponse, long delay) { Vertx vertx = faultParam.getVertx(); if (vertx != null) { vertx.setTimer(delay, timeID -> asynResponse.success(SUCCESS_RESPONSE)); return; } try { Thread.sleep(delay); } catch (InterruptedException e) { LOGGER.info("Interrupted exception is received"); } asynResponse.success(SUCCESS_RESPONSE); }
Example 13
Source File: StepExecution.java From vxms with Apache License 2.0 | 5 votes |
private static void setCircuitBreakerReleaseTimer( VxmsShared vxmsShared, int _retry, long _circuitBreakerTimeout, Counter counter) { final Vertx vertx = vxmsShared.getVertx(); vertx.setTimer( _circuitBreakerTimeout, timer -> { final long initialRetryCounterValue = (long) (_retry + 1); counter.addAndGet(initialRetryCounterValue, val -> { }); }); }
Example 14
Source File: ResponseExecution.java From vxms with Apache License 2.0 | 5 votes |
private static void setCircuitBreakerReleaseTimer( VxmsShared vxmsShared, int _retry, long _circuitBreakerTimeout, Counter counter) { final long initialRetryCounterValue = (long) (_retry + 1); final Vertx vertx = vxmsShared.getVertx(); vertx.setTimer( _circuitBreakerTimeout, timer -> counter.addAndGet(initialRetryCounterValue, val -> { })); }
Example 15
Source File: VoidController.java From nubes with Apache License 2.0 | 4 votes |
@GET("/withAsyncResponse") public void asyncWithResponse(HttpServerResponse response, Vertx vertx) { vertx.setTimer(1000, timer -> response.end()); }
Example 16
Source File: DashboardExample.java From vertx-circuit-breaker with Apache License 2.0 | 4 votes |
private static Handler<Promise<String>> commandThatWorks(Vertx vertx) { return (future -> vertx.setTimer(5, l -> future.complete("OK !"))); }
Example 17
Source File: DashboardExample.java From vertx-circuit-breaker with Apache License 2.0 | 4 votes |
private static Handler<Promise<String>> commandThatFails(Vertx vertx) { return (future -> vertx.setTimer(5, l -> future.fail("expected failure"))); }
Example 18
Source File: EventbusExecution.java From vxms with Apache License 2.0 | 4 votes |
private static <T> void openCircuitAndHandleError( String methodId, VxmsShared vxmsShared, Consumer<Throwable> errorMethodHandler, RoutingContext context, Map<String, String> headers, Encoder encoder, Consumer<Throwable> errorHandler, ThrowableFunction<Throwable, T> onFailureRespond, int httpStatusCode, int httpErrorCode, int retryCount, long timeout, long delay, long circuitBreakerTimeout, RecursiveExecutor<T> executor, AsyncResult<Message<Object>> event, Lock lock, Counter counter) { final Vertx vertx = vxmsShared.getVertx(); vertx.setTimer( circuitBreakerTimeout, timer -> counter.addAndGet(Integer.valueOf(retryCount + 1).longValue(), val -> {})); counter.addAndGet( LOCK_VALUE, val -> { final Throwable cause = event.cause(); handleError( methodId, vxmsShared, errorMethodHandler, context, headers, encoder, errorHandler, onFailureRespond, httpStatusCode, httpErrorCode, retryCount, timeout, delay, circuitBreakerTimeout, executor, lock, cause); }); }
Example 19
Source File: DashboardExample.java From vertx-circuit-breaker with Apache License 2.0 | 4 votes |
private static Handler<Promise<String>> commandThatTimeoutAndFail(Vertx vertx, int timeout) { return (future -> vertx.setTimer(timeout + 500, l -> future.fail("late failure"))); }
Example 20
Source File: BrokenConsul.java From vertx-consul-client with Apache License 2.0 | 4 votes |
SlowHttpServer(Vertx vertx, long delay) { super(vertx, h -> vertx.setTimer(delay, t -> h.response().end())); }