Package com.clickhouse.client
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClickHouseNode.BuilderMutable and non-thread safe builder.static classClickHouseNode.StatusNode status.
-
Constructor Summary
Constructors Modifier Constructor Description protectedClickHouseNode(ClickHouseNode.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClickHouseNodeapply(ClickHouseNodeSelector t)static ClickHouseNode.Builderbuilder()Gets builder for creating a new node, same asbuilder(null).static ClickHouseNode.Builderbuilder(ClickHouseNode base)Gets builder for creating a new node based on the given one.booleanequals(Object obj)InetSocketAddressgetAddress()Gets socket address to connect to this node.StringgetCluster()Gets cluster name of the node.Optional<ClickHouseCredentials>getCredentials()Gets credentials for accessing this node.ClickHouseCredentialsgetCredentials(ClickHouseConfig config)Gets credentials for accessing this node.Optional<String>getDatabase()Gets database of the node.StringgetDatabase(ClickHouseConfig config)Gets database of the node.StringgetHost()Gets host of the node.intgetPort()Gets port of the node.ClickHouseProtocolgetProtocol()Gets protocol used by the node.Set<String>getTags()Gets all tags of the node.Optional<TimeZone>getTimeZone()Gets time zone of the node.TimeZonegetTimeZone(ClickHouseConfig config)Gets time zone of the node.Optional<ClickHouseVersion>getVersion()Gets version of the node.ClickHouseVersiongetVersion(ClickHouseConfig config)Gets version of the node.intgetWeight()Gets weight of the node.inthashCode()booleanhasPreferredDatabase()Checks if preferred database was specified or not.static ClickHouseNodeof(String host, ClickHouseProtocol protocol, int port, String database, String... tags)Creates a node object in one go.voidsetManager(BiConsumer<ClickHouseNode,ClickHouseNode.Status> manager)Sets manager for this node.StringtoString()voidupdateStatus(ClickHouseNode.Status status)Updates status of the node.
-
-
-
Constructor Detail
-
ClickHouseNode
protected ClickHouseNode(ClickHouseNode.Builder builder)
-
-
Method Detail
-
builder
public static ClickHouseNode.Builder builder()
Gets builder for creating a new node, same asbuilder(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 ofClickHouseNode.builder().host(host).port(protocol, port).database(database).tags(tags).build().- Parameters:
host- host name, null meansClickHouseDefaults.HOSTprotocol- protocol, null meansClickHouseDefaults.PROTOCOLport- port numberdatabase- database name, null meansClickHouseDefaults.DATABASEtags- tags for the node, null tag will be ignored- Returns:
- node object
-
getAddress
public InetSocketAddress getAddress()
Gets socket address to connect to this node.- Returns:
- socket address to connect to the node
-
getCredentials
public Optional<ClickHouseCredentials> getCredentials()
Gets credentials for accessing this node. UseClickHouseConfig.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. WhenhasPreferredDatabase()isfalse, it will use database from the given configuration.- Parameters:
config- non-null configuration to get default database- Returns:
- database 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
-
setManager
public void setManager(BiConsumer<ClickHouseNode,ClickHouseNode.Status> manager)
Sets manager for this node.- Parameters:
manager- function to manage status of the node
-
updateStatus
public void updateStatus(ClickHouseNode.Status status)
Updates status of the node. This will only work when a manager function exists viasetManager(BiConsumer).- Parameters:
status- node status
-
apply
public ClickHouseNode apply(ClickHouseNodeSelector t)
- Specified by:
applyin interfaceFunction<ClickHouseNodeSelector,ClickHouseNode>
-
-