Class ClickHouseNodeSelector

java.lang.Object
com.clickhouse.client.ClickHouseNodeSelector
All Implemented Interfaces:
Serializable

public class ClickHouseNodeSelector extends Object implements Serializable
This class maintains two immutable collections: preferred protocols and tags. Usually it will be used in two scenarios: 1) find suitable ClickHouseClient according to preferred protocol(s); and 2) pick suitable ClickHouseNode to connect to.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • of

      public static ClickHouseNodeSelector of(ClickHouseProtocol protocol, ClickHouseProtocol... more)
      Creates a node selector by specifying preferred protocols.
      Parameters:
      protocol - preferred protocol
      more - more protocols
      Returns:
      non-null node selector
    • of

      public static ClickHouseNodeSelector of(String tag, String... more)
      Creates a node selector by specifying preferred tags.
      Parameters:
      tag - preferred tag
      more - more tags
      Returns:
      non-null selector
    • of

      public static ClickHouseNodeSelector of(Collection<ClickHouseProtocol> protocols, Collection<String> tags)
      Creates a node selector by specifying preferred protocols and tags.
      Parameters:
      protocols - preferred protocols
      tags - preferred tags
      Returns:
      non-null selector
    • getPreferredProtocols

      public List<ClickHouseProtocol> getPreferredProtocols()
      Gets preferred protocols. Empty list means all.
      Returns:
      non-null preferred protocols
    • getPreferredTags

      public Set<String> getPreferredTags()
      Gets preferred tags. Empty set means all.
      Returns:
      non-null preferred tags
    • match

      public boolean match(ClickHouseClient client)
      Test if the given client supports any of getPreferredProtocols(). It's always false if either the client is null or there's no preferred protocol.
      Parameters:
      client - client to test
      Returns:
      true if any of the preferred protocols is supported by the client
    • match

      public boolean match(ClickHouseNode node)
      Checks if the given node matches any of preferred protocols and tags.
      Parameters:
      node - node to check
      Returns:
      true if the node matches at least one of preferred protocols and tags; false otherwise
    • matchAnyOfPreferredProtocols

      public boolean matchAnyOfPreferredProtocols(ClickHouseProtocol protocol)
      Checks if the given protocol matches any of the preferred protocols.
      Parameters:
      protocol - protocol to check
      Returns:
      true if the protocol matches at least one of preferred protocols; false otherwise
    • matchAllPreferredTags

      public boolean matchAllPreferredTags(Collection<String> tags)
      Checks if the preferred tags contain all of given tags.
      Parameters:
      tags - tags to check
      Returns:
      true if the preferred tags contain all of given tags; false otherwise
    • matchAnyOfPreferredTags

      public boolean matchAnyOfPreferredTags(Collection<String> tags)
      Checks if the preferred tags contain any of given tags.
      Parameters:
      tags - tags to check
      Returns:
      true if the preferred tags contain any of given tags; false otherwise
    • 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