Example usage for io.vertx.core Vertx cancelTimer

List of usage examples for io.vertx.core Vertx cancelTimer

Introduction

In this page you can find the example usage for io.vertx.core Vertx cancelTimer.

Prototype

boolean cancelTimer(long id);

Source Link

Document

Cancels the timer with the specified id .

Usage

From source file:examples.CoreExamples.java

License:Open Source License

public void example17(Vertx vertx, long timerID) {
    vertx.cancelTimer(timerID);
}

From source file:examples.ShellExamples.java

License:Open Source License

public void interruptHandler(CommandBuilder command) {
    command.processHandler(process -> {
        Vertx vertx = process.vertx();

        // Every second print a message on the console
        long periodicId = vertx.setPeriodic(1000, id -> {
            process.write("tick\n");
        });/*from   w  ww.  jav  a 2s.c om*/

        // When user press Ctrl+C: cancel the timer and end the process
        process.interruptHandler(v -> {
            vertx.cancelTimer(periodicId);
            process.end();
        });
    });
}

From source file:io.openshift.booster.messaging.Worker.java

License:Apache License

private static void sendUpdates(Vertx vertx, ProtonConnection conn) {
    ProtonSender sender = conn.createSender("work-queue/worker-updates");

    vertx.setPeriodic(5 * 1000, (timer) -> {
        if (conn.isDisconnected()) {
            vertx.cancelTimer(timer);
            return;
        }// ww w  . j  a  va2  s.  c  o  m

        if (sender.sendQueueFull()) {
            return;
        }

        log.debug("{0}: Sending status update", id);

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("workerId", conn.getContainer());
        properties.put("timestamp", System.currentTimeMillis());
        properties.put("requestsProcessed", (long) requestsProcessed.get());
        properties.put("processingErrors", (long) processingErrors.get());

        Message message = Message.Factory.create();
        message.setApplicationProperties(new ApplicationProperties(properties));

        sender.send(message);
    });

    sender.open();
}

From source file:org.sfs.integration.java.func.WaitForCluster.java

License:Apache License

@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);//from  w  w  w  . j  a v a  2  s  .c o  m
        }
    });
    return handler;
}