Example usage for io.vertx.core.shareddata SharedData getLocalMap

List of usage examples for io.vertx.core.shareddata SharedData getLocalMap

Introduction

In this page you can find the example usage for io.vertx.core.shareddata SharedData getLocalMap.

Prototype

<K, V> LocalMap<K, V> getLocalMap(String name);

Source Link

Document

Return a LocalMap with the specific name .

Usage

From source file:examples.SharedDataExamples.java

License:Open Source License

public void example1(Vertx vertx) {

    SharedData sd = vertx.sharedData();

    LocalMap<String, String> map1 = sd.getLocalMap("mymap1");

    map1.put("foo", "bar"); // Strings are immutable so no need to copy

    LocalMap<String, Buffer> map2 = sd.getLocalMap("mymap2");

    map2.put("eek", Buffer.buffer().appendInt(123)); // This buffer will be copied before adding to map

    // Then... in another part of your application:

    map1 = sd.getLocalMap("mymap1");

    String val = map1.get("foo");

    map2 = sd.getLocalMap("mymap2");

    Buffer buff = map2.get("eek");
}

From source file:io.github.jdocker.serviceregistry.ServiceRegistry.java

License:Apache License

private void findEndpointEndReply(String endpointName, Message<String> message, SharedData sd) {
    LocalMap<String, String> map1 = sd.getLocalMap(REG_NAME);
    final String endpointValue = map1.get(endpointName);
    // TODO should we define any timeouts or anything else?
    message.reply(endpointValue);/*w  w w.j a  v  a 2 s .c o m*/
}

From source file:io.github.jdocker.serviceregistry.ServiceRegistry.java

License:Apache License

private void putToMap(Endpoint endpoin, SharedData sd) {
    LocalMap<String, String> map1 = sd.getLocalMap(REG_NAME);
    map1.putIfAbsent(endpoin.getServiceName(), Json.encode(endpoin));
}