55import io .scalecube .config .source .ConfigSource ;
66import io .scalecube .config .source .ConfigSourceInfo ;
77import io .scalecube .config .source .LoadedConfigProperty ;
8+ import io .scalecube .config .utils .ThrowableUtil ;
89import java .lang .management .ManagementFactory ;
910import java .lang .reflect .Field ;
1011import java .time .Duration ;
2930import java .util .function .Function ;
3031import java .util .stream .Collectors ;
3132import java .util .stream .Stream ;
32- import javax .management .MBeanInfo ;
3333import javax .management .MBeanServer ;
3434import javax .management .ObjectName ;
3535import 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,26 +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
383- Throwable loadException = null ;
384- Map < String , ConfigProperty > configMap = null ;
382+ final Map < String , ConfigProperty > configMap ;
383+ Throwable error = null ;
385384 try {
386385 configMap = source .loadConfig ();
387386 } catch (Exception e ) {
388- loadException = e ; // save error occurrence
387+ error = e ;
388+ throw ThrowableUtil .propagate (e );
389+ } finally {
390+ computeConfigLoadStatus (sourceName , error );
389391 }
390392
391- computeConfigLoadStatus (name , source , loadException );
392-
393- if (loadException == null ) {
394- // populate loaded properties with new field 'source'
395- configMap .forEach (
396- (key , configProperty ) ->
397- loadedPropertyMap .putIfAbsent (
398- key , LoadedConfigProperty .withCopyFrom (configProperty ).source (name ).build ()));
399- }
393+ // populate loaded properties with new field 'source'
394+ configMap .forEach (
395+ (key , configProperty ) ->
396+ loadedPropertyMap .putIfAbsent (
397+ key ,
398+ LoadedConfigProperty .withCopyFrom (configProperty ).source (sourceName ).build ()));
400399 }
401400
402401 List <ConfigEvent > detectedChanges = new ArrayList <>();
@@ -488,15 +487,15 @@ private void reportChanges(Collection<ConfigEvent> events) {
488487 });
489488 }
490489
491- private void computeConfigLoadStatus (String name , ConfigSource source , Throwable throwable ) {
490+ private void computeConfigLoadStatus (String sourceName , Throwable throwable ) {
492491 int status = throwable != null ? 1 : 0 ;
493- Integer status0 = configSourceStatusMap .put (name , status );
492+ Integer status0 = configSourceStatusMap .put (sourceName , status );
494493 if (status0 == null || (status0 ^ status ) == 1 ) {
495494 if (status == 1 ) {
496495 LOGGER .error (
497- "Exception at loadConfig on {}, source: {} , cause: {}" , source , name , throwable );
496+ "[ loadConfig][{}] Exception occurred , cause: {}" , sourceName , throwable . toString () );
498497 } else {
499- LOGGER .debug ("Loaded config properties from {}, source: {} " , source , name );
498+ LOGGER .debug ("[loadConfig][{}] Loaded config properties" , sourceName );
500499 }
501500 }
502501 }
0 commit comments