示例#1
0
  /**
   * Both Model and Set are oplog-only; they never pass the state on the wire, only the oplog; new
   * replicas are booted with distilled oplog as well. So, this is the only point in the code that
   * mutates the state of a Set.
   */
  @SwarmOperation(kind = SwarmOperationKind.Logged)
  public void change(FullSpec spec, JsonValue value) throws SwarmException {
    value = this.distillOp(spec, value);
    if (!value.isObject()) return;

    JsonObject jo = (JsonObject) value;

    for (JsonObject.Member entry : jo) {
      String keySpecStr = entry.getName();
      TypeIdSpec key_spec = new TypeIdSpec(keySpecStr);
      JsonValue val = entry.getValue();
      if (TRUE.equals(val)) {
        T obj = this.host.get(key_spec);
        this.objects.put(key_spec, obj);
        obj.on(JsonValue.NULL, this.proxy);
      } else if (FALSE.equals(val)) {
        T obj = this.objects.get(key_spec);
        if (obj != null) {
          obj.off(this.proxy);
          this.objects.remove(key_spec);
        }
      } else {
        logger.warn("unexpected value: {}->{}", spec, value);
      }
    }
  }
示例#2
0
 public void remove(T obj) throws SwarmException {
   remove(obj.getTypeId());
 }
示例#3
0
 /**
  * Adds an object to the set.
  *
  * @param obj the object //TODO , its id or its specifier.
  */
 public void add(T obj) throws SwarmException {
   final TypeIdSpec key_spec = obj.getTypeId();
   JsonObject changes = new JsonObject();
   changes.set(key_spec.toString(), TRUE);
   change(changes);
 }