/** * instantiate a strategy from a config property. requires conf to have already been set (as well * as anything the provider might need to read). */ RegionGroupingStrategy getStrategy( final Configuration conf, final String key, final String defaultValue) throws IOException { Class<? extends RegionGroupingStrategy> clazz; try { clazz = Strategies.valueOf(conf.get(key, defaultValue)).clazz; } catch (IllegalArgumentException exception) { // Fall back to them specifying a class name // Note that the passed default class shouldn't actually be used, since the above only fails // when there is a config value present. clazz = conf.getClass(key, IdentityGroupingStrategy.class, RegionGroupingStrategy.class); } LOG.info("Instantiating RegionGroupingStrategy of type " + clazz); try { final RegionGroupingStrategy result = clazz.newInstance(); result.init(conf); return result; } catch (InstantiationException exception) { LOG.error( "couldn't set up region grouping strategy, check config key " + REGION_GROUPING_STRATEGY); LOG.debug("Exception details for failure to load region grouping strategy.", exception); throw new IOException("couldn't set up region grouping strategy", exception); } catch (IllegalAccessException exception) { LOG.error( "couldn't set up region grouping strategy, check config key " + REGION_GROUPING_STRATEGY); LOG.debug("Exception details for failure to load region grouping strategy.", exception); throw new IOException("couldn't set up region grouping strategy", exception); } }