Skip to content

Commit cb6a298

Browse files
mzitnikmzitnik
andauthored
Connection settings new api (#1612)
* Added clickhouse-client test jar to test scope * Add connection settings methods * Remove method * Fix method name * Fix variable name --------- Co-authored-by: mzitnik <[email protected]>
1 parent b99cbd5 commit cb6a298

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

client-v2/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@
7676
<scope>compile</scope>
7777
</dependency>
7878

79+
<dependency>
80+
<groupId>${project.parent.groupId}</groupId>
81+
<artifactId>clickhouse-client</artifactId>
82+
<version>${revision}</version>
83+
<type>test-jar</type>
84+
<scope>test</scope>
85+
</dependency>
7986
<dependency>
8087
<groupId>org.slf4j</groupId>
8188
<artifactId>slf4j-simple</artifactId>

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import java.io.InputStream;
77
import java.net.SocketException;
8+
import java.time.Duration;
9+
import java.time.temporal.ChronoUnit;
810
import java.util.*;
911
import com.clickhouse.client.api.metadata.TableSchema;
1012
import com.clickhouse.client.api.internal.TableSchemaParser;
@@ -15,6 +17,8 @@
1517
import java.util.concurrent.CompletableFuture;
1618
import java.util.concurrent.Future;
1719

20+
import static java.time.temporal.ChronoUnit.SECONDS;
21+
1822
public class Client {
1923
public static final int TIMEOUT = 30_000;
2024
private Set<String> endpoints;
@@ -35,6 +39,11 @@ public static class Builder {
3539
public Builder() {
3640
this.endpoints = new HashSet<>();
3741
this.configuration = new HashMap<String, String>();
42+
// TODO: set defaults configuration values
43+
this.setConnectTimeout(30, SECONDS)
44+
.setSocketTimeout(2, SECONDS)
45+
.setSocketRcvbuf(804800)
46+
.setSocketSndbuf(804800);
3847
}
3948

4049
public Builder addEndpoint(String endpoint) {
@@ -63,7 +72,48 @@ public Builder addPassword(String password) {
6372
this.configuration.put("password", password);
6473
return this;
6574
}
75+
// SOCKET SETTINGS
76+
public Builder setConnectTimeout(long size) {
77+
this.configuration.put("connect_timeout", String.valueOf(size));
78+
return this;
79+
}
80+
public Builder setConnectTimeout(long amount, ChronoUnit unit) {
81+
this.setConnectTimeout(Duration.of(amount, unit).toMillis());
82+
return this;
83+
}
6684

85+
public Builder setSocketTimeout(long size) {
86+
this.configuration.put("socket_timeout", String.valueOf(size));
87+
return this;
88+
}
89+
public Builder setSocketTimeout(long amount, ChronoUnit unit) {
90+
this.setSocketTimeout(Duration.of(amount, unit).toMillis());
91+
return this;
92+
}
93+
public Builder setSocketRcvbuf(long size) {
94+
this.configuration.put("socket_rcvbuf", String.valueOf(size));
95+
return this;
96+
}
97+
public Builder setSocketSndbuf(long size) {
98+
this.configuration.put("socket_sndbuf", String.valueOf(size));
99+
return this;
100+
}
101+
public Builder setSocketReuseaddr(boolean value) {
102+
this.configuration.put("socket_reuseaddr", String.valueOf(value));
103+
return this;
104+
}
105+
public Builder setSocketKeepalive(boolean value) {
106+
this.configuration.put("socket_keepalive", String.valueOf(value));
107+
return this;
108+
}
109+
public Builder setSocketTcpNodelay(boolean value) {
110+
this.configuration.put("socket_tcp_nodelay", String.valueOf(value));
111+
return this;
112+
}
113+
public Builder setSocketLinger(int secondsToWait) {
114+
this.configuration.put("socket_linger", String.valueOf(secondsToWait));
115+
return this;
116+
}
67117
public Client build() {
68118
// check if endpoint are empty. so can not initiate client
69119
if (this.endpoints.isEmpty()) {

0 commit comments

Comments
 (0)