Search in sources :

Example 1 with HttpProvider

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);
            }
        }
    }
}
Also used : HttpProvider(io.gravitee.rest.api.services.dictionary.provider.http.HttpProvider) DictionaryProviderEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity) HttpProviderConfiguration(io.gravitee.rest.api.services.dictionary.provider.http.configuration.HttpProviderConfiguration) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 DictionaryProviderEntity (io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity)1 HttpProvider (io.gravitee.rest.api.services.dictionary.provider.http.HttpProvider)1 HttpProviderConfiguration (io.gravitee.rest.api.services.dictionary.provider.http.configuration.HttpProviderConfiguration)1