Package org.vertx.java.core.json

Examples of org.vertx.java.core.json.JsonArray


    @Override
    public void length(final Handler<Integer> next) {
        JsonObject redis = new JsonObject();
        redis.putString("command", "keys");
        redis.putArray("args", new JsonArray().add(prefix + "*"));

        eventBus.send(redisAddress, redis, new Handler<Message<JsonObject>>() {
            @Override
            public void handle(Message<JsonObject> message) {
                if (!"ok".equals(message.body().getString("status"))) {
                    next.handle(0);
                } else {
                    JsonArray keys = message.body().getArray("value");
                    next.handle(keys.size());
                }
            }
        });
    }
View Full Code Here


    @SuppressWarnings("unused")
    private void getKeys(final Handler<JsonArray> next) {
        JsonObject redis = new JsonObject();
        redis.putString("command", "keys");
        redis.putArray("args", new JsonArray().add(prefix + "*"));

        eventBus.send(redisAddress, redis, new Handler<Message<JsonObject>>() {
            @Override
            public void handle(Message<JsonObject> message) {
                if (!"ok".equals(message.body().getString("status"))) {
                    next.handle(new JsonArray());
                } else {
                    JsonArray keys = message.body().getArray("value");

                    JsonArray result = new JsonArray();
                    int len = prefix.length();

                    for (Object o : keys) {
                        String key = (String) o;
                        result.add(key.substring(len));
                    }

                    next.handle(result);
                }
            }
View Full Code Here

        if (o instanceof Map) {
            return (R) new JsonObject((Map) o);
        }
        if (o instanceof List) {
            return (R) new JsonArray((List) o);
        }
        return (R) o;
    }
View Full Code Here

        if (body != null) {
            if (body instanceof Map) {
                return (V) new JsonObject((Map) body);
            }
            if (body instanceof List) {
                return (V) new JsonArray((List) body);
            }
        }

        return (V) body;
    }
View Full Code Here

            @Override
            public void put(int index, Scriptable start, Object value) {
                if (!json.isArray())
                    throw new RuntimeException("Not a JsonArray.");
                JsonArray arr = json.asArray();
                if (index != arr.size() + 1)
                    throw new RuntimeException("JsonArray does not allow put at random index");
                arr.add(fromNative(value, scope));
            }

            @Override
            public void delete(String name) {
                if (!json.isObject())
View Full Code Here

        if (isNativeArray || isNativeObject) {
            // Convert JavaScript json to vertx JsonArray or JsonObject
            Object json = NativeJSON.stringify(Context.getCurrentContext(), scope, value, null, null);
            if (json instanceof String) {
                if (isNativeArray) {
                    value = new JsonArray((List) Json.decodeValue((String) json, List.class));
                } else {
                    value = new JsonObject((Map) Json.decodeValue((String) json, Map.class));
                }
            }
        }
View Full Code Here

    final RxEventBus rx=new RxEventBus(vertx.eventBus());

    vertx.eventBus().registerHandler("countdown", new Handler<Message<Integer>>() {

      public void sendBatch(final Message<Integer> msg, int from, int length) {
        JsonArray res = new JsonArray();
        for (int i = from; i < from+length; i++) {
          res.add(i);
        }
        // As long as above 0 wait for another request
        if (from > 0) {
          msg.reply(res, this);
        } else {
View Full Code Here

    final RxEventBus rx=new RxEventBus(vertx.eventBus());

    vertx.eventBus().registerHandler("countdown", new Handler<Message<Integer>>() {

      public void sendBatch(final Message<Integer> msg, int from, int length) {
        JsonArray res = new JsonArray();
        for (int i = from; i < from+length; i++) {
          res.add(i);
        }
        // As long as above 0 wait for another request
        if (from > 0) {
          msg.reply(res, this);
        } else {
View Full Code Here

   * @see "SocketNamespace.prototype.setFlags"
   */
  private void setFlags() {
    this.flags = new JsonObject();
    flags.putString("endpoint", this.name);
    flags.putArray("exceptions", new JsonArray());
  }
View Full Code Here

   */
  public Namespace packet(JsonObject packet) {
    packet.putString("endpoint", this.getName());
    Store store = this.manager.getStore();
    boolean isVolatile = this.flags.getBoolean("volatile", false);
    JsonArray exceptions = this.flags.getArray("exceptions");
    String encodedPacket = parser.encodePacket(packet);

    this.manager.onDispatch(this.flags.getString("endpoint"), encodedPacket, isVolatile, exceptions);
    //    this.store.publish('dispatch', this.flags.endpoint, packet, volatile, exceptions);
    this.setFlags();
View Full Code Here

TOP

Related Classes of org.vertx.java.core.json.JsonArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.