Skip to content

Commit a66abeb

Browse files
committed
CR1 updates
1 parent c548863 commit a66abeb

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

config/src/main/java/io/scalecube/config/ConfigRegistryImpl.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.scalecube.config.source.ConfigSource;
66
import io.scalecube.config.source.ConfigSourceInfo;
77
import io.scalecube.config.source.LoadedConfigProperty;
8+
import io.scalecube.config.utils.ThrowableUtil;
89
import java.lang.management.ManagementFactory;
910
import java.lang.reflect.Field;
1011
import java.time.Duration;
@@ -29,7 +30,6 @@
2930
import java.util.function.Function;
3031
import java.util.stream.Collectors;
3132
import java.util.stream.Stream;
32-
import javax.management.MBeanInfo;
3333
import javax.management.MBeanServer;
3434
import javax.management.ObjectName;
3535
import org.slf4j.Logger;
@@ -55,7 +55,7 @@ final class ConfigRegistryImpl implements ConfigRegistry {
5555
r -> {
5656
Thread thread = new Thread(r);
5757
thread.setDaemon(true);
58-
thread.setName("config-reloader");
58+
thread.setName("config-registry");
5959
thread.setUncaughtExceptionHandler((t, e) -> LOGGER.error("Exception occurred: " + e, e));
6060
return thread;
6161
};
@@ -70,6 +70,7 @@ final class ConfigRegistryImpl implements ConfigRegistry {
7070

7171
private volatile Map<String, LoadedConfigProperty> propertyMap; // being reset on reload
7272

73+
@SuppressWarnings("rawtypes")
7374
private final Map<String, Map<Class, PropertyCallback>> propertyCallbackMap =
7475
new ConcurrentHashMap<>();
7576

@@ -94,7 +95,7 @@ void init() {
9495
try {
9596
loadAndNotify();
9697
} catch (Exception e) {
97-
LOGGER.error("Exception on config reload, cause: {}", e, e);
98+
LOGGER.error("[loadAndNotify] Exception occurred, cause: " + e);
9899
}
99100
},
100101
settings.getReloadIntervalSec(),
@@ -111,10 +112,8 @@ private void registerJmxMBean() {
111112
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
112113
ObjectName objectName = new ObjectName(settings.getJmxMBeanName());
113114
mbeanServer.registerMBean(new JmxConfigRegistry(this), objectName);
114-
MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName);
115-
LOGGER.info("Registered JMX MBean: {}", mbeanInfo);
116115
} catch (Exception e) {
117-
LOGGER.warn("Failed to register JMX MBean '{}', cause: {}", settings.getJmxMBeanName(), e);
116+
throw ThrowableUtil.propagate(e);
118117
}
119118
}
120119

@@ -377,24 +376,26 @@ private void loadAndNotify() {
377376

378377
// load config from sources
379378
Map<String, ConfigSource> sources = settings.getSources();
380-
for (String name : sources.keySet()) {
381-
ConfigSource source = sources.get(name);
379+
for (String sourceName : sources.keySet()) {
380+
ConfigSource source = sources.get(sourceName);
382381

383382
final Map<String, ConfigProperty> configMap;
383+
Throwable error = null;
384384
try {
385385
configMap = source.loadConfig();
386386
} catch (Exception e) {
387-
computeConfigLoadStatus(name, source, e);
388-
throw e;
387+
error = e;
388+
throw ThrowableUtil.propagate(e);
389+
} finally {
390+
computeConfigLoadStatus(sourceName, error);
389391
}
390392

391-
computeConfigLoadStatus(name, source, null);
392-
393393
// populate loaded properties with new field 'source'
394394
configMap.forEach(
395395
(key, configProperty) ->
396396
loadedPropertyMap.putIfAbsent(
397-
key, LoadedConfigProperty.withCopyFrom(configProperty).source(name).build()));
397+
key,
398+
LoadedConfigProperty.withCopyFrom(configProperty).source(sourceName).build()));
398399
}
399400

400401
List<ConfigEvent> detectedChanges = new ArrayList<>();
@@ -486,15 +487,15 @@ private void reportChanges(Collection<ConfigEvent> events) {
486487
});
487488
}
488489

489-
private void computeConfigLoadStatus(String name, ConfigSource source, Throwable throwable) {
490+
private void computeConfigLoadStatus(String sourceName, Throwable throwable) {
490491
int status = throwable != null ? 1 : 0;
491-
Integer status0 = configSourceStatusMap.put(name, status);
492+
Integer status0 = configSourceStatusMap.put(sourceName, status);
492493
if (status0 == null || (status0 ^ status) == 1) {
493494
if (status == 1) {
494495
LOGGER.error(
495-
"Exception at loadConfig on {}, source: {}, cause: {}", source, name, throwable);
496+
"[loadConfig][{}] Exception occurred, cause: {}", sourceName, throwable.toString());
496497
} else {
497-
LOGGER.debug("Loaded config properties from {}, source: {}", source, name);
498+
LOGGER.debug("[loadConfig][{}] Loaded config properties", sourceName);
498499
}
499500
}
500501
}

0 commit comments

Comments
 (0)