Example usage for io.vertx.core.json JsonObject put

List of usage examples for io.vertx.core.json JsonObject put

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject put.

Prototype

public JsonObject put(String key, Object value) 

Source Link

Document

Put an Object into the JSON object with the specified key.

Usage

From source file:microservicerx.rx.DistributedObservableCodec.java

@Override
public void encodeToWire(Buffer buffer, DistributedObservable customMessage) {
    // Easiest ways is using JSON object
    JsonObject jsonToEncode = new JsonObject();
    jsonToEncode.put("address", customMessage.address);

    // Encode object to string
    String jsonToStr = jsonToEncode.encode();

    // Length of JSON: is NOT characters count
    int length = jsonToStr.getBytes().length;

    // Write data into given buffer
    buffer.appendInt(length);//from ww w.  j  av  a  2 s  . c  o  m
    buffer.appendString(jsonToStr);
}

From source file:name.bpdp.vertx.blazegraph.BlazegraphServiceVertxEBProxy.java

License:Apache License

public void save(String collection) {
    if (closed) {
        throw new IllegalStateException("Proxy is closed");
    }//from  w w  w  .jav a2s. co m
    JsonObject _json = new JsonObject();
    _json.put("collection", collection);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "save");
    _vertx.eventBus().send(_address, _json, _deliveryOptions);
}

From source file:name.bpdp.vertx.changeme.ChangemeServiceVertxEBProxy.java

License:Apache License

public void method1(String method1Arg, Handler<AsyncResult<String>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//from w w w . java  2s  .  c  o m
    }
    JsonObject _json = new JsonObject();
    _json.put("method1Arg", method1Arg);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "method1");
    _vertx.eventBus().<String>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            resultHandler.handle(Future.failedFuture(res.cause()));
        } else {
            resultHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:net.kuujo.vertigo.context.impl.InputContextImpl.java

License:Apache License

@Override
public JsonObject toJson() {
    JsonObject json = new JsonObject();
    ports.forEach((key, port) -> {//from w w  w . ja  va 2  s  .c o  m
        json.put(key, port.toJson());
    });
    return json;
}

From source file:net.kuujo.vertigo.context.impl.InputPortContextImpl.java

License:Apache License

@Override
public JsonObject toJson() {
    JsonArray connectionJson = new JsonArray();
    connections.forEach(connection -> connectionJson.add(connection.toJson()));

    JsonObject json = new JsonObject().put("name", name).put("connections", connectionJson);

    if (type != null && type != Object.class) {
        json.put("type", type.toString());
    }//w  w w . j  a v  a 2 s .co  m

    if (codec != null) {
        json.put("codec", codec.toString());
    }

    //    if (persistent) {
    //      json.put("persistent", persistent);
    //    }

    return json;

}

From source file:net.kuujo.vertigo.impl.AbstractResolver.java

License:Apache License

/**
 * Converts a Typesafe configuration object to {@link io.vertx.core.json.JsonObject}
 *
 * @param config The Typesafe configuration object to convert.
 * @return The converted configuration.// w ww.  ja v  a2  s  .co m
 */
@SuppressWarnings("unchecked")
protected static JsonObject configObjectToJson(Config config) {
    JsonObject json = new JsonObject();
    for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
        String key = entry.getKey();
        ConfigValue value = entry.getValue();
        if (key.contains(".")) {
            key = key.substring(0, key.indexOf('.'));
            value = config.getValue(key);
        }
        if (value.valueType() == ConfigValueType.OBJECT) {
            json.put(key, configObjectToJson(config.getConfig(key)));
        } else if (value.valueType() == ConfigValueType.LIST) {
            json.put(key, configListToJson(config.getList(key)));
        } else {
            json.put(key, value.unwrapped());
        }
    }
    return json;
}

From source file:net.kuujo.vertigo.network.impl.BasePortConfigImpl.java

License:Apache License

@Override
public JsonObject toJson() {
    JsonObject json = new JsonObject();
    if (type != null && type != Object.class) {
        json.put(PORT_TYPE, type.getName());
    }//from  www  . j a v a2  s  .c om
    if (codec != null) {
        json.put(PORT_CODEC, codec.getName());
    }
    if (persistent) {
        json.put(PORT_PERSISTENT, true);
    }
    return json;
}

From source file:net.kuujo.vertigo.network.impl.ComponentConfigImpl.java

License:Apache License

@Override
public JsonObject toJson() {
    JsonObject json = new JsonObject();
    json.put(COMPONENT_NAME, name);
    json.put(COMPONENT_IDENTIFIER, identifier);
    json.put(COMPONENT_CONFIG, config);/* w  ww  . j av a 2 s.  com*/
    json.put(COMPONENT_WORKER, worker);
    json.put(COMPONENT_MULTI_THREADED, multiThreaded);
    json.put(COMPONENT_STATEFUL, stateful);
    json.put(COMPONENT_REPLICAS, replicas);
    json.put(COMPONENT_RESOURCES,
            new JsonArray(Arrays.asList(resources.toArray(new String[resources.size()]))));
    JsonObject input = new JsonObject();
    for (InputPortConfig port : this.input.getPorts()) {
        input.put(port.getName(), port.toJson());
    }
    json.put(COMPONENT_INPUT, input);
    JsonObject output = new JsonObject();
    for (OutputPortConfig port : this.output.getPorts()) {
        output.put(port.getName(), port.toJson());
    }
    json.put(COMPONENT_OUTPUT, output);
    return json;
}

From source file:net.kuujo.vertigo.network.impl.ConnectionConfigImpl.java

License:Apache License

@Override
public JsonObject toJson() {
    JsonObject json = new JsonObject();
    json.put(CONNECTION_SOURCE, source != null ? source.toJson() : null);
    json.put(CONNECTION_TARGET, target != null ? target.toJson() : null);
    json.put(CONNECTION_ORDERED, ordered);
    json.put(CONNECTION_AT_LEAST_ONCE, atLeastOnce);
    json.put(CONNECTION_SEND_TIMEOUT, sendTimeout);
    return json;/*  www.j  a  va 2 s. co  m*/
}

From source file:net.kuujo.vertigo.network.impl.EndpointConfigImpl.java

License:Apache License

@Override
public JsonObject toJson() {
    JsonObject json = new JsonObject();
    if (component != null) {
        json.put(ENDPOINT_COMPONENT, component);
    }//from  w w w .  j ava  2  s  .com
    if (isNetwork) {
        json.put(ENDPOINT_IS_NETWORK, true);
    }
    json.put(ENDPOINT_PORT, port);
    return json;
}