Package com.clickhouse.client
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 suitableClickHouseClientaccording to preferred protocol(s); and 2) pick suitableClickHouseNodeto connect to.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ClickHouseNodeSelectorEMPTYEmpty node selector matches all clients and nodes.
-
Constructor Summary
Constructors Modifier Constructor Description protectedClickHouseNodeSelector(Collection<ClickHouseProtocol> protocols, Collection<String> tags)Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)List<ClickHouseProtocol>getPreferredProtocols()Gets preferred protocols.Set<String>getPreferredTags()Gets preferred tags.inthashCode()booleanmatch(ClickHouseClient client)Test if the given client supports any ofgetPreferredProtocols().booleanmatch(ClickHouseNode node)Checks if the given node matches any of preferred protocols and tags.booleanmatchAllPreferredTags(Collection<String> tags)Checks if the preferred tags contain all of given tags.booleanmatchAnyOfPreferredProtocols(ClickHouseProtocol protocol)Checks if the given protocol matches any of the preferred protocols.booleanmatchAnyOfPreferredTags(Collection<String> tags)Checks if the preferred tags contain any of given tags.static ClickHouseNodeSelectorof(ClickHouseProtocol protocol, ClickHouseProtocol... more)Creates a node selector by specifying preferred protocols.static ClickHouseNodeSelectorof(String tag, String... more)Creates a node selector by specifying preferred tags.static ClickHouseNodeSelectorof(Collection<ClickHouseProtocol> protocols, Collection<String> tags)Creates a node selector by specifying preferred protocols and tags.StringtoString()
-
-
-
Field Detail
-
EMPTY
public static final ClickHouseNodeSelector EMPTY
Empty node selector matches all clients and nodes.
-
-
Constructor Detail
-
ClickHouseNodeSelector
protected ClickHouseNodeSelector(Collection<ClickHouseProtocol> protocols, Collection<String> tags)
Default constructor.- Parameters:
protocols- preferred protocolstags- preferred tags
-
-
Method Detail
-
of
public static ClickHouseNodeSelector of(ClickHouseProtocol protocol, ClickHouseProtocol... more)
Creates a node selector by specifying preferred protocols.- Parameters:
protocol- preferred protocolmore- 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 tagmore- 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 protocolstags- 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 ofgetPreferredProtocols(). It's alwaysfalseif 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
-
-