Class ZooKeeperAdmin

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    @Public
    public class ZooKeeperAdmin
    extends ZooKeeper
    This is the main class for ZooKeeperAdmin client library. This library is used to perform cluster administration tasks, such as reconfigure cluster membership. The ZooKeeperAdmin class inherits ZooKeeper and has similar usage pattern as ZooKeeper class. Please check ZooKeeper class document for more details.
    Since:
    3.5.3
    • Constructor Detail

      • ZooKeeperAdmin

        public ZooKeeperAdmin​(java.lang.String connectString,
                              int sessionTimeout,
                              Watcher watcher)
                       throws java.io.IOException
        Create a ZooKeeperAdmin object which is used to perform dynamic reconfiguration operations.
        Parameters:
        connectString - comma separated host:port pairs, each corresponding to a zk server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If the optional chroot suffix is used the example would look like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" where the client would be rooted at "/app/a" and all paths would be relative to this root - ie getting/setting/etc... "/foo/bar" would result in operations being run on "/app/a/foo/bar" (from the server perspective).
        sessionTimeout - session timeout in milliseconds
        watcher - a watcher object which will be notified of state changes, may also be notified for node events
        Throws:
        java.io.IOException - in cases of network failure
        java.lang.IllegalArgumentException - if an invalid chroot path is specified
        See Also:
        ZooKeeper(String, int, Watcher)
      • ZooKeeperAdmin

        public ZooKeeperAdmin​(java.lang.String connectString,
                              int sessionTimeout,
                              Watcher watcher,
                              ZKClientConfig conf)
                       throws java.io.IOException
        Create a ZooKeeperAdmin object which is used to perform dynamic reconfiguration operations.
        Parameters:
        connectString - comma separated host:port pairs, each corresponding to a zk server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If the optional chroot suffix is used the example would look like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" where the client would be rooted at "/app/a" and all paths would be relative to this root - ie getting/setting/etc... "/foo/bar" would result in operations being run on "/app/a/foo/bar" (from the server perspective).
        sessionTimeout - session timeout in milliseconds
        watcher - a watcher object which will be notified of state changes, may also be notified for node events
        conf - passing this conf object gives each client the flexibility of configuring properties differently compared to other instances
        Throws:
        java.io.IOException - in cases of network failure
        java.lang.IllegalArgumentException - if an invalid chroot path is specified
        See Also:
        ZooKeeper(String, int, Watcher, ZKClientConfig)
      • ZooKeeperAdmin

        public ZooKeeperAdmin​(java.lang.String connectString,
                              int sessionTimeout,
                              Watcher watcher,
                              boolean canBeReadOnly,
                              ZKClientConfig conf)
                       throws java.io.IOException
        Create a ZooKeeperAdmin object which is used to perform dynamic reconfiguration operations.
        Parameters:
        connectString - comma separated host:port pairs, each corresponding to a zk server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If the optional chroot suffix is used the example would look like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" where the client would be rooted at "/app/a" and all paths would be relative to this root - ie getting/setting/etc... "/foo/bar" would result in operations being run on "/app/a/foo/bar" (from the server perspective).
        sessionTimeout - session timeout in milliseconds
        watcher - a watcher object which will be notified of state changes, may also be notified for node events
        canBeReadOnly - whether the created client is allowed to go to read-only mode in case of partitioning. Read-only mode basically means that if the client can't find any majority servers but there's partitioned server it could reach, it connects to one in read-only mode, i.e. read requests are allowed while write requests are not. It continues seeking for majority in the background.
        conf - passing this conf object gives each client the flexibility of configuring properties differently compared to other instances
        Throws:
        java.io.IOException - in cases of network failure
        java.lang.IllegalArgumentException - if an invalid chroot path is specified
        Since:
        3.6.1
        See Also:
        ZooKeeper(String, int, Watcher, boolean, ZKClientConfig)
      • ZooKeeperAdmin

        public ZooKeeperAdmin​(java.lang.String connectString,
                              int sessionTimeout,
                              Watcher watcher,
                              boolean canBeReadOnly)
                       throws java.io.IOException
        Create a ZooKeeperAdmin object which is used to perform dynamic reconfiguration operations.
        Parameters:
        connectString - comma separated host:port pairs, each corresponding to a zk server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If the optional chroot suffix is used the example would look like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a" where the client would be rooted at "/app/a" and all paths would be relative to this root - ie getting/setting/etc... "/foo/bar" would result in operations being run on "/app/a/foo/bar" (from the server perspective).
        sessionTimeout - session timeout in milliseconds
        watcher - a watcher object which will be notified of state changes, may also be notified for node events
        canBeReadOnly - whether the created client is allowed to go to read-only mode in case of partitioning. Read-only mode basically means that if the client can't find any majority servers but there's partitioned server it could reach, it connects to one in read-only mode, i.e. read requests are allowed while write requests are not. It continues seeking for majority in the background.
        Throws:
        java.io.IOException - in cases of network failure
        java.lang.IllegalArgumentException - if an invalid chroot path is specified
        See Also:
        ZooKeeper(String, int, Watcher, boolean)
    • Method Detail

      • reconfigure

        public byte[] reconfigure​(java.lang.String joiningServers,
                                  java.lang.String leavingServers,
                                  java.lang.String newMembers,
                                  long fromConfig,
                                  Stat stat)
                           throws KeeperException,
                                  java.lang.InterruptedException
        Reconfigure - add/remove servers. Return the new configuration.
        Parameters:
        joiningServers - a comma separated list of servers being added (incremental reconfiguration)
        leavingServers - a comma separated list of servers being removed (incremental reconfiguration)
        newMembers - a comma separated list of new membership (non-incremental reconfiguration)
        fromConfig - version of the current configuration (optional - causes reconfiguration to throw an exception if configuration is no longer current)
        stat - the stat of /zookeeper/config znode will be copied to this parameter if not null.
        Returns:
        new configuration
        Throws:
        java.lang.InterruptedException - If the server transaction is interrupted.
        KeeperException - If the server signals an error with a non-zero error code.
      • toString

        public java.lang.String toString()
        String representation of this ZooKeeperAdmin client. Suitable for things like logging. Do NOT count on the format of this string, it may change without warning.
        Overrides:
        toString in class ZooKeeper
        Since:
        3.5.3