public class BalancedClickhouseDataSource extends Object implements DataSource
Database for clickhouse jdbc connections.
It has list of database urls.
For every getConnection invocation, it returns connection to random host from the list.
Furthermore, this class has method scheduleActualization
which test hosts for availability. By default, this option is turned off.
| Constructor and Description |
|---|
BalancedClickhouseDataSource(String url)
create Datasource for clickhouse JDBC connections
|
BalancedClickhouseDataSource(String url,
ClickHouseProperties properties)
create Datasource for clickhouse JDBC connections
|
BalancedClickhouseDataSource(String url,
Properties properties)
create Datasource for clickhouse JDBC connections
|
| Modifier and Type | Method and Description |
|---|---|
int |
actualize()
Checks if clickhouse on url is alive, if it isn't, disable url, else enable.
|
List<String> |
getAllClickhouseUrls() |
ClickHouseConnection |
getConnection() |
ClickHouseConnection |
getConnection(String username,
String password) |
List<String> |
getDisabledUrls() |
List<String> |
getEnabledClickHouseUrls() |
int |
getLoginTimeout() |
PrintWriter |
getLogWriter() |
Logger |
getParentLogger() |
ClickHouseProperties |
getProperties() |
boolean |
hasDisabledUrls() |
boolean |
isWrapperFor(Class<?> iface) |
BalancedClickhouseDataSource |
scheduleActualization(int delay,
TimeUnit timeUnit)
set time period for checking availability connections
|
void |
setLoginTimeout(int seconds) |
void |
setLogWriter(PrintWriter printWriter) |
<T> T |
unwrap(Class<T> iface) |
BalancedClickhouseDataSource |
withConnectionsCleaning(int rate,
TimeUnit timeUnit)
set time period of removing connections
|
public BalancedClickhouseDataSource(String url)
url - address for connection to the database
must have the next format jdbc:clickhouse://<first-host>:<port>,<second-host>:<port>/<database>?param1=value1¶m2=value2
for example, jdbc:clickhouse://localhost:8123,localhost:8123/database?compress=1&decompress=2 IllegalArgumentException - if param have not correct format, or error happens when checking host availabilitypublic BalancedClickhouseDataSource(String url, Properties properties)
url - address for connection to the databaseproperties - database propertiesBalancedClickhouseDataSource(String)public BalancedClickhouseDataSource(String url, ClickHouseProperties properties)
url - address for connection to the databaseproperties - database propertiesBalancedClickhouseDataSource(String)public int actualize()
public ClickHouseConnection getConnection() throws SQLException
getConnection in interface DataSourceSQLExceptionpublic ClickHouseConnection getConnection(String username, String password) throws SQLException
getConnection in interface DataSourceSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic PrintWriter getLogWriter() throws SQLException
getLogWriter in interface CommonDataSourceSQLExceptionpublic void setLogWriter(PrintWriter printWriter) throws SQLException
setLogWriter in interface CommonDataSourceSQLExceptionpublic void setLoginTimeout(int seconds)
throws SQLException
setLoginTimeout in interface CommonDataSourceSQLExceptionpublic int getLoginTimeout()
throws SQLException
getLoginTimeout in interface CommonDataSourceSQLExceptionpublic Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger in interface CommonDataSourceSQLFeatureNotSupportedExceptionpublic BalancedClickhouseDataSource withConnectionsCleaning(int rate, TimeUnit timeUnit)
rate - value for time unittimeUnit - time unit for checkingClickHouseDriver.scheduleConnectionsCleaning(int, java.util.concurrent.TimeUnit)public BalancedClickhouseDataSource scheduleActualization(int delay, TimeUnit timeUnit)
delay - value for time unittimeUnit - time unit for checkingpublic boolean hasDisabledUrls()
public ClickHouseProperties getProperties()
Copyright © 2020. All rights reserved.