@ Override public int compare ( T server1 , T server2 ) { LoadBalancerStats lbStats = getLoadBalancerStats ( ) ; ServerStats stats1 = lbStats . getSingleServerStat ( server1 ) ; ServerStats stats2 = lbStats . getSingleServerStat ( server2 ) ; int failuresDiff = ( int ) ( stats2 . getFailureCount ( ) - stats1 . getFailureCount ( ) ) ; if ( failuresDiff != 0 ) { return failuresDiff ; } else { return ( stats2 . getActiveRequestsCount ( ) - stats1 . getActiveRequestsCount ( ) ) ; } }
Function to sort the list by server health condition with unhealthy servers before healthy servers . The servers are first sorted by failures count and then concurrent connection count .