Package com.goodow.realtime.json

Examples of com.goodow.realtime.json.JsonObject


  public void load(final String id, final Handler<Document> onLoaded,
      final Handler<Model> opt_initializer, final Handler<Error> opt_error) {
    bus.send(Constants.Topic.STORE, Json.createObject().set(Key.ID, id), new Handler<Message<JsonObject>>() {
      @Override
      public void handle(Message<JsonObject> message) {
        JsonObject body = message.body();
        if (!body.has(Key.VERSION)) {
          body.set(Key.VERSION, 0);
        }
        final DocumentBridge bridge =
            new DocumentBridge(SubscribeOnlyStore.this, id, body.getArray(Key.SNAPSHOT),
                               body.getArray(Key.COLLABORATORS), opt_error);
        onLoaded(id, opt_initializer, body.getNumber(Key.VERSION), bridge);
        if (body.getNumber(Key.VERSION) == 0) {
          bridge.createRoot();
          if (opt_initializer != null) {
            Platform.scheduler().handle(opt_initializer, bridge.getDocument().getModel());
          }
        }
View Full Code Here


        bus.subscribe(topic, new Handler<Message<JsonObject>>() {
          Transformer<CollaborativeOperation> transformer = new CollaborativeTransformer();

          @Override
          public void handle(Message<JsonObject> message) {
            JsonObject body = message.body();
            CollaborativeOperation op = transformer.createOperation(body);
            bridge.consume(op);
          }
        });
    bridge.setOutputSink(new OutputSink() {
View Full Code Here

  @Test
  public void testInitialize() {
    VertxAssert.assertEquals(0, list.length());

    JsonObject v4 = Json.createObject();
    v4.set("subKey", "subValue");
    list = mod.createList(Json.createArray().push("v1").push(1).push(true).push(v4).push(null));
    VertxAssert.assertEquals(5, list.length());
    VertxAssert.assertEquals("v1", list.get(0));
    VertxAssert.assertEquals(1d, (Double) list.get(1), 0d);
    VertxAssert.assertEquals(true, list.get(2));
    VertxAssert.assertTrue(v4.equals(list.get(3)));
    VertxAssert.assertNull(list.get(4));

    VertxAssert.testComplete();
  }
View Full Code Here

    VertxAssert.testComplete();
  }

  @Test
  public void testInsert() {
    JsonObject v4 = Json.createObject();
    v4.set("subKey", "subValue");
    list.insertAll(0, Json.createArray().push("v1").push(1).push(true).push(v4).push(null));
    list.insert(0, null);
    Object obj = null;
    list.insertAll(2, Json.createArray().push(obj));
    list.insertAll(0, Json.createArray());
View Full Code Here

  @Test
  public void testInitialize() {
    VertxAssert.assertEquals(0, map.size());
    VertxAssert.assertTrue(map.isEmpty());

    JsonObject v4 = Json.createObject();
    v4.set("subKey", "subValue");
    JsonObject initialValue = Json.createObject();
    initialValue.set("k1", "v1").set("k2", 2).set("k3", true).set("k4", v4);
    map = mod.createMap(initialValue);
    VertxAssert.assertEquals(4, map.size());
    VertxAssert.assertEquals("v1", map.get("k1"));
    VertxAssert.assertEquals(2d, (Double) map.get("k2"), 0d);
    VertxAssert.assertEquals(true, map.get("k3"));
View Full Code Here

    consumeAndSubmit(op);
  }

  @Override
  public JsonObject toJson() {
    JsonObject json = Json.createObject();
    json.set("id", id).set("referencedObjectId", referencedObjectId).set("index", index).set(
        "canBeDeleted", canBeDeleted);
    return json;
  }
View Full Code Here

  private void sendUnackedOps() {
    O unackedClientOp = queue.unackedClientOp();
    assert unackedClientOp != null;
    logger.log(Level.FINE, "Sending " + unackedClientOp + " @" + queue.version());

    JsonObject delta =
        Json.createObject().set("action", "post").set(Key.ID, id).set(Key.OP_DATA,
            ((JsonObject) unackedClientOp.toJson()).set(Key.VERSION, queue.version()));
    bus.send(Constants.Topic.STORE, delta, new Handler<Message<JsonObject>>() {
      @Override
      public void handle(Message<JsonObject> message) {
View Full Code Here

    return snapshot.size();
  }

  @Override
  public JsonObject toJson() {
    final JsonObject json = Json.createObject();
    snapshot.forEach(new MapIterator<JsonArray>() {
      @Override
      public void call(String key, JsonArray value) {
        Object val = get(key);
        if (val instanceof CollaborativeObjectImpl) {
          json.set(key, ((CollaborativeObject) val).toJson());
        } else {
          json.set(key, snapshot.getArray(key).get(1));
        }
      }
    });
    return json;
  }
View Full Code Here

    handlerRegs.wrap(bus.subscribe(
        Constants.Topic.STORE + "/" + internalApi.id + Constants.Topic.PRESENCE
        + Constants.Topic.WATCH, new Handler<Message<JsonObject>>() {
          @Override
          public void handle(Message<JsonObject> message) {
            JsonObject body = message.body().set(Key.IS_ME, false);
            Collaborator collaborator = new CollaboratorImpl(body);
            boolean isJoined = !body.has(Key.IS_JOINED) || body.getBoolean(Key.IS_JOINED);
            String sessionId = collaborator.sessionId();
            if (isJoined) {
              if (!collaborators.has(sessionId)) {
                collaborators.set(sessionId, collaborator);
                model.bridge.store.getBus().publishLocal(
View Full Code Here

      @Override
      public void handle(Message<JsonObject> message) {
        if (!isConnected()) {
          return;
        }
        JsonObject body = message.body();
        O op = transformer.createOperation(body);
        double appliedAt = body.getNumber(Key.VERSION);
        if (bus.getSessionId().equals(body.getString(Key.SESSION_ID))) {
          onAckOwnOperation(appliedAt, op);
        } else {
          onIncomingOperation(appliedAt, op);
        }
      }
View Full Code Here

TOP

Related Classes of com.goodow.realtime.json.JsonObject

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.