@@ -725,25 +725,25 @@ public boolean connect(String hostName, int port, String userId, String password
725
725
return connect (hostName , port , userId , password , initialScript , enableHighAvailability , highAvailabilitySites , reconnect , false );
726
726
}
727
727
728
- public boolean connect (String hostName , int port , String userId , String password , String initialScript , boolean enableHighAvailability , String [] highAvailabilitySites , boolean reconnect , boolean enableLoadBalance , int tryReconnectNums ) throws IOException {
729
- if (tryReconnectNums <= 0 ) {
730
- this .tryReconnectNums = -1 ;
731
- log .warn ("If the param 'tryReconnectNums' less than or equal to 0, when reconnect will be unlimited attempts." );
732
- } else {
733
- this .tryReconnectNums = tryReconnectNums ;
734
- }
735
-
736
- return connect (hostName , port , userId , password , initialScript , enableHighAvailability , highAvailabilitySites , reconnect , enableLoadBalance );
728
+ public boolean connect (String hostName , int port , String userId , String password , String initialScript , boolean enableHighAvailability , String [] highAvailabilitySites , boolean reconnect , boolean enableLoadBalance ) throws IOException {
729
+ return connect (hostName , port , userId , password , initialScript , enableHighAvailability , highAvailabilitySites , reconnect , enableLoadBalance , -1 );
737
730
}
738
731
739
- public boolean connect (String hostName , int port , String userId , String password , String initialScript , boolean enableHighAvailability , String [] highAvailabilitySites , boolean reconnect , boolean enableLoadBalance ) throws IOException {
732
+ public boolean connect (String hostName , int port , String userId , String password , String initialScript , boolean enableHighAvailability , String [] highAvailabilitySites , boolean reconnect , boolean enableLoadBalance , int tryReconnectNums ) throws IOException {
740
733
mutex_ .lock ();
741
734
try {
742
735
this .uid_ = userId ;
743
736
this .pwd_ = password ;
744
737
this .initialScript_ = initialScript ;
745
738
this .enableHighAvailability_ = enableHighAvailability ;
746
739
this .loadBalance_ = enableLoadBalance ;
740
+ if (tryReconnectNums <= 0 ) {
741
+ this .tryReconnectNums = -1 ;
742
+ log .warn ("If the param 'tryReconnectNums' less than or equal to 0, when reconnect will be unlimited attempts." );
743
+ } else {
744
+ this .tryReconnectNums = tryReconnectNums ;
745
+ }
746
+
747
747
if (this .loadBalance_ && !this .enableHighAvailability_ )
748
748
throw new RuntimeException ("Cannot only enable loadbalance but not enable highAvailablity." );
749
749
@@ -923,7 +923,7 @@ public void switchDataNode(Node node) throws IOException{
923
923
}
924
924
} while (!closed_ && (tryReconnectNums == -1 || attempt < tryReconnectNums ));
925
925
926
- if (!closed_ )
926
+ if (!closed_ && tryReconnectNums > 0 )
927
927
throw new RuntimeException ("Connect to " + node .hostName + ":" + node .port + " failed after " + attempt + " reconnect attemps." );
928
928
929
929
if (initialScript_ !=null && initialScript_ .length () > 0 ){
0 commit comments