public SortedMap < String , HealthCheck . Result > runHealthChecks ( ExecutorService executor , HealthCheckFilter filter ) { final Map < String , Future < HealthCheck . Result > > futures = new HashMap <> ( ) ; for ( final Map . Entry < String , HealthCheck > entry : healthChecks . entrySet ( ) ) { final String name = entry . getKey ( ) ; final HealthCheck healthCheck = entry . getValue ( ) ; if ( filter . matches ( name , healthCheck ) ) { futures . put ( name , executor . submit ( ( ) -> healthCheck . execute ( ) ) ) ; } } final SortedMap < String , HealthCheck . Result > results = new TreeMap <> ( ) ; for ( Map . Entry < String , Future < Result > > entry : futures . entrySet ( ) ) { try { results . put ( entry . getKey ( ) , entry . getValue ( ) . get ( ) ) ; } catch ( Exception e ) { LOGGER . warn ( "Error executing health check {}" , entry . getKey ( ) , e ) ; results . put ( entry . getKey ( ) , HealthCheck . Result . unhealthy ( e ) ) ; } } return Collections . unmodifiableSortedMap ( results ) ; }
Runs the registered health checks matching the filter in parallel and returns a map of the results .