@Override public String choose(VolumeChooserEnvironment env, String[] options) throws VolumeChooserException { options = getPreferredVolumes(env, options); try { return getCache(env).get(Arrays.asList(options)).next(); } catch (ExecutionException e) { throw new IllegalStateException("Execution exception when attempting to cache choice", e); } }
private synchronized LoadingCache<List<String>,WeightedRandomCollection> getCache( VolumeChooserEnvironment env) { if (choiceCache == null) { ServerConfigurationFactory scf = loadConfFactory(env); AccumuloConfiguration systemConfiguration = scf.getSystemConfiguration(); String propertyValue = systemConfiguration.get(HDFS_SPACE_RECOMPUTE_INTERVAL); long computationCacheDuration = StringUtils.isNotBlank(propertyValue) ? Long.parseLong(propertyValue) : defaultComputationCacheDuration; choiceCache = CacheBuilder.newBuilder() .expireAfterWrite(computationCacheDuration, TimeUnit.MILLISECONDS) .build(new CacheLoader<List<String>,WeightedRandomCollection>() { @Override public WeightedRandomCollection load(List<String> key) { return new WeightedRandomCollection(key, env, random); } }); } return choiceCache; }