public JestClient createLocalClient ( String className , String fieldName , String indexName , String defaultIndexName ) { String clientKey = "local:" + className + ' ' + fieldName ; //$NON-NLS-1$ synchronized ( clients ) { if ( clients . containsKey ( clientKey ) ) { return clients . get ( clientKey ) ; } else { try { Class < ? > clientLocClass = Class . forName ( className ) ; Field field = clientLocClass . getField ( fieldName ) ; JestClient client = ( JestClient ) field . get ( null ) ; clients . put ( clientKey , client ) ; initializeClient ( client , indexName , defaultIndexName ) ; return client ; } catch ( ClassNotFoundException | NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e ) { throw new RuntimeException ( "Error using local elasticsearch client." , e ) ; //$NON-NLS-1$ } } } }
Creates a cache by looking it up in a static field . Typically used for testing .