private void initializePresets ( ) { if ( gobblinPresets == null ) { synchronized ( GobblinHadoopJob . class ) { if ( gobblinPresets == null ) { gobblinPresets = Maps . newHashMap ( ) ; String gobblinPresetDirName = getSysProps ( ) . getString ( GobblinConstants . GOBBLIN_PRESET_DIR_KEY ) ; File gobblinPresetDir = new File ( gobblinPresetDirName ) ; File [ ] presetFiles = gobblinPresetDir . listFiles ( ) ; if ( presetFiles == null ) { return ; } File commonPropertiesFile = new File ( gobblinPresetDir , GOBBLIN_PRESET_COMMON_PROPERTIES_FILE_NAME ) ; if ( ! commonPropertiesFile . exists ( ) ) { throw new IllegalStateException ( "Gobbline preset common properties file is missing " + commonPropertiesFile . getAbsolutePath ( ) ) ; } for ( File f : presetFiles ) { if ( GOBBLIN_PRESET_COMMON_PROPERTIES_FILE_NAME . equals ( f . getName ( ) ) ) { //Don't load common one itself. continue ; } if ( f . isFile ( ) ) { Properties prop = new Properties ( ) ; try ( InputStream commonIs = new BufferedInputStream ( new FileInputStream ( commonPropertiesFile ) ) ; InputStream presetIs = new BufferedInputStream ( new FileInputStream ( f ) ) ) { prop . load ( commonIs ) ; prop . load ( presetIs ) ; String presetName = f . getName ( ) . substring ( 0 , f . getName ( ) . lastIndexOf ( ' ' ) ) ; //remove extension from the file name gobblinPresets . put ( GobblinPresets . fromName ( presetName ) , prop ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } } } } } }
Initializes presets and cache it into preset map . As presets do not change while server is up this initialization happens only once per JVM .