Package org.apache.zookeeper

Examples of org.apache.zookeeper.CreateMode


  public AccessResult doUpdate(String path, DataUpdater<T> updater, int options) {
    if (path == null || updater == null) {
      throw new NullPointerException("path|updater can't be null");
    }

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

    boolean retry;
View Full Code Here


      throw new IllegalArgumentException(
          "paths and needCreate should be of same size, but paths size: " + paths.size()
              + ", needCreate size: " + needCreate.length);
    }

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

    CreateCallbackHandler[] cbList = new CreateCallbackHandler[paths.size()];
View Full Code Here

      throw new IllegalArgumentException(
          "paths and records should be of same size, but paths size: " + size
              + ", records size: " + records.size());
    }

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

    if (size == 0) {
View Full Code Here

      throw new IllegalArgumentException(
          "paths and updaters should be of same size, but paths size: " + size
              + ", updaters size: " + updaters.size());
    }

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

    if (size == 0) {
View Full Code Here

          createZnode(pathBuffer.toString(), CreateMode.PERSISTENT, null,
              watcher);
        }
        pathBuffer.append("/")
            .append(pathComponents[pathComponents.length - 1]);
        CreateMode mode = CreateMode.EPHEMERAL;
        if (persistent) {
          mode = CreateMode.PERSISTENT;
        }
        createZnode(pathBuffer.toString(), mode, data, watcher);
View Full Code Here

        StringBuilder sb = new StringBuilder();
        // We start at 1 because / will create an empty part first
        for(int i = 1; i < subpath.length; i++) {
            sb.append("/");
            sb.append(subpath[i]);
            CreateMode m = CreateMode.PERSISTENT;
            if (i == subpath.length-1) {
                m = mode;
            }
            mknod_inner(sb.toString(), m);
        }
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.code());
        }

        try {
            CreateMode cm = CreateMode.fromFlag(-1);
            fail("Shouldn't be able to convert -1 to a CreateMode.");
        } catch(KeeperException ke) {
            assertEquals(Code.BADARGUMENTS, ke.code());
        }
    }
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);
                }
                int newCversion = parentRecord.stat.getCversion()+1;
                request.txn = new CreateTxn(path, createRequest.getData(),
                        listACL,
                        createMode.isEphemeral(), newCversion);
                StatPersisted s = new StatPersisted();
                if (createMode.isEphemeral()) {
                    s.setEphemeralOwner(request.sessionId);
                }
                parentRecord = parentRecord.duplicate(request.hdr.getZxid());
                parentRecord.childCount++;
                parentRecord.stat.setCversion(newCversion);
View Full Code Here

        if (setNull.equals("true")) {
            data = null;
        }

        CreateMode createMode;
        if (sequence.equals("true")) {
            createMode = CreateMode.PERSISTENT_SEQUENTIAL;
        } else {
            createMode = CreateMode.PERSISTENT;
        }
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.