Package com.clickhouse.client.api
Class Client.Builder
java.lang.Object
com.clickhouse.client.api.Client.Builder
- Enclosing class:
- Client
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault size for a buffers used in networking.static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddEndpoint(Protocol protocol, String host, int port, boolean secure) Server address to which client may connect.addEndpoint(String endpoint) Server address to which client may connect.allowBinaryReaderToReuseBuffers(boolean reuse) Configures client to reuse allocated byte buffers for numbers.appCompressedData(boolean enabled) build()Sets column to method matching strategy.compressClientRequest(boolean enabled) Client request compression.compressServerResponse(boolean enabled) Server response compression.enableConnectionPool(boolean enable) Configures client to use build-in connection poolhttpHeader(String key, String value) Defines list of headers that should be sent with each request.httpHeader(String key, Collection<String> values) but for multiple values.httpHeaders(Map<String, String> headers) but for multiple headers.registerClientMetrics(Object registry, String name) Registers http client metrics with MeterRegistry.retryOnFailures(ClientFaultCause... causes) Sets list of causes that should be retried on.serverSetting(String name, String value) Defines list of server settings that should be sent with each request.serverSetting(String name, Collection<String> values) but for multiple values.setAccessToken(String accessToken) Access token for authentication with server.setClientCertificate(String path) Client certificate for mTLS.setClientKey(String path) Client key for mTLS.setClientName(String clientName) Sets additional information about calling application.setClientNetworkBufferSize(int size) Set size of a buffers that are used to read/write data from the server.setConnectionRequestTimeout(long timeout, ChronoUnit unit) Set timeout for waiting a free connection from a pool when all connections are leased.Sets strategy of how connections are reuse.setConnectionTTL(long timeout, ChronoUnit unit) Sets how long any connection would be considered as active and able for a lease.setConnectTimeout(long timeout) Default connection timeout in milliseconds.setConnectTimeout(long timeout, ChronoUnit unit) Default connection timeout in milliseconds.setDefaultDatabase(String database) Sets the default database name that will be used by operations if not specified.setExecutionTimeout(long timeout, ChronoUnit timeUnit) Sets the maximum time for operation to complete.setHttpCookiesEnabled(boolean enabled) setKeepAliveTimeout(long timeout, ChronoUnit unit) Sets keep alive timeout for a connection to override server value.setLZ4UncompressedBufferSize(int size) Sets buffer size for uncompressed data in LZ4 compression.setMaxConnections(int maxConnections) Sets the maximum number of connections that can be opened at the same time to a single server.setMaxRetries(int maxRetries) Sets a configuration option.setOptions(Map<String, String> options) Sets client options from provided map.setPassword(String password) Password for authentication with server.setProxyCredentials(String user, String pass) setRootCertificate(String path) Defines path to the key store file.setServerTimeZone(String timeZone) Specify server timezone to use.setSharedOperationExecutor(ExecutorService executorService) Sets an executor for running operations.setSocketKeepAlive(boolean value) Default socket keep alive option.If set to true socket will be kept alive until terminated by one of the parties.setSocketLinger(int secondsToWait) Default socket linger option.setSocketRcvbuf(long size) Default socket receive buffer size in bytes.setSocketReuseAddress(boolean value) Default socket reuse address option.setSocketSndbuf(long size) Default socket send buffer size in bytes.setSocketTcpNodelay(boolean value) Default socket tcp_no_delay option.setSocketTimeout(long timeout) Default socket timeout in milliseconds.setSocketTimeout(long timeout, ChronoUnit unit) Default socket timeout in milliseconds.setSSLTrustStore(String path) Defines path to the trust store file.setSSLTrustStorePassword(String password) Password for the SSL Trust Store.setSSLTrustStoreType(String type) Type of the SSL Trust Store.setUsername(String username) Username for authentication with server.useAsyncRequests(boolean async) Configures client to execute requests in a separate thread.useBearerTokenAuth(String bearerToken) Specifies whether to use Bearer Authentication and what token to use.useHTTPBasicAuth(boolean useBasicAuth) Whether to use HTTP basic authentication.useHttpCompression(boolean enabled) Configures the client to use HTTP compression.useNewImplementation(boolean useNewImplementation) Deprecated.useServerTimeZone(boolean useServerTimeZone) Configure client to use server timezone for date/datetime columns.useSSLAuthentication(boolean useSSLAuthentication) Makes client to use SSL Client Certificate to authenticate with server.useTimeZone(String timeZone) Configure client to use specified timezone.
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault size for a buffers used in networking.- See Also:
-
DEFAULT_SOCKET_BUFFER_SIZE
public static final int DEFAULT_SOCKET_BUFFER_SIZE- See Also:
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
addEndpoint
Server address to which client may connect. If there are multiple endpoints then client will connect to one of them. Acceptable formats are:http://localhost:8123https://localhost:8443
- Parameters:
endpoint- - URL formatted string with protocol, host and port.
-
addEndpoint
Server address to which client may connect. If there are multiple endpoints then client will connect to one of them.- Parameters:
protocol- - Endpoint protocolhost- - Endpoint hostport- - Endpoint port
-
setOption
Sets a configuration option. This method can be used to set any configuration option. There is no specific validation is done on the key or value.- Parameters:
key- - configuration option namevalue- - configuration option value
-
setUsername
Username for authentication with server. Required for all operations. Same username will be used for all endpoints.- Parameters:
username- - a valid username
-
setPassword
Password for authentication with server. Required for all operations. Same password will be used for all endpoints.- Parameters:
password- - plain text password
-
setAccessToken
Access token for authentication with server. Required for all operations. Same access token will be used for all endpoints.- Parameters:
accessToken- - plain text access token
-
useSSLAuthentication
Makes client to use SSL Client Certificate to authenticate with server. Client certificate should be set as well.setClientCertificate(String)- Parameters:
useSSLAuthentication-- Returns:
-
enableConnectionPool
Configures client to use build-in connection pool- Parameters:
enable- - if connection pool should be enabled- Returns:
-
setConnectTimeout
Default connection timeout in milliseconds. Timeout is applied to establish a connection.- Parameters:
timeout- - connection timeout in milliseconds
-
setConnectTimeout
Default connection timeout in milliseconds. Timeout is applied to establish a connection.- Parameters:
timeout- - connection timeout valueunit- - time unit
-
setConnectionRequestTimeout
Set timeout for waiting a free connection from a pool when all connections are leased. This configuration is important when need to fail fast in high concurrent scenarios. Default is 10 s.- Parameters:
timeout- - connection timeout in millisecondsunit- - time unit
-
setMaxConnections
Sets the maximum number of connections that can be opened at the same time to a single server. Limit is not a hard stop. It is done to prevent threads stuck inside a connection pool waiting for a connection. Default is 10. It is recommended to set a higher value for a high concurrent applications. It will let more threads to get a connection and execute a query.- Parameters:
maxConnections- - maximum number of connections
-
setConnectionTTL
Sets how long any connection would be considered as active and able for a lease. After this time connection will be marked for sweep and will not be returned from a pool. Has more effect than keep-alive timeout.- Parameters:
timeout- - time in unitunit- - time unit- Returns:
-
setKeepAliveTimeout
Sets keep alive timeout for a connection to override server value. If set to -1 then server value will be used. Default is -1. Doesn't override connection TTL value.- Parameters:
timeout- - time in unitunit- - time unit- Returns:
-
setConnectionReuseStrategy
Sets strategy of how connections are reuse. Default isConnectionReuseStrategy.FIFOto evenly distribute load between them.- Parameters:
strategy- - strategy for connection reuse- Returns:
-
setSocketTimeout
Default socket timeout in milliseconds. Timeout is applied to read and write operations.- Parameters:
timeout- - socket timeout in milliseconds
-
setSocketTimeout
Default socket timeout in milliseconds. Timeout is applied to read and write operations. Default is 0.- Parameters:
timeout- - socket timeout valueunit- - time unit
-
setSocketRcvbuf
Default socket receive buffer size in bytes.- Parameters:
size- - socket receive buffer size in bytes
-
setSocketSndbuf
Default socket send buffer size in bytes.- Parameters:
size- - socket send buffer size in bytes
-
setSocketReuseAddress
Default socket reuse address option.- Parameters:
value- - socket reuse address option
-
setSocketKeepAlive
Default socket keep alive option.If set to true socket will be kept alive until terminated by one of the parties.- Parameters:
value- - socket keep alive option
-
setSocketTcpNodelay
Default socket tcp_no_delay option. If set to true, disables Nagle's algorithm.- Parameters:
value- - socket tcp no delay option
-
setSocketLinger
Default socket linger option. If set to true, socket will linger for the specified time.- Parameters:
secondsToWait- - socket linger time in seconds
-
compressServerResponse
Server response compression. If set to true server will compress the response. Has most effect for read operations. Default is true.- Parameters:
enabled- - indicates if server response compression is enabled
-
compressClientRequest
Client request compression. If set to true client will compress the request. Has most effect for write operations. Default is false.- Parameters:
enabled- - indicates if client request compression is enabled
-
useHttpCompression
Configures the client to use HTTP compression. In this case compression is controlled by http headers. Client compression will setContent-Encoding: lz4header and server compression will setAccept-Encoding: lz4header. Default is false.- Parameters:
enabled- - indicates if http compression is enabled- Returns:
-
appCompressedData
-
setLZ4UncompressedBufferSize
Sets buffer size for uncompressed data in LZ4 compression. For outgoing data it is the size of a buffer that will be compressed. For incoming data it is the size of a buffer that will be decompressed.- Parameters:
size- - size of the buffer in bytes- Returns:
-
setDefaultDatabase
Sets the default database name that will be used by operations if not specified.- Parameters:
database- - actual default database name.
-
addProxy
-
setProxyCredentials
-
setExecutionTimeout
Sets the maximum time for operation to complete. By default, it is set to 3 hours.- Parameters:
timeout-timeUnit-- Returns:
-
useNewImplementation
Deprecated.Switches to new implementation of the client. Default is true. Throws exception ifuseNewImplementation == false -
setHttpCookiesEnabled
-
setSSLTrustStore
Defines path to the trust store file. It cannot be combined with certificates. Either trust store or certificates should be used. and- Parameters:
path-- Returns:
-
setSSLTrustStorePassword
Password for the SSL Trust Store.- Parameters:
password-- Returns:
-
setSSLTrustStoreType
Type of the SSL Trust Store. Usually JKS- Parameters:
type-- Returns:
-
setRootCertificate
Defines path to the key store file. It cannot be combined with certificates. Either key store or certificates should be used. and- Parameters:
path-- Returns:
-
setClientCertificate
Client certificate for mTLS.- Parameters:
path-- Returns:
-
setClientKey
Client key for mTLS.- Parameters:
path-- Returns:
-
useServerTimeZone
Configure client to use server timezone for date/datetime columns. Default is true. If this options is selected then server timezone should be set as well.- Parameters:
useServerTimeZone- - if to use server timezone- Returns:
-
useTimeZone
Configure client to use specified timezone. If set using server TimeZone should be set to false- Parameters:
timeZone-- Returns:
-
setServerTimeZone
Specify server timezone to use. If not set then UTC will be used.- Parameters:
timeZone- - server timezone- Returns:
-
useAsyncRequests
Configures client to execute requests in a separate thread. By default, operations (query, insert) are executed in the same thread as the caller. It is possible to set a shared executor for all operations. SeesetSharedOperationExecutor(ExecutorService)Note: Async operations a using executor what expects having a queue of tasks for a pool of executors. The queue size limit is small it may quickly become a problem for scheduling new tasks.- Parameters:
async- - if to use async requests- Returns:
-
setClientNetworkBufferSize
Set size of a buffers that are used to read/write data from the server. It is mainly used to copy data from a socket to application memory and visa-versa. Setting is applied for both read and write operations. Default is 300,000 bytes.- Parameters:
size- - size in bytes- Returns:
-
retryOnFailures
Sets list of causes that should be retried on. Default[NoHttpResponse, ConnectTimeout, ConnectionRequestTimeout]UseClientFaultCause.Noneto disable retries.- Parameters:
causes- - list of causes- Returns:
-
setMaxRetries
-
allowBinaryReaderToReuseBuffers
Configures client to reuse allocated byte buffers for numbers. It affects how binary format reader is working. If set to 'true' thenClient.newBinaryFormatReader(QueryResponse)will construct reader that will reuse buffers for numbers. It improves performance for large datasets by reducing number of allocations (therefore GC pressure). Enabling this feature is safe because each reader suppose to be used by a single thread and readers are not reused. Default is false.- Parameters:
reuse- - if to reuse buffers- Returns:
-
httpHeader
Defines list of headers that should be sent with each request. The Client will use a header value defined inheadersinstead of any other. Operation settings may override these headers.- Parameters:
key- - a name of the header.value- - a value of the header.- Returns:
- same instance of the builder
- See Also:
-
httpHeader
but for multiple values.- Parameters:
key- - name of the headervalues- - collection of values- Returns:
- same instance of the builder
-
httpHeaders
but for multiple headers.- Parameters:
headers- - map of headers- Returns:
- same instance of the builder
-
serverSetting
Defines list of server settings that should be sent with each request. The Client will use a setting value defined insettingsinstead of any other. Operation settings may override these values. -
serverSetting
but for multiple values.- Parameters:
name- - name of the setting without special prefixvalues- - collection of values- Returns:
- same instance of the builder
-
columnToMethodMatchingStrategy
Sets column to method matching strategy. It is used while registering POJO serializers and deserializers. Default isDefaultColumnToMethodMatchingStrategy.- Parameters:
strategy- - matching strategy- Returns:
- same instance of the builder
-
useHTTPBasicAuth
Whether to use HTTP basic authentication. Default value is true. Password that contain UTF8 characters may not be passed through http headers and BASIC authentication is the only option here.- Parameters:
useBasicAuth- - indicates if basic authentication should be used- Returns:
- same instance of the builder
-
setClientName
Sets additional information about calling application. This string will be passed to server as a client name. In case of HTTP protocol it will be passed as aUser-Agentheader. Warn: If custom value of User-Agent header is set it will override this value for HTTP transport Client name is used by server to identify client application when investigatingsystem.query_log. In case of HTTP transport this value will be in thesystem.query_log.http_user_agentcolumn. Currently only HTTP transport is used.- Parameters:
clientName- - client application display name.- Returns:
- same instance of the builder
-
setOptions
Sets client options from provided map. Values are copied as is- Parameters:
options- - map of client options- Returns:
- same instance of the builder
-
useBearerTokenAuth
Specifies whether to use Bearer Authentication and what token to use. The token will be sent as is, so it should be encoded before passing to this method.- Parameters:
bearerToken- - token to use- Returns:
- same instance of the builder
-
registerClientMetrics
Registers http client metrics with MeterRegistry.- Parameters:
registry- - metrics registryname- - name of metrics group- Returns:
- same instance of the builder
-
build
-