protected synchronized List < String > getActiveWorkerInstances ( ) { List < String > localList = new ArrayList < String > ( ) ; int activeServerInterval = PropertyManager . getIntegerProperty ( PropertyNames . MDW_ROUTING_ACTIVE_SERVER_INTERVAL , 15 ) ; // Represents how many seconds between checks if ( lastCheck == 0 || ( ( System . currentTimeMillis ( ) - lastCheck ) / 1000 ) > activeServerInterval ) { lastCheck = System . currentTimeMillis ( ) ; activeServerList . clear ( ) ; for ( String server : getWorkerInstances ( ) ) { try { HttpHelper helper = new HttpHelper ( new URL ( "http://" + server + "/" + ApplicationContext . getServicesContextRoot ( ) + "/Services/SystemInfo?type=threadDumpCount&format=text" ) ) ; helper . setConnectTimeout ( 1000 ) ; // Timeout after 1 second helper . setReadTimeout ( 1000 ) ; String response = helper . get ( ) ; if ( ! StringHelper . isEmpty ( response ) && Integer . parseInt ( response ) > 0 && ! activeServerList . contains ( server ) ) activeServerList . add ( server ) ; } catch ( Exception ex ) { if ( activeServerList . contains ( server ) ) activeServerList . remove ( server ) ; logger . info ( "MDW Server instance " + server + " is not responding" ) ; } } lastCheck = System . currentTimeMillis ( ) ; } // If all worker instances are non-responsive, still try to send it to one of them - Don't want routing instance to process request // Could be they just did a cache refresh or initial startup and couldn't respond in < 1 second - First request if ( activeServerList . isEmpty ( ) ) { for ( String server : getWorkerInstances ( ) ) activeServerList . ( server ) ; } for ( String server : activeServerList ) localList . ( server ) ; return localList ; }
Override this to modify how active instances are determined