示例#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
 /**
  * Indicates whether a given object is "equal to" this JsonObject. An object is considered equal
  * if it is also a <code>JsonObject</code> and both objects contain the same members <em>in the
  * same order</em>.
  *
  * <p>If two JsonObjects are equal, they will also produce the same JSON output.
  *
  * @param object the object to be compared with this JsonObject
  * @return <tt>true</tt> if the specified object is equal to this JsonObject, <code>false</code>
  *     otherwise
  */
 @Override
 public boolean equals(Object object) {
   if (this == object) {
     return true;
   }
   if (object == null) {
     return false;
   }
   if (getClass() != object.getClass()) {
     return false;
   }
   Member other = (Member) object;
   return name.equals(other.name) && value.equals(other.value);
 }