Package ru.yandex.clickhouse
Class BalancedClickhouseDataSource
- java.lang.Object
-
- ru.yandex.clickhouse.BalancedClickhouseDataSource
-
- All Implemented Interfaces:
Wrapper,CommonDataSource,DataSource
public class BalancedClickhouseDataSource extends Object implements DataSource
Database for clickhouse jdbc connections.
It has list of database urls. For every
getConnectioninvocation, it returns connection to random host from the list. Furthermore, this class has methodscheduleActualizationwhich test hosts for availability. By default, this option is turned off.
-
-
Constructor Summary
Constructors Constructor Description BalancedClickhouseDataSource(String url)create Datasource for clickhouse JDBC connectionsBalancedClickhouseDataSource(String url, Properties properties)create Datasource for clickhouse JDBC connectionsBalancedClickhouseDataSource(String url, ClickHouseProperties properties)create Datasource for clickhouse JDBC connections
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intactualize()Checks if clickhouse on url is alive, if it isn't, disable url, else enable.List<String>getAllClickhouseUrls()ClickHouseConnectiongetConnection()ClickHouseConnectiongetConnection(String username, String password)List<String>getDisabledUrls()List<String>getEnabledClickHouseUrls()intgetLoginTimeout()PrintWritergetLogWriter()LoggergetParentLogger()ClickHousePropertiesgetProperties()booleanhasDisabledUrls()booleanisWrapperFor(Class<?> iface)BalancedClickhouseDataSourcescheduleActualization(int delay, TimeUnit timeUnit)set time period for checking availability connectionsvoidsetLoginTimeout(int seconds)voidsetLogWriter(PrintWriter printWriter)<T> Tunwrap(Class<T> iface)BalancedClickhouseDataSourcewithConnectionsCleaning(int rate, TimeUnit timeUnit)set time period of removing connections-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
-
-
-
Constructor Detail
-
BalancedClickhouseDataSource
public BalancedClickhouseDataSource(String url)
create Datasource for clickhouse JDBC connections- Parameters:
url- address for connection to the database must have the next formatjdbc:clickhouse://<first-host>:<port>,<second-host>:<port>/<database>?param1=value1¶m2=value2for example,jdbc:clickhouse://localhost:8123,localhost:8123/database?compress=1&decompress=2- Throws:
IllegalArgumentException- if param have not correct format, or error happens when checking host availability
-
BalancedClickhouseDataSource
public BalancedClickhouseDataSource(String url, Properties properties)
create Datasource for clickhouse JDBC connections- Parameters:
url- address for connection to the databaseproperties- database properties- See Also:
BalancedClickhouseDataSource(String)
-
BalancedClickhouseDataSource
public BalancedClickhouseDataSource(String url, ClickHouseProperties properties)
create Datasource for clickhouse JDBC connections- Parameters:
url- address for connection to the databaseproperties- database properties- See Also:
BalancedClickhouseDataSource(String)
-
-
Method Detail
-
actualize
public int actualize()
Checks if clickhouse on url is alive, if it isn't, disable url, else enable.- Returns:
- number of avaliable clickhouse urls
-
getConnection
public ClickHouseConnection getConnection() throws SQLException
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getConnection
public ClickHouseConnection getConnection(String username, String password) throws SQLException
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
getLogWriter
public PrintWriter getLogWriter() throws SQLException
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Throws:
SQLException
-
setLogWriter
public void setLogWriter(PrintWriter printWriter) throws SQLException
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Throws:
SQLException
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws SQLException- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getLoginTimeout
public int getLoginTimeout() throws SQLException- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getParentLogger
public Logger getParentLogger() throws SQLFeatureNotSupportedException
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
withConnectionsCleaning
public BalancedClickhouseDataSource withConnectionsCleaning(int rate, TimeUnit timeUnit)
set time period of removing connections- Parameters:
rate- value for time unittimeUnit- time unit for checking- Returns:
- this datasource with changed settings
- See Also:
ClickHouseDriver.scheduleConnectionsCleaning(int, java.util.concurrent.TimeUnit)
-
scheduleActualization
public BalancedClickhouseDataSource scheduleActualization(int delay, TimeUnit timeUnit)
set time period for checking availability connections- Parameters:
delay- value for time unittimeUnit- time unit for checking- Returns:
- this datasource with changed settings
-
hasDisabledUrls
public boolean hasDisabledUrls()
-
getProperties
public ClickHouseProperties getProperties()
-
-