cfg4j / cfg4j

Modern configuration library for distributed apps written in Java.

Home Page:http://cfg4j.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

for ConsulConfigurationSource if some errors happens in the reload process once, the initialized flag will keep false all the way, which will lead to the getConfiguration function throw IllegalStateException

hqlvzs opened this issue · comments

`public void reload() {
Map<String, String> newConsulValues = new HashMap<>();
List valueList;

try {
  LOG.debug("Reloading configuration from Consuls' K-V store");
  valueList = kvClient.getValues("/");
} catch (Exception e) {
  initialized = false;
  throw new SourceCommunicationException("Can't get values from k-v store", e);
}

for (Value value : valueList) {
  String val = "";

  if (value.getValueAsString().isPresent()) {
    val = value.getValueAsString().get();
  }

  LOG.trace("Consul provided configuration key: " + value.getKey() + " with value: " + val);

  newConsulValues.put(value.getKey(), val);
}

consulValues = newConsulValues;

}`

For this reload function, in my opinion, if no Exception has been caught, then we need to set the initialized as true

fixed in #178
set true is incorrect. Retry and fail if not initialized much better. Please review