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); } }
@Override void validate() throws KeeperException { CreateMode createMode = CreateMode.fromFlag(flags); PathUtils.validatePath(getPath(), createMode.isSequential()); EphemeralType.validateTTL(createMode, ttl); } }
@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) * @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); }
@Test public void testFlagConversion() throws KeeperException { // Ensure we get the same value back after round trip conversion EnumSet<CreateMode> allModes = EnumSet.allOf(CreateMode.class); for(CreateMode cm : allModes) { Assert.assertEquals(cm, CreateMode.fromFlag( cm.toFlag() ) ); } }
if (op.getType() == OpCode.create || op.getType() == OpCode.create2) { CreateRequest createRequest = (CreateRequest)op.toRequestRecord(); CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags()); if (createMode.isEphemeral()) { containsEphemeralCreate = true; ByteBufferInputStream.byteBuffer2Record(request.request, createRequest); request.request.rewind(); CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags()); if (!createMode.isEphemeral()) { return null;
@Test public void testInvalidFlagConversion() throws KeeperException { try { CreateMode.fromFlag(99); Assert.fail("Shouldn't be able to convert 99 to a CreateMode."); } catch(KeeperException ke) { Assert.assertEquals(Code.BADARGUMENTS, ke.code()); } try { CreateMode.fromFlag(-1); Assert.fail("Shouldn't be able to convert -1 to a CreateMode."); } catch(KeeperException ke) { Assert.assertEquals(Code.BADARGUMENTS, ke.code()); } } }
private static void createAndFailSilent(ZKWatcher zkw, CreateAndFailSilent cafs) throws KeeperException { CreateRequest create = (CreateRequest)toZooKeeperOp(zkw, cafs).toRequestRecord(); String znode = create.getPath(); try { RecoverableZooKeeper zk = zkw.getRecoverableZooKeeper(); if (zk.exists(znode, false) == null) { zk.create(znode, create.getData(), create.getAcl(), CreateMode.fromFlag(create.getFlags())); } } catch(KeeperException.NodeExistsException nee) { } catch(KeeperException.NoAuthException nee){ try { if (null == zkw.getRecoverableZooKeeper().exists(znode, false)) { // If we failed to create the file and it does not already exist. throw(nee); } } catch (InterruptedException ie) { zkw.interruptedException(ie); } } catch(InterruptedException ie) { zkw.interruptedException(ie); } }
int parentCVersion = parentRecord.stat.getCversion(); CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags()); if (createMode.isSequential()) { path = path + String.format(Locale.ENGLISH, "%010d", parentCVersion);
ttl = -1; CreateMode createMode = CreateMode.fromFlag(flags); validateCreateRequest(path, createMode, request, ttl); String parentPath = validatePathForCreate(path, request.sessionId);
@Override protected CreateMode getCreateMode() throws KeeperException { return CreateMode.fromFlag(mode); }
@Override public List<OpResult> multi(Iterable<Op> ops) throws KeeperException, InterruptedException { List<OpResult> opResults = new ArrayList<>(); for (Op op : ops) { if (Op.Check.class.isAssignableFrom(op.getClass())) { CheckVersionRequest check = (CheckVersionRequest) op.toRequestRecord(); exists(check.getPath(), false); opResults.add(new OpResult.CheckResult()); } else if (Op.Create.class.isAssignableFrom(op.getClass())) { CreateRequest create = (CreateRequest) op.toRequestRecord(); String path = create(create.getPath(), create.getData(), CreateMode.fromFlag(create.getFlags())); opResults.add(new OpResult.CreateResult(path)); } else if (Op.Delete.class.isAssignableFrom(op.getClass())) { DeleteRequest delete = (DeleteRequest) op.toRequestRecord(); delete(delete.getPath()); opResults.add(new OpResult.DeleteResult()); } else if (Op.SetData.class.isAssignableFrom(op.getClass())) { SetDataRequest setData = (SetDataRequest) op.toRequestRecord(); writeData(setData.getPath(), setData.getData(), setData.getVersion()); opResults.add(new OpResult.SetDataResult(null)); } } return opResults; }
private static void createAndFailSilent(ZKWatcher zkw, CreateAndFailSilent cafs) throws KeeperException { CreateRequest create = (CreateRequest)toZooKeeperOp(zkw, cafs).toRequestRecord(); String znode = create.getPath(); try { RecoverableZooKeeper zk = zkw.getRecoverableZooKeeper(); if (zk.exists(znode, false) == null) { zk.create(znode, create.getData(), create.getAcl(), CreateMode.fromFlag(create.getFlags())); } } catch(KeeperException.NodeExistsException nee) { } catch(KeeperException.NoAuthException nee){ try { if (null == zkw.getRecoverableZooKeeper().exists(znode, false)) { // If we failed to create the file and it does not already exist. throw(nee); } } catch (InterruptedException ie) { zkw.interruptedException(ie); } } catch(InterruptedException ie) { zkw.interruptedException(ie); } }
private static void createAndFailSilent(ZooKeeperWatcher zkw, CreateAndFailSilent cafs) throws KeeperException { CreateRequest create = (CreateRequest)toZooKeeperOp(zkw, cafs).toRequestRecord(); String znode = create.getPath(); try { RecoverableZooKeeper2 zk = zkw.getRecoverableZooKeeper2(); if (zk.exists(znode, false) == null) { zk.create(znode, create.getData(), create.getAcl(), CreateMode.fromFlag(create.getFlags())); } } catch(KeeperException.NodeExistsException nee) { } catch(KeeperException.NoAuthException nee){ try { if (null == zkw.getRecoverableZooKeeper2().exists(znode, false)) { // If we failed to create the file and it does not already exist. throw(nee); } } catch (InterruptedException ie) { zkw.interruptedException(ie); } } catch(InterruptedException ie) { zkw.interruptedException(ie); } }
private static void createAndFailSilent(ZooKeeperWatcher zkw, CreateAndFailSilent cafs) throws KeeperException { CreateRequest create = (CreateRequest)toZooKeeperOp(zkw, cafs).toRequestRecord(); String znode = create.getPath(); try { RecoverableZooKeeper zk = zkw.getRecoverableZooKeeper(); if (zk.exists(znode, false) == null) { zk.create(znode, create.getData(), create.getAcl(), CreateMode.fromFlag(create.getFlags())); } } catch(KeeperException.NodeExistsException nee) { } catch(KeeperException.NoAuthException nee){ try { if (null == zkw.getRecoverableZooKeeper().exists(znode, false)) { // If we failed to create the file and it does not already exist. throw(nee); } } catch (InterruptedException ie) { zkw.interruptedException(ie); } } catch(InterruptedException ie) { zkw.interruptedException(ie); } }
private static void createAndFailSilent(ZooKeeperWatcher zkw, CreateAndFailSilent cafs) throws KeeperException { CreateRequest create = (CreateRequest)toZooKeeperOp(zkw, cafs).toRequestRecord(); String znode = create.getPath(); try { RecoverableZooKeeper zk = zkw.getRecoverableZooKeeper(); if (zk.exists(znode, false) == null) { zk.create(znode, create.getData(), create.getAcl(), CreateMode.fromFlag(create.getFlags())); } } catch(KeeperException.NodeExistsException nee) { } catch(KeeperException.NoAuthException nee){ try { if (null == zkw.getRecoverableZooKeeper().exists(znode, false)) { // If we failed to create the file and it does not already exist. throw(nee); } } catch (InterruptedException ie) { zkw.interruptedException(ie); } } catch(InterruptedException ie) { zkw.interruptedException(ie); } }
int parentCVersion = parentRecord.stat.getCversion(); CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags()); if (createMode.isSequential()) { path = path + String.format("%010d", parentCVersion);