@@ -52,6 +52,8 @@ public class ObDirectLoadConnection {
5252 private long heartBeatTimeout = 0 ;
5353 private long heartBeatInterval = 0 ;
5454
55+ private long connectTimeout = 0 ;
56+
5557 private boolean isInited = false ;
5658 private boolean isClosed = false ;
5759
@@ -137,6 +139,8 @@ private void fillParams(Builder builder) throws ObDirectLoadException {
137139 heartBeatInterval = builder .heartBeatInterval ;
138140
139141 writeConnectionNum = builder .writeConnectionNum ;
142+
143+ connectTimeout = builder .connectTimeout ;
140144 }
141145
142146 private void initCheck () throws ObDirectLoadException {
@@ -167,6 +171,7 @@ private void initCheck() throws ObDirectLoadException {
167171 "Param 'heartBeatInterval' must not be greater than or equal to Param 'heartBeatTimeout', heartBeatTimeout:"
168172 + heartBeatTimeout + ", heartBeatInterval:" + heartBeatInterval );
169173 }
174+ ObDirectLoadUtil .checkPositive (connectTimeout , "connectTimeout" , logger );
170175 }
171176
172177 private void initProtocol () throws ObDirectLoadException {
@@ -178,6 +183,8 @@ private void initProtocol() throws ObDirectLoadException {
178183 Properties properties = new Properties ();
179184 properties .setProperty (Property .SERVER_CONNECTION_POOL_SIZE .getKey (),
180185 String .valueOf (1 ));
186+ properties .setProperty (Property .RPC_CONNECT_TIMEOUT .getKey (),
187+ String .valueOf (connectTimeout ));
181188 table = new ObTable .Builder (ip , port )
182189 .setLoginInfo (tenantName , userName , password , databaseName )
183190 .setProperties (properties ).build ();
@@ -276,6 +283,8 @@ public static final class Builder {
276283
277284 private static final long MAX_HEART_BEAT_TIMEOUT = 1L * 365 * 24 * 3600 * 1000 ; // 1year
278285
286+ private long connectTimeout = 1000 ;
287+
279288 Builder (ObDirectLoadConnectionFactory connectionFactory ) {
280289 this .connectionFactory = connectionFactory ;
281290 }
@@ -306,12 +315,17 @@ public Builder setHeartBeatInfo(long heartBeatTimeout, long heartBeatInterval) {
306315 return this ;
307316 }
308317
318+ public Builder setConnectTimeout (long connectTimeout ) {
319+ this .connectTimeout = Math .min (connectTimeout , (long ) Integer .MAX_VALUE );
320+ return this ;
321+ }
322+
309323 public String toString () {
310324 return String
311325 .format (
312- "{ip:\" %s\" , port:%d, tenantName:\" %s\" , userName:\" %s\" , databaseName:\" %s\" , writeConnectionNum:%d, heartBeatTimeout:%d, heartBeatInterval:%d}" ,
326+ "{ip:\" %s\" , port:%d, tenantName:\" %s\" , userName:\" %s\" , databaseName:\" %s\" , writeConnectionNum:%d, heartBeatTimeout:%d, heartBeatInterval:%d, connectTimeout:%d }" ,
313327 ip , port , tenantName , userName , databaseName , writeConnectionNum ,
314- heartBeatTimeout , heartBeatInterval );
328+ heartBeatTimeout , heartBeatInterval , connectTimeout );
315329 }
316330
317331 public ObDirectLoadConnection build () throws ObDirectLoadException {
@@ -370,6 +384,8 @@ private void initTables() throws ObDirectLoadException {
370384 Properties properties = new Properties ();
371385 properties
372386 .setProperty (Property .SERVER_CONNECTION_POOL_SIZE .getKey (), String .valueOf (1 ));
387+ properties .setProperty (Property .RPC_CONNECT_TIMEOUT .getKey (),
388+ String .valueOf (connection .connectTimeout ));
373389 properties .setProperty (Property .RPC_EXECUTE_TIMEOUT .getKey (),
374390 String .valueOf (timeoutMillis ));
375391 properties .setProperty (Property .RPC_OPERATION_TIMEOUT .getKey (),
0 commit comments