if (op instanceof Create) { Create create = (Create) op; LOG.debug("op : create {}", create.getPath()); } else if (op instanceof Delete) { Delete delete = (Delete) op;
/** * Constructs a create operation. Arguments are as for the ZooKeeper method of the same name. * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode) * @see CreateMode#fromFlag(int) * * @param path * the path for the node * @param data * the initial data for the node * @param acl * the acl for the node * @param flags * specifying whether the node to be created is ephemeral * and/or sequential but using the integer encoding. */ public static Op create(String path, byte[] data, List<ACL> acl, int flags) { return new Create(path, data, acl, flags); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Create)) return false; Create op = (Create) o; boolean aclEquals = true; Iterator<ACL> i = op.acl.iterator(); for (ACL acl : op.acl) { boolean hasMoreData = i.hasNext(); if (!hasMoreData) { aclEquals = false; break; } ACL otherAcl = i.next(); if (!acl.equals(otherAcl)) { aclEquals = false; break; } } return !i.hasNext() && getType() == op.getType() && Arrays.equals(data, op.data) && flags == op.flags && aclEquals; }
/** * Constructs a create operation. Arguments are as for the ZooKeeper method of the same name. * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode) * * @param path * the path for the node * @param data * the initial data for the node * @param acl * the acl for the node * @param createMode * specifying whether the node to be created is ephemeral * and/or sequential */ public static Op create(String path, byte[] data, List<ACL> acl, CreateMode createMode) { return new Create(path, data, acl, createMode); }
@Override public Record toRequestRecord() { return new CreateRequest(getPath(), data, acl, flags); }
@Override Op withChroot(String path) { return new Create(path, data, acl, flags); }
/** * Constructs a create operation. Arguments are as for the ZooKeeper method of the same name * but adding an optional ttl * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode) * @see CreateMode#fromFlag(int) * * @param path * the path for the node * @param data * the initial data for the node * @param acl * the acl for the node * @param flags * specifying whether the node to be created is ephemeral * and/or sequential but using the integer encoding. * @param ttl * optional ttl or 0 (flags must imply a TTL creation mode) */ public static Op create(String path, byte[] data, List<ACL> acl, int flags, long ttl) { CreateMode createMode = CreateMode.fromFlag(flags, CreateMode.PERSISTENT); if (createMode.isTTL()) { return new CreateTTL(path, data, acl, createMode, ttl); } return new Create(path, data, acl, flags); }
@Override void validate() throws KeeperException { CreateMode createMode = CreateMode.fromFlag(flags); PathUtils.validatePath(getPath(), createMode.isSequential()); } }
/** * Constructs a create operation. Arguments are as for the ZooKeeper method of the same name * but adding an optional ttl * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode) * * @param path * the path for the node * @param data * the initial data for the node * @param acl * the acl for the node * @param createMode * specifying whether the node to be created is ephemeral * and/or sequential * @param ttl * optional ttl or 0 (createMode must imply a TTL) */ public static Op create(String path, byte[] data, List<ACL> acl, CreateMode createMode, long ttl) { if (createMode.isTTL()) { return new CreateTTL(path, data, acl, createMode, ttl); } return new Create(path, data, acl, createMode); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Create)) return false; Create op = (Create) o; boolean aclEquals = true; Iterator<ACL> i = op.acl.iterator(); for (ACL acl : op.acl) { boolean hasMoreData = i.hasNext(); if (!hasMoreData) { aclEquals = false; break; } ACL otherAcl = i.next(); if (!acl.equals(otherAcl)) { aclEquals = false; break; } } return !i.hasNext() && getType() == op.getType() && Arrays.equals(data, op.data) && flags == op.flags && aclEquals; }
/** * Constructs a create operation. Arguments are as for the ZooKeeper method of the same name. * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode) * @see CreateMode#fromFlag(int) * * @param path * the path for the node * @param data * the initial data for the node * @param acl * the acl for the node * @param flags * specifying whether the node to be created is ephemeral * and/or sequential but using the integer encoding. */ public static Op create(String path, byte[] data, List<ACL> acl, int flags) { return new Create(path, data, acl, flags); }
/** * Constructs a create operation. Arguments are as for the ZooKeeper method of the same name. * @see ZooKeeper#create(String, byte[], java.util.List, CreateMode) * * @param path * the path for the node * @param data * the initial data for the node * @param acl * the acl for the node * @param createMode * specifying whether the node to be created is ephemeral * and/or sequential */ public static Op create(String path, byte[] data, List<ACL> acl, CreateMode createMode) { return new Create(path, data, acl, createMode); }
@Override public int hashCode() { return super.hashCode() + (int)(ttl ^ (ttl >>> 32)); }
@Override public boolean equals(Object o) { return super.equals(o) && (o instanceof CreateTTL) && (ttl == ((CreateTTL)o).ttl); }
@Override public Record toRequestRecord() { return new CreateRequest(getPath(), data, acl, flags); }
private Create(String path, byte[] data, List<ACL> acl, int flags) { super(getOpcode(CreateMode.fromFlag(flags, CreateMode.PERSISTENT)), path); this.data = data; this.acl = acl; this.flags = flags; }
@Override void validate() throws KeeperException { CreateMode createMode = CreateMode.fromFlag(flags); PathUtils.validatePath(getPath(), createMode.isSequential()); EphemeralType.validateTTL(createMode, -1); } }
private Create(String path, byte[] data, List<ACL> acl, CreateMode createMode) { super(getOpcode(createMode), path); this.data = data; this.acl = acl; this.flags = createMode.toFlag(); }