Class ClickHouseNode

java.lang.Object
com.clickhouse.client.ClickHouseNode
All Implemented Interfaces:
Serializable, Function<ClickHouseNodeSelector,ClickHouseNode>

public class ClickHouseNode extends Object implements Function<ClickHouseNodeSelector,ClickHouseNode>, Serializable
This class depicts a ClickHouse server, essentially a combination of host, port and protocol, for client to connect.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • builder

      public static ClickHouseNode.Builder builder()
      Gets builder for creating a new node, same as builder(null).
      Returns:
      builder for creating a new node
    • builder

      public static ClickHouseNode.Builder builder(ClickHouseNode base)
      Gets builder for creating a new node based on the given one.
      Parameters:
      base - template to start with
      Returns:
      builder for creating a new node
    • of

      public static ClickHouseNode of(String host, ClickHouseProtocol protocol, int port, String database, String... tags)
      Creates a node object in one go. Short version of ClickHouseNode.builder().host(host).port(protocol, port).database(database).tags(tags).build().
      Parameters:
      host - host name, null means ClickHouseDefaults.HOST
      protocol - protocol, null means ClickHouseDefaults.PROTOCOL
      port - port number
      database - database name, null means ClickHouseDefaults.DATABASE
      tags - tags for the node, null tag will be ignored
      Returns:
      non-null node object
    • of

      public static ClickHouseNode of(String uri)
      Creates a node object using given URI. Same as of(uri, ClickHouseProtocol.ANY).
      Parameters:
      uri - non-empty URI
      Returns:
      non-null node object
    • of

      public static ClickHouseNode of(String uri, Map<?,?> options)
      Creates a node object using given URI. Same as of(uri, ClickHouseProtocol.ANY).
      Parameters:
      uri - non-empty URI
      options - default options
      Returns:
      non-null node object
    • of

      public static ClickHouseNode of(String uri, ClickHouseNode template)
      Creates a node object using given URI and template.
      Parameters:
      uri - non-empty URI
      template - optinal template used for creating the node
      Returns:
      non-null node object
    • of

      public static ClickHouseNode of(URI uri, ClickHouseNode template)
      Creates a node object using given URI.
      Parameters:
      uri - non-null URI which contains scheme(protocol), host and optionally port
      template - optinal template used for creating the node object
      Returns:
      non-null node object
    • probe

      protected ClickHouseNode probe()
    • setManager

      protected ClickHouseNode setManager(ClickHouseNodeManager m)
      Sets manager for this node.
      Parameters:
      m - node manager
      Returns:
      this node
    • getAddress

      public InetSocketAddress getAddress()
      Gets socket address to connect to this node.
      Returns:
      socket address to connect to the node
    • getBaseUri

      public String getBaseUri()
      Gets base URI which is composed of protocol, host and port.
      Returns:
      non-emtpy base URI
    • getConfig

      public ClickHouseConfig getConfig()
      Gets configuration.
      Returns:
      non-null configuration
    • getCredentials

      public Optional<ClickHouseCredentials> getCredentials()
      Gets credentials for accessing this node. Use ClickHouseConfig.getDefaultCredentials() if this is not present.
      Returns:
      credentials for accessing this node
    • getCredentials

      public ClickHouseCredentials getCredentials(ClickHouseConfig config)
      Gets credentials for accessing this node. It first attempts to use credentials tied to the node, and then use default credentials from the given configuration.
      Parameters:
      config - non-null configuration for retrieving default credentials
      Returns:
      credentials for accessing this node
    • getHost

      public String getHost()
      Gets host of the node.
      Returns:
      host of the node
    • getPort

      public int getPort()
      Gets port of the node.
      Returns:
      port of the node
    • getDatabase

      public Optional<String> getDatabase()
      Gets database of the node.
      Returns:
      database of the node
    • getDatabase

      public String getDatabase(ClickHouseConfig config)
      Gets database of the node. When hasPreferredDatabase() is false, it will use database from the given configuration.
      Parameters:
      config - non-null configuration to get default database
      Returns:
      database of the node
    • getOptions

      public Map<String,String> getOptions()
      Gets all options of the node.
      Returns:
      options of the node
    • getTags

      public Set<String> getTags()
      Gets all tags of the node.
      Returns:
      tags of the node
    • getWeight

      public int getWeight()
      Gets weight of the node.
      Returns:
      weight of the node
    • getTimeZone

      public Optional<TimeZone> getTimeZone()
      Gets time zone of the node.
      Returns:
      time zone of the node
    • getTimeZone

      public TimeZone getTimeZone(ClickHouseConfig config)
      Gets time zone of the node. When not defined, it will use server time zone from the given configuration.
      Parameters:
      config - non-null configuration to get server time zone
      Returns:
      time zone of the node
    • getVersion

      public Optional<ClickHouseVersion> getVersion()
      Gets version of the node.
      Returns:
      version of the node
    • getVersion

      public ClickHouseVersion getVersion(ClickHouseConfig config)
      Gets version of the node. When not defined, it will use server version from the given configuration.
      Parameters:
      config - non-null configuration to get server version
      Returns:
      version of the node
    • getCluster

      public String getCluster()
      Gets cluster name of the node.
      Returns:
      cluster name of node
    • getProtocol

      public ClickHouseProtocol getProtocol()
      Gets protocol used by the node.
      Returns:
      protocol used by the node
    • hasPreferredDatabase

      public boolean hasPreferredDatabase()
      Checks if preferred database was specified or not. When preferred database was not specified, getDatabase() will return default database.
      Returns:
      true if preferred database was specified; false otherwise
    • isManaged

      public boolean isManaged()
      Checks whether the node is managed by a ClickHouseCluster ro ClickHouseNodes.
      Returns:
      true if the node is managed; false otherwise
    • isStandalone

      public boolean isStandalone()
      Checks whether the node is not managed by any ClickHouseCluster ro ClickHouseNodes.
      Returns:
      true if the node is not managed; false otherwise
    • isSameEndpoint

      public boolean isSameEndpoint(ClickHouseNode node)
      Checks if the given node has same base URI as current one.
      Parameters:
      node - node to test
      Returns:
      true if the nodes are same endpoint; false otherwise
    • update

      public void update(ClickHouseNode.Status status)
      Updates status of the node. This will only work when the node is managed(isManaged() returns true).
      Parameters:
      status - non-null node status
    • apply

      Specified by:
      apply in interface Function<ClickHouseNodeSelector,ClickHouseNode>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toUri

      public URI toUri()
      Converts to URI, without credentials for security reason.
      Returns:
      non-null URI
    • toUri

      public URI toUri(String schemePrefix)
      Converts to URI, without credentials for security reason.
      Parameters:
      schemePrefix - optional prefix of scheme
      Returns:
      non-null URI