public void reconnectFailedConnection ( SearchFilter searchFilter ) throws SQLException { if ( ! searchFilter . isInitialConnection ( ) && ( isExplicitClosed ( ) || ( searchFilter . isFineIfFoundOnlyMaster ( ) && ! isMasterHostFail ( ) ) || searchFilter . isFineIfFoundOnlySlave ( ) && ! isSecondaryHostFail ( ) ) ) { return ; } //check if a connection has been retrieved by failoverLoop during lock if ( ! searchFilter . isFailoverLoop ( ) ) { try { checkWaitingConnection ( ) ; if ( ( searchFilter . isFineIfFoundOnlyMaster ( ) && ! isMasterHostFail ( ) ) || searchFilter . isFineIfFoundOnlySlave ( ) && ! isSecondaryHostFail ( ) ) { return ; } } catch ( ReconnectDuringTransactionException e ) { //don't throw an exception for this specific exception return ; } } currentConnectionAttempts . incrementAndGet ( ) ; resetOldsBlackListHosts ( ) ; //put the list in the following order // - random order not blacklist and not connected host // - random order blacklist host // - connected host List < HostAddress > loopAddress = new LinkedList <> ( urlParser . getHostAddresses ( ) ) ; loopAddress . removeAll ( getBlacklistKeys ( ) ) ; Collections . shuffle ( loopAddress ) ; List < HostAddress > blacklistShuffle = new LinkedList <> ( getBlacklistKeys ( ) ) ; blacklistShuffle . retainAll ( urlParser . getHostAddresses ( ) ) ; Collections . shuffle ( blacklistShuffle ) ; loopAddress . addAll ( blacklistShuffle ) ; //put connected at end if ( masterProtocol != null && ! isMasterHostFail ( ) ) { loopAddress . remove ( masterProtocol . getHostAddress ( ) ) ; loopAddress . add ( masterProtocol . getHostAddress ( ) ) ; } if ( secondaryProtocol != null && ! isSecondaryHostFail ( ) ) { loopAddress . remove ( secondaryProtocol . getHostAddress ( ) ) ; loopAddress . add ( secondaryProtocol . getHostAddress ( ) ) ; } if ( ( isMasterHostFail ( ) || isSecondaryHostFail ( ) ) || searchFilter . isInitialConnection ( ) ) { //while permit to avoid case when succeeded creating a new Master connection //and ping master connection fail a few millissecond after, //resulting a masterConnection not initialized. do { MastersSlavesProtocol . loop ( this , globalInfo , loopAddress , searchFilter ) ; //close loop if all connection are retrieved if ( ! searchFilter . isFailoverLoop ( ) ) { try { checkWaitingConnection ( ) ; } catch ( ReconnectDuringTransactionException e ) { //don't throw an exception for this specific exception } } } while ( searchFilter . isInitialConnection ( ) && ! ( masterProtocol != null || ( urlParser . getOptions ( ) . allowMasterDownConnection && secondaryProtocol != null ) ) ) ; if ( searchFilter . isInitialConnection ( ) && masterProtocol == null && currentReadOnlyAsked ) { currentProtocol = this . secondaryProtocol ; currentReadOnlyAsked = true ; } } }
Loop to connect .