Class 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:
    Serialized Form
    • Field Detail

    • Constructor Detail

    • Method Detail

      • 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
      • 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 protocl 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