@ SuppressWarnings ( "unchecked" ) public static < T > Set < T > getServices ( Class < T > serviceInterface ) { synchronized ( servicesCache ) { if ( servicesCache . containsKey ( serviceInterface ) ) { return ( Set < T > ) servicesCache . get ( serviceInterface ) ; } Set < T > services = new LinkedHashSet <> ( ) ; try { for ( T service : ServiceLoader . load ( serviceInterface ) ) { services . add ( service ) ; } } catch ( ServiceConfigurationError sce ) { // No services found - don't check again. } servicesCache . put ( serviceInterface , services ) ; return services ; } }
Get a set of service implementations for a given interface .