question: protected void recoverPrimary ( Set excludedServers ) { if ( pool . getPoolOrCacheCancelInProgress ( ) != null ) { return ; } final boolean isDebugEnabled = logger . isDebugEnabled ( ) ; if ( queueConnections . getPrimary ( ) != null ) { if ( isDebugEnabled ) { logger . debug ( "Primary recovery not needed" ) ; } return ; } if ( isDebugEnabled ) { logger . debug ( "SubscriptionManager redundancy satisfier - primary endpoint has been lost. Attempting to recover" ) ; } if ( printRecoveringPrimary ) { logger . info ( LocalizedMessage . create ( LocalizedStrings . QueueManagerImpl_SUBSCRIPTION_MANAGER_REDUNDANCY_SATISFIER_PRIMARY_ENDPOINT_HAS_BEEN_LOST_ATTEMPTIMG_TO_RECOVER ) ) ; printRecoveringPrimary = false ; } QueueConnectionImpl newPrimary = null ; while ( newPrimary == null && pool . getPoolOrCacheCancelInProgress ( ) == null ) { List backups = queueConnections . getBackups ( ) ; newPrimary = promoteBackupToPrimary ( backups ) ; if ( newPrimary == null ) { break ; } if ( ! addToConnectionList ( newPrimary , true ) ) { synchronized ( lock ) { queueConnections = queueConnections . removeConnection ( newPrimary ) ; } newPrimary = null ; } } if ( newPrimary != null ) { if ( isDebugEnabled ) { logger . debug ( "SubscriptionManager redundancy satisfier - Switched backup server to primary: {}" , newPrimary . getEndpoint ( ) ) ; } if ( PoolImpl . AFTER_PRIMARY_RECOVERED_CALLBACK_FLAG ) { ClientServerObserver bo = ClientServerObserverHolder . getInstance ( ) ; bo . afterPrimaryRecovered ( newPrimary . getServer ( ) ) ; } cqsConnected ( ) ; printPrimaryNotFoundError = true ; printRecoveringPrimary = true ; return ; } while ( newPrimary == null ) { newPrimary = createNewPrimary ( excludedServers ) ; if ( newPrimary == null ) { break ; } if ( ! addToConnectionList ( newPrimary , true ) ) { excludedServers . add ( newPrimary . getServer ( ) ) ; newPrimary = null ; } if ( newPrimary != null ) { if ( isDebugEnabled ) { logger . debug ( "SubscriptionManager redundancy satisfier - Non backup server was made primary. Recovering interest {}" , newPrimary . getEndpoint ( ) ) ; } if ( ! recoverInterest ( newPrimary , true ) ) { excludedServers . add ( newPrimary . getServer ( ) ) ; newPrimary = null ; } cqsConnected ( ) ; } if ( newPrimary != null && PoolImpl . AFTER_PRIMARY_RECOVERED_CALLBACK_FLAG ) { ClientServerObserver bo = ClientServerObserverHolder . getInstance ( ) ; bo . afterPrimaryRecovered ( newPrimary . getServer ( ) ) ; } printPrimaryNotFoundError = true ; printRecoveringPrimary = true ; return ; } cqsDisconnected ( ) ; if ( isDebugEnabled ) { logger . debug ( "SubscriptionManager redundancy satisfier - Could not recover a new primary" ) ; } synchronized ( lock ) { queueConnections = queueConnections . setPrimaryDiscoveryFailed ( null ) ; lock . notifyAll ( ) ; } }
target:  Find a new primary, adding any failed servers we encounter to the excluded servers list First we try to make a backup server the primary, but if run out of backup servers we will try to find a new server.