@ SuppressWarnings ( "unchecked" ) public static < T > T getSingletonService ( Class < T > intf ) { T ret = null ; synchronized ( singletons ) { if ( singletons . containsKey ( intf ) ) { ret = ( T ) singletons . get ( intf ) ; } else { List < T > services = getServices ( intf ) ; if ( ! services . isEmpty ( ) ) { ret = services . get ( 0 ) ; } singletons . put ( intf , ret ) ; } } return ret ; }
This method identifies a service implementation that implements the supplied interface and returns it as a singleton so that subsequent calls for the same service will get the same instance .