Class CreateBuilderImpl

    • Constructor Detail

      • CreateBuilderImpl

        public CreateBuilderImpl​(CuratorFrameworkImpl client,
                                 org.apache.zookeeper.CreateMode createMode,
                                 Backgrounding backgrounding,
                                 boolean createParentsIfNeeded,
                                 boolean createParentsAsContainers,
                                 boolean doProtected,
                                 boolean compress,
                                 boolean setDataIfExists,
                                 java.util.List<org.apache.zookeeper.data.ACL> aclList,
                                 org.apache.zookeeper.data.Stat storingStat,
                                 long ttl)
    • Method Detail

      • setSetDataIfExistsVersion

        public void setSetDataIfExistsVersion​(int version)
      • withTtl

        public CreateBuilderMain withTtl​(long ttl)
        Description copied from interface: CreateBuilder
        Specify a TTL when mode is CreateMode.PERSISTENT_WITH_TTL or CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL. If the znode has not been modified within the given TTL, it will be deleted once it has no children. The TTL unit is milliseconds and must be greater than 0 and less than or equal to EphemeralType.MAX_TTL.
        Specified by:
        withTtl in interface CreateBuilder
        Specified by:
        withTtl in interface CreateBuilder2
        Parameters:
        ttl - the ttl
        Returns:
        this for chaining
      • withACL

        public ACLBackgroundPathAndBytesable<java.lang.String> withACL​(java.util.List<org.apache.zookeeper.data.ACL> aclList)
        Description copied from interface: ACLable
        Set an ACL list (default is ZooDefs.Ids.OPEN_ACL_UNSAFE)
        Specified by:
        withACL in interface ACLable<BackgroundPathAndBytesable<java.lang.String>>
        Parameters:
        aclList - the ACL list to use
        Returns:
        this
      • withACL

        public ACLBackgroundPathAndBytesable<java.lang.String> withACL​(java.util.List<org.apache.zookeeper.data.ACL> aclList,
                                                                       boolean applyToParents)
        Description copied from interface: ParentACLable
        Set an ACL list (default is ZooDefs.Ids.OPEN_ACL_UNSAFE). If applyToParents is true, then the aclList is applied to the created parents. Existing parent nodes are not affected.
        Specified by:
        withACL in interface ParentACLable<BackgroundPathAndBytesable<java.lang.String>>
        Parameters:
        aclList - the ACL list to use
        applyToParents - if true, then the aclList is applied to the created parents.
        Returns:
        this
      • creatingParentContainersIfNeeded

        public ProtectACLCreateModeStatPathAndBytesable<java.lang.String> creatingParentContainersIfNeeded()
        Description copied from interface: CreateBuilderMain
        Causes any parent nodes to get created using CreateMode.CONTAINER if they haven't already been. IMPORTANT NOTE: container creation is a new feature in recent versions of ZooKeeper. If the ZooKeeper version you're using does not support containers, the parent nodes are created as ordinary PERSISTENT nodes.
        Specified by:
        creatingParentContainersIfNeeded in interface CreateBuilderMain
        Returns:
        this
      • withProtection

        public ACLCreateModeStatBackgroundPathAndBytesable<java.lang.String> withProtection()
        Description copied from interface: CreateBuilderMain

        Hat-tip to https://github.com/sbridges for pointing this out

        It turns out there is an edge case that exists when creating sequential-ephemeral nodes. The creation can succeed on the server, but the server can crash before the created node name is returned to the client. However, the ZK session is still valid so the ephemeral node is not deleted. Thus, there is no way for the client to determine what node was created for them.

        Even without sequential-ephemeral, however, the create can succeed on the sever but the client (for various reasons) will not know it.

        Putting the create builder into protection mode works around this. The name of the node that is created is prefixed with a 40 characters string that is the concatenation of

        • "_c_"
        • Canonical text representation of a random generated UUID as produced by UUID.toString()
        • 45
        If node creation fails the normal retry mechanism will occur. On the retry, the parent path is first searched for a node that has previous described prefix in it. If that node is found, it is assumed to be the lost node that was successfully created on the first try and is returned to the caller.

        Specified by:
        withProtection in interface CreateBuilderMain
        Returns:
        this
      • inBackground

        public ErrorListenerPathAndBytesable<java.lang.String> inBackground​(BackgroundCallback callback,
                                                                            java.lang.Object context,
                                                                            java.util.concurrent.Executor executor)
        Description copied from interface: Backgroundable
        Perform the action in the background
        Specified by:
        inBackground in interface Backgroundable<ErrorListenerPathAndBytesable<java.lang.String>>
        Parameters:
        callback - a functor that will get called when the operation has completed
        context - context object - will be available from the event sent to the listener
        executor - executor to use for the background call
        Returns:
        this
      • forPath

        public java.lang.String forPath​(java.lang.String path)
                                 throws java.lang.Exception
        Description copied from interface: PathAndBytesable
        Commit the currently building operation using the given path and the default data for the client (usually a byte[0] unless changed via CuratorFrameworkFactory.Builder.defaultData(byte[])).
        Specified by:
        forPath in interface PathAndBytesable<java.lang.String>
        Parameters:
        path - the path
        Returns:
        operation result if any
        Throws:
        java.lang.Exception - errors
      • forPath

        public java.lang.String forPath​(java.lang.String givenPath,
                                        byte[] data)
                                 throws java.lang.Exception
        Description copied from interface: PathAndBytesable
        Commit the currently building operation using the given path and data
        Specified by:
        forPath in interface PathAndBytesable<java.lang.String>
        Parameters:
        givenPath - the path
        data - the data
        Returns:
        operation result if any
        Throws:
        java.lang.Exception - errors
      • performBackgroundOperation

        public void performBackgroundOperation​(org.apache.curator.framework.imps.OperationAndData<org.apache.curator.framework.imps.PathAndBytes> operationAndData)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception