Example usage for io.vertx.core.shareddata AsyncMap put

List of usage examples for io.vertx.core.shareddata AsyncMap put

Introduction

In this page you can find the example usage for io.vertx.core.shareddata AsyncMap put.

Prototype

Future<Void> put(K k, V v, long ttl);

Source Link

Document

Same as #put(K,V,long,Handler) but returns a Future of the asynchronous result

Usage

From source file:examples.SharedDataExamples.java

License:Open Source License

public void example3(AsyncMap<String, String> map) {

    map.put("foo", "bar", resPut -> {
        if (resPut.succeeded()) {
            // Successfully put the value
        } else {// www . ja  v  a  2 s  .  c o  m
            // Something went wrong!
        }
    });

}

From source file:org.entcore.infra.Starter.java

License:Open Source License

private void loadInvalidEmails() {
    MapFactory.getClusterMap("invalidEmails", vertx, new Handler<AsyncMap<Object, Object>>() {
        @Override/*from   www.j a va2s.  co m*/
        public void handle(final AsyncMap<Object, Object> invalidEmails) {
            if (invalidEmails != null) {
                invalidEmails.size(new Handler<AsyncResult<Integer>>() {
                    @Override
                    public void handle(AsyncResult<Integer> event) {
                        if (event.succeeded() && event.result() < 1) {
                            MongoDb.getInstance().findOne(HardBounceTask.PLATEFORM_COLLECTION,
                                    new JsonObject().put("type", HardBounceTask.PLATFORM_ITEM_TYPE),
                                    new Handler<Message<JsonObject>>() {
                                        @Override
                                        public void handle(Message<JsonObject> event) {
                                            JsonObject res = event.body().getJsonObject("result");
                                            if ("ok".equals(event.body().getString("status")) && res != null
                                                    && res.getJsonArray("invalid-emails") != null) {
                                                for (Object o : res.getJsonArray("invalid-emails")) {
                                                    invalidEmails.put(o, "", new Handler<AsyncResult<Void>>() {
                                                        @Override
                                                        public void handle(AsyncResult<Void> event) {
                                                            if (event.failed()) {
                                                                log.error("Error adding invalid email.",
                                                                        event.cause());
                                                            }
                                                        }
                                                    });
                                                }
                                            } else {
                                                log.error(event.body().getString("message"));
                                            }
                                        }
                                    });
                        }
                    }
                });
            }
            EmailFactory emailFactory = new EmailFactory(vertx, config);
            try {
                new CronTrigger(vertx, config.getString("hard-bounces-cron", "0 0 7 * * ? *")).schedule(
                        new HardBounceTask(emailFactory.getSender(), config.getInteger("hard-bounces-day", -1),
                                new TimelineHelper(vertx, getEventBus(vertx), config), invalidEmails));
            } catch (ParseException e) {
                log.error(e.getMessage(), e);
                vertx.close();
            }
        }
    });
}