Class ZooKeeperRetry

    • Constructor Detail

      • ZooKeeperRetry

        public ZooKeeperRetry​(java.lang.String connectString,
                              int sessionTimeout,
                              Watcher watcher)
                       throws java.io.IOException
        Parameters:
        connectString -
        sessionTimeout -
        watcher -
        Throws:
        java.io.IOException
      • ZooKeeperRetry

        public ZooKeeperRetry​(java.lang.String connectString,
                              int sessionTimeout,
                              Watcher watcher,
                              long sessionId,
                              byte[] sessionPasswd)
                       throws java.io.IOException
        Parameters:
        connectString -
        sessionTimeout -
        watcher -
        sessionId -
        sessionPasswd -
        Throws:
        java.io.IOException
    • Method Detail

      • close

        public void close()
                   throws java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Close this client object. Once the client is closed, its session becomes invalid. All the ephemeral nodes in the ZooKeeper server associated with the session will be removed. The watches left on those nodes (and on their parents) will be triggered.

        Added in 3.5.3: try-with-resources may be used instead of calling close directly.

        This method does not wait for all internal threads to exit. Use the ZooKeeper.close(int) method to wait for all resources to be released

        Specified by:
        close in interface java.lang.AutoCloseable
        Overrides:
        close in class ZooKeeper
        Throws:
        java.lang.InterruptedException
      • create

        public java.lang.String create​(java.lang.String path,
                                       byte[] data,
                                       java.util.List<ACL> acl,
                                       CreateMode createMode)
                                throws KeeperException,
                                       java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Create a node with the given path. The node data will be the given data, and node acl will be the given acl.

        The flags argument specifies whether the created node will be ephemeral or not.

        An ephemeral node will be removed by the ZooKeeper automatically when the session associated with the creation of the node expires.

        The flags argument can also specify to create a sequential node. The actual path name of a sequential node will be the given path plus a suffix "i" where i is the current sequential number of the node. The sequence number is always fixed length of 10 digits, 0 padded. Once such a node is created, the sequential number will be incremented by one.

        If a node with the same actual path already exists in the ZooKeeper, a KeeperException with error code KeeperException.NodeExists will be thrown. Note that since a different actual path is used for each invocation of creating sequential node with the same path argument, the call will never throw "file exists" KeeperException.

        If the parent node does not exist in the ZooKeeper, a KeeperException with error code KeeperException.NoNode will be thrown.

        An ephemeral node cannot have children. If the parent node of the given path is ephemeral, a KeeperException with error code KeeperException.NoChildrenForEphemerals will be thrown.

        This operation, if successful, will trigger all the watches left on the node of the given path by exists and getData API calls, and the watches left on the parent node by getChildren API calls.

        If a node is created successfully, the ZooKeeper server will trigger the watches on the path left by exists calls, and the watches on the parent of the node by getChildren calls.

        The maximum allowable size of the data array is 1 MB (1,048,576 bytes). Arrays larger than this will cause a KeeperExecption to be thrown.

        Overrides:
        create in class ZooKeeper
        Parameters:
        path - the path for the node
        data - the initial data for the node
        acl - the acl for the node
        createMode - specifying whether the node to be created is ephemeral and/or sequential
        Returns:
        the actual path of the created node
        Throws:
        KeeperException - if the server returns a non-zero error code
        KeeperException.InvalidACLException - if the ACL is invalid, null, or empty
        java.lang.InterruptedException - if the transaction is interrupted
      • delete

        public void delete​(java.lang.String path,
                           int version)
                    throws java.lang.InterruptedException,
                           KeeperException
        Description copied from class: ZooKeeper
        Delete the node with the given path. The call will succeed if such a node exists, and the given version matches the node's version (if the given version is -1, it matches any node's versions).

        A KeeperException with error code KeeperException.NoNode will be thrown if the nodes does not exist.

        A KeeperException with error code KeeperException.BadVersion will be thrown if the given version does not match the node's version.

        A KeeperException with error code KeeperException.NotEmpty will be thrown if the node has children.

        This operation, if successful, will trigger all the watches on the node of the given path left by exists API calls, and the watches on the parent node left by getChildren API calls.

        Overrides:
        delete in class ZooKeeper
        Parameters:
        path - the path of the node to be deleted.
        version - the expected node version.
        Throws:
        java.lang.InterruptedException - IF the server transaction is interrupted
        KeeperException - If the server signals an error with a non-zero return code.
      • exists

        public Stat exists​(java.lang.String path,
                           boolean watch)
                    throws KeeperException,
                           java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Return the stat of the node of the given path. Return null if no such a node exists.

        If the watch is true and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that creates/delete the node or sets the data on the node.

        Overrides:
        exists in class ZooKeeper
        Parameters:
        path - the node path
        watch - whether need to watch this node
        Returns:
        the stat of the node of the given path; return null if no such a node exists.
        Throws:
        KeeperException - If the server signals an error
        java.lang.InterruptedException - If the server transaction is interrupted.
      • exists

        public Stat exists​(java.lang.String path,
                           Watcher watcher)
                    throws KeeperException,
                           java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Return the stat of the node of the given path. Return null if no such a node exists.

        If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that creates/delete the node or sets the data on the node.

        Overrides:
        exists in class ZooKeeper
        Parameters:
        path - the node path
        watcher - explicit watcher
        Returns:
        the stat of the node of the given path; return null if no such a node exists.
        Throws:
        KeeperException - If the server signals an error
        java.lang.InterruptedException - If the server transaction is interrupted.
      • getACL

        public java.util.List<ACL> getACL​(java.lang.String path,
                                          Stat stat)
                                   throws KeeperException,
                                          java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Return the ACL and stat of the node of the given path.

        A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.

        Overrides:
        getACL in class ZooKeeper
        Parameters:
        path - the given path for the node
        stat - the stat of the node will be copied to this parameter if not null.
        Returns:
        the ACL array of the given node.
        Throws:
        KeeperException - If the server signals an error with a non-zero error code.
        java.lang.InterruptedException - If the server transaction is interrupted.
      • getChildren

        public java.util.List<java.lang.String> getChildren​(java.lang.String path,
                                                            boolean watch)
                                                     throws KeeperException,
                                                            java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Return the list of the children of the node of the given path.

        If the watch is true and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that deletes the node of the given path or creates/delete a child under the node.

        The list of children returned is not sorted and no guarantee is provided as to its natural or lexical order.

        A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.

        Overrides:
        getChildren in class ZooKeeper
        Parameters:
        path - the node path
        watch - whether need to watch this node
        Returns:
        an unordered array of children of the node with the given path
        Throws:
        KeeperException - If the server signals an error with a non-zero error code.
        java.lang.InterruptedException - If the server transaction is interrupted.
      • getChildren

        public java.util.List<java.lang.String> getChildren​(java.lang.String path,
                                                            Watcher watcher)
                                                     throws KeeperException,
                                                            java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Return the list of the children of the node of the given path.

        If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that deletes the node of the given path or creates/delete a child under the node.

        The list of children returned is not sorted and no guarantee is provided as to its natural or lexical order.

        A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.

        Overrides:
        getChildren in class ZooKeeper
        watcher - explicit watcher
        Returns:
        an unordered array of children of the node with the given path
        Throws:
        KeeperException - If the server signals an error with a non-zero error code.
        java.lang.InterruptedException - If the server transaction is interrupted.
      • getData

        public byte[] getData​(java.lang.String path,
                              boolean watch,
                              Stat stat)
                       throws KeeperException,
                              java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Return the data and the stat of the node of the given path.

        If the watch is true and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that sets data on the node, or deletes the node.

        A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.

        Overrides:
        getData in class ZooKeeper
        Parameters:
        path - the given path
        watch - whether need to watch this node
        stat - the stat of the node
        Returns:
        the data of the node
        Throws:
        KeeperException - If the server signals an error with a non-zero error code
        java.lang.InterruptedException - If the server transaction is interrupted.
      • getData

        public byte[] getData​(java.lang.String path,
                              Watcher watcher,
                              Stat stat)
                       throws KeeperException,
                              java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Return the data and the stat of the node of the given path.

        If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that sets data on the node, or deletes the node.

        A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.

        Overrides:
        getData in class ZooKeeper
        Parameters:
        path - the given path
        watcher - explicit watcher
        stat - the stat of the node
        Returns:
        the data of the node
        Throws:
        KeeperException - If the server signals an error with a non-zero error code
        java.lang.InterruptedException - If the server transaction is interrupted.
      • setACL

        public Stat setACL​(java.lang.String path,
                           java.util.List<ACL> acl,
                           int aclVersion)
                    throws KeeperException,
                           java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Set the ACL for the node of the given path if such a node exists and the given aclVersion matches the acl version of the node. Return the stat of the node.

        A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.

        A KeeperException with error code KeeperException.BadVersion will be thrown if the given aclVersion does not match the node's aclVersion.

        Overrides:
        setACL in class ZooKeeper
        Parameters:
        path - the given path for the node
        acl - the given acl for the node
        aclVersion - the given acl version of the node
        Returns:
        the stat of the node.
        Throws:
        KeeperException - If the server signals an error with a non-zero error code.
        KeeperException.InvalidACLException - If the acl is invalide.
        java.lang.InterruptedException - If the server transaction is interrupted.
      • setData

        public Stat setData​(java.lang.String path,
                            byte[] data,
                            int version)
                     throws KeeperException,
                            java.lang.InterruptedException
        Description copied from class: ZooKeeper
        Set the data for the node of the given path if such a node exists and the given version matches the version of the node (if the given version is -1, it matches any node's versions). Return the stat of the node.

        This operation, if successful, will trigger all the watches on the node of the given path left by getData calls.

        A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.

        A KeeperException with error code KeeperException.BadVersion will be thrown if the given version does not match the node's version.

        The maximum allowable size of the data array is 1 MB (1,048,576 bytes). Arrays larger than this will cause a KeeperException to be thrown.

        Overrides:
        setData in class ZooKeeper
        Parameters:
        path - the path of the node
        data - the data to set
        version - the expected matching version
        Returns:
        the state of the node
        Throws:
        KeeperException - If the server signals an error with a non-zero error code.
        java.lang.InterruptedException - If the server transaction is interrupted.
      • setRetryLimit

        public void setRetryLimit​(int limit)
        Parameters:
        limit -
      • testConnection

        public boolean testConnection()
        Returns:
        true if successfully connected to zookeeper