use of io.gravitee.rest.api.services.dictionary.provider.http.HttpProvider in project gravitee-management-rest-api by gravitee-io.
the class DictionaryService method startDynamicDictionary.
private void startDynamicDictionary(DictionaryEntity dictionary) {
if (!timers.containsKey(dictionary.getId())) {
DictionaryProviderEntity providerConf = dictionary.getProvider();
if (DICTIONARY_HTTP_PROVIDER.equals(providerConf.getType())) {
try {
HttpProviderConfiguration configuration = objectMapper.treeToValue(providerConf.getConfiguration(), HttpProviderConfiguration.class);
DictionaryRefresher refresher = new DictionaryRefresher(dictionary);
HttpProvider provider = new HttpProvider(configuration);
provider.setVertx(vertx);
provider.setNode(node);
refresher.setProvider(provider);
refresher.setDictionaryService(dictionaryService);
logger.info("Add a scheduled task to poll dictionary provider for dictionary [{}] each {} {} ", dictionary.getId(), dictionary.getTrigger().getRate(), dictionary.getTrigger().getUnit());
// Force the first refresh, and then run it periodically
refresher.handle(null);
long periodicTimer = vertx.setPeriodic(getDelayMillis(dictionary.getTrigger()), refresher);
timers.put(dictionary.getId(), periodicTimer);
} catch (JsonProcessingException jpe) {
logger.error("Dictionary provider configuration for dictionary [{}] is invalid", dictionary.getId(), jpe);
}
}
}
}
Aggregations