55
66import java .io .InputStream ;
77import java .net .SocketException ;
8+ import java .time .Duration ;
9+ import java .time .temporal .ChronoUnit ;
810import java .util .*;
911import com .clickhouse .client .api .metadata .TableSchema ;
1012import com .clickhouse .client .api .internal .TableSchemaParser ;
1517import java .util .concurrent .CompletableFuture ;
1618import java .util .concurrent .Future ;
1719
20+ import static java .time .temporal .ChronoUnit .SECONDS ;
21+
1822public 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