接口 EtcdClient

    • 方法详细资料

      • create

        void create​(String path)
        save the specified path to the etcd registry.
        参数:
        path - the path to be saved
      • createEphemeral

        long createEphemeral​(String path)
        save the specified path to the etcd registry. if node disconnect from etcd, it will be deleted automatically by etcd when session timeout.
        参数:
        path - the path to be saved
        返回:
        the lease of current path.
      • delete

        void delete​(String path)
        remove the specified from etcd registry.
        参数:
        path - the path to be removed
      • getChildren

        List<String> getChildren​(String path)
        find direct children directory, excluding path self, Never return null.
        参数:
        path - the path to be found direct children.
        返回:
        direct children directory, contains zero element list if children directory not exists.
      • addChildListener

        List<String> addChildListener​(String path,
                                      ChildListener listener)
        register children listener for specified path.
        参数:
        path - the path to be watched when children is added, delete or update.
        listener - when children is changed , listener will be triggered.
        返回:
        direct children directory, contains zero element list if children directory not exists.
      • getChildListener

        <T> T getChildListener​(String path,
                               ChildListener listener)
        find watcher of the children listener for specified path.
        参数:
        path - the path to be watched when children is added, delete or update.
        listener - when children is changed , listener will be triggered.
        返回:
        watcher if find else null
      • removeChildListener

        void removeChildListener​(String path,
                                 ChildListener listener)
        unregister children lister for specified path.
        参数:
        path - the path to be unwatched .
        listener - when children is changed , lister will be triggered.
      • addStateListener

        void addStateListener​(StateListener listener)
        support connection notify if connection state was changed.
        参数:
        listener - if state changed, listener will be triggered.
      • removeStateListener

        void removeStateListener​(StateListener listener)
        remove connection notify if connection state was changed.
        参数:
        listener - remove already registered listener, if listener not exists nothing happened.
      • isConnected

        boolean isConnected()
        test if current client is active.
        返回:
        true if connection is active else false.
      • close

        void close()
        close current client and release all resourses.
      • getUrl

        URL getUrl()
      • createLease

        long createLease​(long second)
        create new lease from specified second ,it should be waiting if failed.

        参数:
        second - lease time (support second only).
        返回:
        lease id from etcd
      • revokeLease

        void revokeLease​(long lease)
        revoke specified lease, any associated path will removed automatically.
        参数:
        lease - to be removed lease
      • getKVValue

        String getKVValue​(String key)
        Get the value of the specified key.
        参数:
        key - the specified key
        返回:
        null if the value is not found
      • put

        boolean put​(String key,
                    String value)
        Put the key value pair to etcd
        参数:
        key - the specified key
        value - the paired value
        返回:
        true if put success
      • putEphemeral

        boolean putEphemeral​(String key,
                             String value)
        Put the key value pair to etcd (Ephemeral)
        参数:
        key - the specified key
        value - the paired value
        返回:
        true if put success