Class ZKNaming


  • public class ZKNaming
    extends Object
    This class defines simple methods to bind service names to URI addresses: list, lookup, unbind, bind, rebind.
    Author:
    Rui Claro
    • Constructor Detail

      • ZKNaming

        public ZKNaming​(String zkUrl)
        Parameters:
        zkUrl - ZooKeeper url in format host:port
      • ZKNaming

        public ZKNaming​(String host,
                        String port)
        Parameters:
        host - ZooKeeper host
        port - ZooKeeper port
    • Method Detail

      • bind

        public void bind​(ZKRecord record)
                  throws ZKNamingException
        Binds the specified record containing a path and a URI pair
        Parameters:
        record - record to register
        Throws:
        ZKNamingException - If bind fails
      • bind

        public void bind​(String path,
                         String host,
                         String port)
                  throws ZKNamingException
        Binds the specified path with a host port pair
        Parameters:
        path - Path to the zNode
        host - service host
        port - service port
        Throws:
        ZKNamingException - If bind fails
      • rebind

        public void rebind​(ZKRecord record)
                    throws ZKNamingException
        Rebinds the specified record. Existing record is overridden.
        Parameters:
        record - record to register
        Throws:
        ZKNamingException - If rebind fails
      • rebind

        public void rebind​(String path,
                           String URI)
                    throws ZKNamingException
        Rebinds the specified path with a URI
        Parameters:
        path - Path to the zNode
        URI - URI in the format host:port
        Throws:
        ZKNamingException - If rebind fails
      • rebind

        public void rebind​(String path,
                           String host,
                           String port)
                    throws ZKNamingException
        Rebinds the specified path with a host port pair
        Parameters:
        path - Path to the zNode
        host - service host
        port - service port
        Throws:
        ZKNamingException - If rebind fails
      • unbind

        public void unbind​(String path,
                           String URI)
                    throws ZKNamingException
        Destroys the binding for the specified path with a URI.
        Parameters:
        path - Path to the zNode
        URI - URI in the format host:port
        Throws:
        ZKNamingException - if unbind fails
      • unbind

        public void unbind​(String path,
                           String host,
                           String port)
                    throws ZKNamingException
        Destroys the binding for the specified path with a host port pair.
        Parameters:
        path - Path to the zNode
        host - service host
        port - service port
        Throws:
        ZKNamingException - If unbind fails
      • lookup

        public ZKRecord lookup​(String path)
                        throws ZKNamingException
        Returns the record associated with the specified path.
        Parameters:
        path - Path to the zNode
        Returns:
        Record object with associated path and URI
        Throws:
        ZKNamingException - if lookup fails
      • listRecords

        public Collection<ZKRecord> listRecords​(String path)
                                         throws ZKNamingException
        Returns a collection of records representing the child nodes of a zNode.
        Parameters:
        path - Path to the parent zNode
        Returns:
        Collection of record matching the children of provided zNode
        Throws:
        ZKNamingException - if listRecords fails