@ Nullable @ VisibleForTesting static Map < String , ? > maybeChooseServiceConfig ( Map < String , ? > choice , Random random , String hostname ) { for ( Entry < String , ? > entry : choice . entrySet ( ) ) { Verify . verify ( SERVICE_CONFIG_CHOICE_KEYS . contains ( entry . getKey ( ) ) , "Bad key: %s" , entry ) ; } List < String > clientLanguages = getClientLanguagesFromChoice ( choice ) ; if ( clientLanguages != null && ! clientLanguages . isEmpty ( ) ) { boolean javaPresent = false ; for ( String lang : clientLanguages ) { if ( "java" . equalsIgnoreCase ( lang ) ) { javaPresent = true ; break ; } } if ( ! javaPresent ) { return null ; } } Double percentage = getPercentageFromChoice ( choice ) ; if ( percentage != null ) { int pct = percentage . intValue ( ) ; Verify . verify ( pct >= 0 && pct <= 100 , "Bad percentage: %s" , percentage ) ; if ( random . nextInt ( 100 ) >= pct ) { return null ; } } List < String > clientHostnames = getHostnamesFromChoice ( choice ) ; if ( clientHostnames != null && ! clientHostnames . isEmpty ( ) ) { boolean hostnamePresent = false ; for ( String clientHostname : clientHostnames ) { if ( clientHostname . equals ( hostname ) ) { hostnamePresent = true ; break ; } } if ( ! hostnamePresent ) { return null ; } } Map < String , ? > sc = ServiceConfigUtil . getObject ( choice , SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY ) ; if ( sc == null ) { throw new VerifyException ( String . format ( "key '%s' missing in '%s'" , choice , SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY ) ) ; } return sc ; }
Determines if a given Service Config choice applies and if so returns it .