Package org.apache.zookeeper

Examples of org.apache.zookeeper.CreateMode


                ChangeRecord parentRecord = getRecordForPath(parentPath);

                checkACL(zks, parentRecord.acl, ZooDefs.Perms.CREATE,
                        request.authInfo);
                int parentCVersion = parentRecord.stat.getCversion();
                CreateMode createMode =
                    CreateMode.fromFlag(createRequest.getFlags());
                if (createMode.isSequential()) {
                    path = path + String.format("%010d", parentCVersion);
                }
                try {
                    PathUtils.validatePath(path);
                } catch(IllegalArgumentException ie) {
                    LOG.info("Invalid path " + path + " with session 0x" +
                            Long.toHexString(request.sessionId));
                    throw new KeeperException.BadArgumentsException(path);
                }
                try {
                    if (getRecordForPath(path) != null) {
                        throw new KeeperException.NodeExistsException(path);
                    }
                } catch (KeeperException.NoNodeException e) {
                    // ignore this one
                }
                boolean ephemeralParent = parentRecord.stat.getEphemeralOwner() != 0;
                if (ephemeralParent) {
                    throw new KeeperException.NoChildrenForEphemeralsException(path);
                }
                txn = new CreateTxn(path, createRequest.getData(),
                        createRequest.getAcl(),
                        createMode.isEphemeral());
                StatPersisted s = new StatPersisted();
                if (createMode.isEphemeral()) {
                    s.setEphemeralOwner(request.sessionId);
                }
                parentRecord = parentRecord.duplicate(txnHeader.getZxid());
                parentRecord.childCount++;
                parentRecord.stat
View Full Code Here


                ChangeRecord parentRecord = getRecordForPath(parentPath);

                checkACL(zks, parentRecord.acl, ZooDefs.Perms.CREATE,
                        request.authInfo);
                int parentCVersion = parentRecord.stat.getCversion();
                CreateMode createMode =
                    CreateMode.fromFlag(createRequest.getFlags());
                if (createMode.isSequential()) {
                    path = path + String.format(Locale.ENGLISH, "%010d", parentCVersion);
                }
                try {
                    PathUtils.validatePath(path);
                } catch(IllegalArgumentException ie) {
                    LOG.info("Invalid path " + path + " with session 0x" +
                            Long.toHexString(request.sessionId));
                    throw new KeeperException.BadArgumentsException(path);
                }
                try {
                    if (getRecordForPath(path) != null) {
                        throw new KeeperException.NodeExistsException(path);
                    }
                } catch (KeeperException.NoNodeException e) {
                    // ignore this one
                }
                boolean ephemeralParent = parentRecord.stat.getEphemeralOwner() != 0;
                if (ephemeralParent) {
                    throw new KeeperException.NoChildrenForEphemeralsException(path);
                }
                txn = new CreateTxn(path, createRequest.getData(),
                        createRequest.getAcl(),
                        createMode.isEphemeral());
                StatPersisted s = new StatPersisted();
                if (createMode.isEphemeral()) {
                    s.setEphemeralOwner(request.sessionId);
                }
                parentRecord = parentRecord.duplicate(txnHeader.getZxid());
                parentRecord.childCount++;
                parentRecord.stat
View Full Code Here

        boolean         isDone = false;
        for ( int i = 0; !isDone && (i < MAX_TRIES); ++i )
        {
            try
            {
                CreateMode      mode = (service.getServiceType() == ServiceType.DYNAMIC) ? CreateMode.EPHEMERAL : CreateMode.PERSISTENT;
                client.create().creatingParentsIfNeeded().withMode(mode).forPath(path, bytes);
                isDone = true;
            }
            catch ( KeeperException.NodeExistsException e )
            {
View Full Code Here

public class CreateModeTest extends TestCase {
   
    @Test
    public void testBasicCreateMode() {
        CreateMode cm = CreateMode.PERSISTENT;
        assertEquals(cm.toFlag(), 0);
        assertFalse(cm.isEphemeral());
        assertFalse(cm.isSequential());
       
        cm = CreateMode.EPHEMERAL;
        assertEquals(cm.toFlag(), 1);
        assertTrue(cm.isEphemeral());
        assertFalse(cm.isSequential());
       
        cm = CreateMode.PERSISTENT_SEQUENTIAL;
        assertEquals(cm.toFlag(), 2);
        assertFalse(cm.isEphemeral());
        assertTrue(cm.isSequential());
       
        cm = CreateMode.EPHEMERAL_SEQUENTIAL;
        assertEquals(cm.toFlag(), 3);
        assertTrue(cm.isEphemeral());
        assertTrue(cm.isSequential());
    }
View Full Code Here

    }

    @Test
    public void testInvalidFlagConversion() throws KeeperException {
        try {
            CreateMode cm = CreateMode.fromFlag(99);
            fail("Shouldn't be able to convert 99 to a CreateMode.");
        } catch(KeeperException ke) {
            assertEquals(Code.BadArguments, ke.getCode());
        }

        try {
            CreateMode cm = CreateMode.fromFlag(-1);
            fail("Shouldn't be able to convert -1 to a CreateMode.");
        } catch(KeeperException ke) {
            assertEquals(Code.BadArguments, ke.getCode());
        }
    }
View Full Code Here

              return record;
            }
          };
          client.updateDataSerialized(path, updater);
        } else {
          CreateMode mode = (persistent) ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL;
          if (record.getDeltaList().size() > 0) {
            ZNRecord value = new ZNRecord(record.getId());
            value.merge(record);
            client.create(path, value, mode);
          } else {
View Full Code Here

          }
        } else {
          client.asyncSetData(path, record, -1, null);
        }
      } else {
        CreateMode mode = (persistent) ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL;
        if (record.getDeltaList().size() > 0) {
          ZNRecord newRecord = new ZNRecord(record.getId());
          newRecord.merge(record);
          client.create(path, null, mode);
View Full Code Here

              return record;
            }
          };
          client.updateDataSerialized(path, updater);
        } else {
          CreateMode mode = (persistent) ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL;
          client.create(path, record, mode);
        }
        break;
      } catch (Exception e) {
        retryCount = retryCount + 1;
View Full Code Here

  public AccessResult doCreate(String path, T record, int options) {
    if (path == null) {
      throw new NullPointerException("path can't be null");
    }

    CreateMode mode = AccessOption.getMode(options);
    if (mode == null) {
      throw new IllegalArgumentException("Invalid create options: " + options);
    }

    boolean retry;
View Full Code Here

  public AccessResult doSet(String path, T record, int expectVersion, int options) {
    if (path == null) {
      throw new NullPointerException("path can't be null");
    }

    CreateMode mode = AccessOption.getMode(options);
    if (mode == null) {
      throw new IllegalArgumentException("Invalid set options: " + options);
    }

    Stat stat = null;
View Full Code Here

TOP

Related Classes of org.apache.zookeeper.CreateMode

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.