Example usage for io.vertx.core Future succeededFuture

List of usage examples for io.vertx.core Future succeededFuture

Introduction

In this page you can find the example usage for io.vertx.core Future succeededFuture.

Prototype

static <T> Future<T> succeededFuture() 

Source Link

Document

Create a succeeded future with a null result

Usage

From source file:com.github.ithildir.airbot.BaseServiceVerticle.java

License:Open Source License

protected Future<Void> start(JsonObject configJsonObject) {
    _messageConsumer = ProxyHelper.registerService(getServiceInterface(), vertx,
            getServiceImpl(configJsonObject), getAddress());

    return Future.succeededFuture();
}

From source file:com.github.ithildir.airbot.service.impl.AirNowMeasurementServiceImpl.java

License:Open Source License

private void _initReportingAreaRecords(Handler<AsyncResult<Void>> handler) {
    HttpRequest<?> httpRequest = _webClient.get(_REPORTING_AREA_URI);

    RecordParser recordParser = RecordParser.newDelimited("\n", this::_initReportingAreaRecord);

    httpRequest = httpRequest.as(BodyCodec.pipe(new RecordParserWriteStream(recordParser)));

    httpRequest.send(asyncResult -> {
        HttpResponse<?> httpResponse = _handleHttpResponse(asyncResult, handler);

        if (httpResponse == null) {
            return;
        }//from   w  w  w .j av  a  2  s  .  c o m

        _reportingAreaETag = httpResponse.getHeader(HttpHeaders.ETAG.toString());

        if (_logger.isInfoEnabled()) {
            _logger.info("AirNow reporting area records updated with ETag {0}", _reportingAreaETag);
        }

        handler.handle(Future.succeededFuture());
    });
}

From source file:com.github.ithildir.airbot.service.impl.DummyUserServiceImpl.java

License:Open Source License

@Override
public void updateUserLocation(String userId, double latitude, double longitude, String country,
        Handler<AsyncResult<Void>> handler) {

    Location location = new Location(latitude, longitude, country);

    _userLocationsMap.put(userId, location);

    handler.handle(Future.succeededFuture());
}

From source file:com.github.ithildir.airbot.service.impl.WaqiMeasurementServiceImpl.java

License:Open Source License

@Override
public void init(Handler<AsyncResult<Void>> handler) {
    handler.handle(Future.succeededFuture());
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

License:Apache License

private void createWithoutValidate(JsonObject data, RBatch redissonBatch,
        AsyncResultHandler<String> resultHandler) {
    AtomicReference<String> id = new AtomicReference<>();
    Async.waterfall().<String>task(this::newId).<String>task((i, t) -> {
        id.set(i);//from   w w  w  .jav  a  2 s  . c  o  m
        ensureUniqueAndIndexing(id.get(), data, true, rs -> {
            if (rs.succeeded() && rs.result() == null) {
                t.handle(Future.succeededFuture());
            } else if (rs.result() != null) {
                t.handle(Future.failedFuture(new RepositoryException(rs.result())));
            } else {
                t.handle(Future.failedFuture(rs.cause()));
            }
        });
    }).<Boolean>task((rs, t) -> {
        persist(id.get(), data.put("id", id.get()), redissonBatch, t);
    }).run(run -> {
        resultHandler
                .handle(run.succeeded() ? Future.succeededFuture(id.get()) : Future.failedFuture(run.cause()));
    });
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

License:Apache License

private void updateWithoutValidate(String id, JsonObject data, RBatch redissonBatch,
        Handler<AsyncResult<Boolean>> resultHandler) {
    vertx.<Boolean>executeBlocking(f -> {
        Async.waterfall().<Boolean>task(t -> idExist(id, t)).<String>task((idExist, t) -> {
            if (!idExist) {
                t.handle(Future.failedFuture(new RepositoryException("ID: " + id + " does not exist")));
                return;
            }/*from ww  w  .ja v a  2 s .c o m*/
            ensureUniqueAndIndexing(id, data, false, rs -> {
                if (rs.succeeded() && rs.result() == null) {
                    t.handle(Future.succeededFuture());
                } else if (rs.result() != null) {
                    t.handle(Future.failedFuture(rs.result()));
                } else {
                    t.handle(Future.failedFuture(rs.cause()));
                }
            });

        }).<Boolean>task((rs, t) -> persist(id, data, redissonBatch, t)).run(run -> {
            if (run.succeeded() && !f.isComplete()) {
                f.complete(run.result());
            } else if (!f.isComplete()) {
                f.fail(run.cause());
            }
        });
    }, resultHandler);
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

License:Apache License

private void ensureUniqueAndIndexingBlocking(String id, JsonObject data, Boolean isNew,
        AsyncResultHandler<String> resultHandler) {
    Async.waterfall().<String>task(t -> {
        RBatch batch = redissonOther.createBatch();
        ArrayList<String> pList = new ArrayList();
        try {/*from w  w w  .j  av  a 2s .c  o m*/
            prepareEnsureUnique(id, data, batch, pList, null);
        } catch (RepositoryException ex) {
            t.handle(Future.failedFuture(ex));
            return;
        }
        if (pList.isEmpty()) {
            t.handle(Future.succeededFuture());
            return;
        }
        batch.executeAsync().addListener(future -> {
            if (future.isSuccess() && future.get() != null) {
                List<String> result = (List<String>) future.get();
                Stream<String> filter = pList.stream().filter(
                        p -> result.get(pList.indexOf(p)) != null && !result.get(pList.indexOf(p)).equals(id));//uniques are ensured by using putIfAbsent and all results should be null or itself to indicate no violation.
                Object[] filterArray = filter.toArray();
                if (filterArray.length != 0) {
                    t.handle(Future.succeededFuture(
                            new JsonObject().put("uniqueViolation", Json.encode(filterArray)).encode()));
                    //now undo these things.
                    ArrayList<String> undoList = pList.stream()
                            .filter(p -> result.get(pList.indexOf(p)) == null
                                    || result.get(pList.indexOf(p)).equals(id))
                            .collect(Collectors.toCollection(ArrayList::new));
                    Async.<Void>waterfall().<Void>task(task -> {
                        RBatch b = redissonOther.createBatch();
                        try {
                            prepareUndoUnique(id, data, b, undoList, null);
                        } catch (RepositoryException ex) {
                            task.handle(Future.failedFuture(ex));
                        }
                        b.executeAsync().addListener(fu -> {
                            task.handle(fu.isSuccess() ? Future.succeededFuture((Void) fu.get())
                                    : Future.failedFuture(fu.cause()));
                        });
                    }).run(run -> {
                        logger.debug("Parallel undo indexing [id: " + id + "] "
                                + (run.succeeded() ? "successed." : "failed."));
                    });
                } else {
                    t.handle(Future.succeededFuture());
                }
            } else {
                t.handle(Future.failedFuture(!future.isSuccess() ? future.cause().fillInStackTrace()
                        : new RepositoryException("No unique check result returned")));
            }
        });
    }).<String>task((violations, t) -> {
        if (violations != null) {
            t.handle(Future.failedFuture(violations));
            return;
        } else {
            t.handle(Future.succeededFuture());
        }
        //parallel indexing
        Async.<Void>waterfall().<T>task(task -> {
            if (!isNew) {
                fetch(id, Boolean.TRUE, task);
            } else {
                task.handle(Future.succeededFuture(null));
            }
        }).<Void>task((r, task) -> {
            reIndex(id, r, data, isNew, ri -> {
                task.handle(
                        ri.succeeded() ? Future.succeededFuture(ri.result()) : Future.failedFuture(ri.cause()));
            });
        }).run(run -> {
            logger.debug("Parallel Indexing [id: " + id + "] " + (run.succeeded() ? "successed." : "failed."),
                    run.cause());
        });
    }).run(resultHandler);

}

From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

License:Apache License

private void reIndexBlocking(String id, T r, JsonObject data, Boolean isNew,
        Handler<AsyncResult<Void>> resultHandler) {

    RBatch updateIndexBatch = redissonOther.createBatch();
    ArrayList<String> pList = new ArrayList();
    try {//ww w .j  ava 2 s. co  m
        prepareEnsuerIndex(id, r, data, isNew, updateIndexBatch, pList, null);
    } catch (Exception e) {
        resultHandler.handle(Future.failedFuture(e));
        return;
    }
    updateIndexBatch.executeAsync().addListener(f -> {
        resultHandler.handle(f.isSuccess() ? Future.succeededFuture()
                : Future.failedFuture(new RepositoryException(f.cause())));
        if (f.isSuccess()) {
            logger.debug("[" + getStorageKey() + "] Re Index Success : " + id);
        } else {
            logger.debug("[" + getStorageKey() + "] Re Index Failure", f.cause());
        }
    });
}

From source file:com.hubrick.vertx.kafka.producer.DefaultKafkaProducerService.java

License:Apache License

protected void sendOK(Handler<AsyncResult<Void>> resultHandler) {
    resultHandler.handle(Future.succeededFuture());
}

From source file:de.braintags.netrelay.controller.api.MailController.java

License:Open Source License

private static void readData(MailPreferences prefs, UriMailAttachment attachment,
        Handler<AsyncResult<Void>> handler) {
    URI uri = attachment.getUri();
    HttpClient client = prefs.httpClient;
    int port = uri.getPort() > 0 ? uri.getPort() : 80;
    HttpClientRequest req = client.request(HttpMethod.GET, port, uri.getHost(), uri.getPath(), resp -> {
        resp.bodyHandler(buff -> {/*from w  w  w .j a  va2  s . c  om*/
            try {
                attachment.setData(buff);
                handler.handle(Future.succeededFuture());
            } catch (Exception e) {
                LOGGER.error("", e);
                handler.handle(Future.failedFuture(e));
            }
        });
    });
    req.end();
}