@Override
    public void start(StartContext context) throws StartException {
        Set<KeytabService> services = keytabServices.getValue();

        hostServiceMap = new HashMap<String, KeytabService>(services.size()); // Assume at least one per service.
        /*
         * Iterate the services and find the first one to offer default resolution, also create a hostname to KeytabService map
         * for the first one that claims each host.
         */
        for (KeytabService current : services) {
            for (String currentHost : current.getForHosts()) {
                if ("*".equals(currentHost)) {
                    if (defaultService == null) {
                        defaultService = current;
                    }
                } else if (currentHost != null) {
                    int idx = currentHost.indexOf("/");
                    String hostKey = idx > -1 ? currentHost.substring(0, idx) + "/" + currentHost.substring(idx + 1).toLowerCase(Locale.ENGLISH) :
                        currentHost.toLowerCase(Locale.ENGLISH);
                    if (hostServiceMap.containsKey(hostKey) == false) {
                        hostServiceMap.put(hostKey, current);
                    }
                }
            }
        }

        /*
         * Iterate the services again and attempt to identify host names from the principal name and add to the map if there is
         * not already a mapping for that host name.
         */
        for (KeytabService current : services) {
            String principal = current.getPrincipal();
            int start = principal.indexOf('/');
            int end = principal.indexOf('@');

            String currentHost = principal.substring(start > -1 ? start + 1 : 0, end > -1 ? end : principal.length() - 1);
            if (hostServiceMap.containsKey(currentHost.toLowerCase(Locale.ENGLISH)) == false) {
                hostServiceMap.put(currentHost.toLowerCase(Locale.ENGLISH), current);
            }
            principal = principal.substring(0, end > -1 ? end : principal.length() - 1);
            if (principal.equals(currentHost) == false) {
                String principalKey = principal.substring(0, start) + "/" + currentHost.toLowerCase(Locale.ENGLISH);
                if (hostServiceMap.containsKey(principalKey) == false) {
                    hostServiceMap.put(principalKey, current);
                }
            }
        }
    }
@ Override public void start ( StartContext context ) throws StartException { Set < KeytabService > services = keytabServices . getValue ( ) ; hostServiceMap = new HashMap < String , KeytabService > ( services . size ( ) ) ; for ( KeytabService current : services ) { for ( String currentHost : current . getForHosts ( ) ) { if ( "*" . equals ( currentHost ) ) { if ( defaultService == null ) { defaultService = current ; } } else if ( currentHost != null ) { int idx = currentHost . indexOf ( "/" ) ; String hostKey = idx > - 1 ? currentHost . substring ( 0 , idx ) + "/" + currentHost . substring ( idx + 1 ) . toLowerCase ( Locale . ENGLISH ) : currentHost . toLowerCase ( Locale . ENGLISH ) ; if ( hostServiceMap . containsKey ( hostKey ) == false ) { hostServiceMap . put ( hostKey , current ) ; } } } } for ( KeytabService current : services ) { String principal = current . getPrincipal ( ) ; int start = principal . indexOf ( '/' ) ; int end = principal . indexOf ( '@' ) ; String currentHost = principal . substring ( start > - 1 ? start + 1 : 0 , end > - 1 ? end : principal . length ( ) - 1 ) ; if ( hostServiceMap . containsKey ( currentHost . toLowerCase ( Locale . ENGLISH ) ) == false ) { hostServiceMap . put ( currentHost . toLowerCase ( Locale . ENGLISH ) , current ) ; } principal = principal . substring ( 0 , end > - 1 ? end : principal . length ( ) - 1 ) ; if ( principal . equals ( currentHost ) == false ) { String principalKey = principal . substring ( 0 , start ) + "/" + currentHost . toLowerCase ( Locale . ENGLISH ) ; if ( hostServiceMap . containsKey ( principalKey ) == false ) { hostServiceMap . put ( principalKey , current ) ; } } } }
/*
Service Methods.