Example usage for io.vertx.core Vertx executeBlocking

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

Introduction

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

Prototype

<T> Future<@Nullable T> executeBlocking(Handler<Promise<T>> blockingCodeHandler, boolean ordered);

Source Link

Document

Same as #executeBlocking(Handler,boolean,Handler) but with an handler called when the operation completes

Usage

From source file:examples.CoreExamples.java

License:Open Source License

public void example7(Vertx vertx) {
    vertx.executeBlocking(future -> {
        // Call some blocking API that takes a significant amount of time to return
        String result = someAPI.blockingMethod("hello");
        future.complete(result);/*from   w  ww.java  2s .co m*/
    }, res -> {
        System.out.println("The result is: " + res.result());
    });
}

From source file:space.xkr47.vertx.acme4j.async.AsyncKeyPairUtils.java

License:Apache License

public static Future<KeyPair> createKeyPair(Vertx vertx, int keysize) {
    Future<KeyPair> res = future();
    vertx.executeBlocking(fut -> {
        fut.complete(KeyPairUtils.createKeyPair(keysize));
    }, res);//w w  w .j  a  v  a 2  s.com
    return res;
}

From source file:space.xkr47.vertx.acme4j.async.AsyncKeyPairUtils.java

License:Apache License

public static Future<KeyPair> readKeyPair(Vertx vertx, Buffer buf) {
    Future<KeyPair> res = future();
    vertx.executeBlocking(fut -> {
        try {/*from ww w .  jav  a2  s. com*/
            fut.complete(KeyPairUtils.readKeyPair(new StringReader(buf.toString())));
        } catch (IOException e) {
            fut.fail(e);
        }
    }, res);
    return res;
}

From source file:space.xkr47.vertx.acme4j.async.AsyncKeyPairUtils.java

License:Apache License

public static Future<Buffer> writeKeyPair(Vertx vertx, KeyPair keyPair) {
    Future<Buffer> res = future();
    vertx.executeBlocking(fut -> {
        try {/*from w w  w  .j  av  a  2s .  c  om*/
            StringWriter sw = new StringWriter();
            KeyPairUtils.writeKeyPair(keyPair, sw);
            fut.complete(Buffer.buffer(sw.toString()));
        } catch (IOException e) {
            fut.fail(e);
        }
    }, res);
    return res;
}