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:com.glt.rest.client.RestServiceVertxEBProxy.java

License:Apache License

public void deleteJson(JsonObject command, Handler<AsyncResult<JsonObject>> asyncHandler) {
    if (closed) {
        asyncHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;/* w w  w .  j av  a 2 s  .c o m*/
    }
    JsonObject _json = new JsonObject();
    _json.put("command", command);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "deleteJson");
    _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            asyncHandler.handle(Future.failedFuture(res.cause()));
        } else {
            asyncHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.glt.rest.client.RestServiceVertxEBProxy.java

License:Apache License

public void request(JsonObject command, Handler<AsyncResult<String>> asyncHandler) {
    if (closed) {
        asyncHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//from   ww w  .  ja  v a 2 s.co m
    }
    JsonObject _json = new JsonObject();
    _json.put("command", command);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "request");
    _vertx.eventBus().<String>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            asyncHandler.handle(Future.failedFuture(res.cause()));
        } else {
            asyncHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.groupon.vertx.memcache.codec.DeleteCommandResponseCodec.java

License:Apache License

@Override
public void encodeToWire(Buffer buffer, DeleteCommandResponse commandResponse) {
    JsonObject json = new JsonObject();
    json.put("status", commandResponse.getStatus());
    json.put("message", commandResponse.getMessage());
    json.put("data", commandResponse.getData());

    CodecManager.JSON_OBJECT_MESSAGE_CODEC.encodeToWire(buffer, json);
}

From source file:com.groupon.vertx.memcache.codec.MemcacheCommandCodec.java

License:Apache License

@Override
public void encodeToWire(Buffer buffer, MemcacheCommand memcacheCommand) {
    JsonObject json = new JsonObject();
    json.put("key", memcacheCommand.getKey());
    json.put("value", memcacheCommand.getValue());
    json.put("expires", memcacheCommand.getExpires());
    json.put("type", memcacheCommand.getType());

    CodecManager.JSON_OBJECT_MESSAGE_CODEC.encodeToWire(buffer, json);
}

From source file:com.groupon.vertx.memcache.codec.MemcacheCommandResponseCodec.java

License:Apache License

@Override
public void encodeToWire(Buffer buffer, MemcacheCommandResponse commandResponse) {
    JsonObject json = new JsonObject();
    json.put("status", commandResponse.getStatus());
    json.put("message", commandResponse.getMessage());

    CodecManager.JSON_OBJECT_MESSAGE_CODEC.encodeToWire(buffer, json);
}

From source file:com.groupon.vertx.memcache.codec.ModifyCommandResponseCodec.java

License:Apache License

@Override
public void encodeToWire(Buffer buffer, ModifyCommandResponse commandResponse) {
    JsonObject json = new JsonObject();
    json.put("status", commandResponse.getStatus());
    json.put("message", commandResponse.getMessage());
    json.put("data", commandResponse.getData());

    CodecManager.JSON_OBJECT_MESSAGE_CODEC.encodeToWire(buffer, json);
}

From source file:com.groupon.vertx.memcache.codec.RetrieveCommandResponseCodec.java

License:Apache License

@Override
public void encodeToWire(Buffer buffer, RetrieveCommandResponse commandResponse) {
    JsonObject json = new JsonObject();
    json.put("status", commandResponse.getStatus());
    json.put("message", commandResponse.getMessage());
    json.put("data", commandResponse.getData());

    CodecManager.JSON_OBJECT_MESSAGE_CODEC.encodeToWire(buffer, json);
}

From source file:com.groupon.vertx.memcache.codec.StoreCommandResponseCodec.java

License:Apache License

@Override
public void encodeToWire(Buffer buffer, StoreCommandResponse commandResponse) {
    JsonObject json = new JsonObject();
    json.put("status", commandResponse.getStatus());
    json.put("message", commandResponse.getMessage());
    json.put("data", commandResponse.getData());

    CodecManager.JSON_OBJECT_MESSAGE_CODEC.encodeToWire(buffer, json);
}

From source file:com.groupon.vertx.memcache.codec.TouchCommandResponseCodec.java

License:Apache License

@Override
public void encodeToWire(Buffer buffer, TouchCommandResponse commandResponse) {
    JsonObject json = new JsonObject();
    json.put("status", commandResponse.getStatus());
    json.put("message", commandResponse.getMessage());
    json.put("data", commandResponse.getData());

    CodecManager.JSON_OBJECT_MESSAGE_CODEC.encodeToWire(buffer, json);
}

From source file:com.groupon.vertx.memcache.MemcacheClusterConfig.java

License:Apache License

public MemcacheClusterConfig(JsonObject jsonConfig) {
    if (jsonConfig == null) {
        log.error("initialize", "exception", "noConfigFound");
        throw new MemcacheException("No Memcache cluster config found");
    }//from w  w w.  jav a  2  s  .  c  o  m

    this.eventBusAddressPrefix = jsonConfig.getString(EVENT_BUS_ADDRESS_PREFIX_KEY);
    this.retryInterval = jsonConfig.getLong(RETRY_INTERVAL, MemcacheConfig.DEFAULT_RETRY_INTERVAL);
    JsonObject clusters = jsonConfig.getJsonObject(CLUSTERS_KEY, new JsonObject());

    if (eventBusAddressPrefix != null && !eventBusAddressPrefix.isEmpty() && clusters.size() > 0) {
        for (String clusterKey : clusters.fieldNames()) {
            JsonObject clusterConfig = clusters.getJsonObject(clusterKey, new JsonObject()).copy();
            clusterConfig.put(EVENT_BUS_ADDRESS_KEY, eventBusAddressPrefix);
            clusterConfig.put(RETRY_INTERVAL, retryInterval);
            clusterMap.put(clusterKey, new MemcacheConfig(clusterConfig));
        }
    } else {
        log.error("initialize", "exception", "invalidConfigFound", new String[] { "config" },
                jsonConfig.encode());
        throw new MemcacheException("Invalid Memcache config defined");
    }

    log.info("initialize", "success", new String[] { "eventBusAddressPrefix", "clusters" },
            eventBusAddressPrefix, clusterMap.size());
}