5
5
import io .scalecube .config .source .ConfigSource ;
6
6
import io .scalecube .config .source .ConfigSourceInfo ;
7
7
import io .scalecube .config .source .LoadedConfigProperty ;
8
+ import io .scalecube .config .utils .ThrowableUtil ;
8
9
import java .lang .management .ManagementFactory ;
9
10
import java .lang .reflect .Field ;
10
11
import java .time .Duration ;
29
30
import java .util .function .Function ;
30
31
import java .util .stream .Collectors ;
31
32
import java .util .stream .Stream ;
32
- import javax .management .MBeanInfo ;
33
33
import javax .management .MBeanServer ;
34
34
import javax .management .ObjectName ;
35
35
import org .slf4j .Logger ;
@@ -55,7 +55,7 @@ final class ConfigRegistryImpl implements ConfigRegistry {
55
55
r -> {
56
56
Thread thread = new Thread (r );
57
57
thread .setDaemon (true );
58
- thread .setName ("config-reloader " );
58
+ thread .setName ("config-registry " );
59
59
thread .setUncaughtExceptionHandler ((t , e ) -> LOGGER .error ("Exception occurred: " + e , e ));
60
60
return thread ;
61
61
};
@@ -70,6 +70,7 @@ final class ConfigRegistryImpl implements ConfigRegistry {
70
70
71
71
private volatile Map <String , LoadedConfigProperty > propertyMap ; // being reset on reload
72
72
73
+ @ SuppressWarnings ("rawtypes" )
73
74
private final Map <String , Map <Class , PropertyCallback >> propertyCallbackMap =
74
75
new ConcurrentHashMap <>();
75
76
@@ -94,7 +95,7 @@ void init() {
94
95
try {
95
96
loadAndNotify ();
96
97
} catch (Exception e ) {
97
- LOGGER .error ("Exception on config reload , cause: {}" , e , e );
98
+ LOGGER .error ("[loadAndNotify] Exception occurred , cause: " + e );
98
99
}
99
100
},
100
101
settings .getReloadIntervalSec (),
@@ -111,10 +112,8 @@ private void registerJmxMBean() {
111
112
MBeanServer mbeanServer = ManagementFactory .getPlatformMBeanServer ();
112
113
ObjectName objectName = new ObjectName (settings .getJmxMBeanName ());
113
114
mbeanServer .registerMBean (new JmxConfigRegistry (this ), objectName );
114
- MBeanInfo mbeanInfo = mbeanServer .getMBeanInfo (objectName );
115
- LOGGER .info ("Registered JMX MBean: {}" , mbeanInfo );
116
115
} catch (Exception e ) {
117
- LOGGER . warn ( "Failed to register JMX MBean '{}', cause: {}" , settings . getJmxMBeanName (), e );
116
+ throw ThrowableUtil . propagate ( e );
118
117
}
119
118
}
120
119
@@ -377,26 +376,26 @@ private void loadAndNotify() {
377
376
378
377
// load config from sources
379
378
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 );
382
381
383
- Throwable loadException = null ;
384
- Map < String , ConfigProperty > configMap = null ;
382
+ final Map < String , ConfigProperty > configMap ;
383
+ Throwable error = null ;
385
384
try {
386
385
configMap = source .loadConfig ();
387
386
} catch (Exception e ) {
388
- loadException = e ; // save error occurrence
387
+ error = e ;
388
+ throw ThrowableUtil .propagate (e );
389
+ } finally {
390
+ computeConfigLoadStatus (sourceName , error );
389
391
}
390
392
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 ()));
400
399
}
401
400
402
401
List <ConfigEvent > detectedChanges = new ArrayList <>();
@@ -488,15 +487,15 @@ private void reportChanges(Collection<ConfigEvent> events) {
488
487
});
489
488
}
490
489
491
- private void computeConfigLoadStatus (String name , ConfigSource source , Throwable throwable ) {
490
+ private void computeConfigLoadStatus (String sourceName , Throwable throwable ) {
492
491
int status = throwable != null ? 1 : 0 ;
493
- Integer status0 = configSourceStatusMap .put (name , status );
492
+ Integer status0 = configSourceStatusMap .put (sourceName , status );
494
493
if (status0 == null || (status0 ^ status ) == 1 ) {
495
494
if (status == 1 ) {
496
495
LOGGER .error (
497
- "Exception at loadConfig on {}, source: {} , cause: {}" , source , name , throwable );
496
+ "[ loadConfig][{}] Exception occurred , cause: {}" , sourceName , throwable . toString () );
498
497
} else {
499
- LOGGER .debug ("Loaded config properties from {}, source: {} " , source , name );
498
+ LOGGER .debug ("[loadConfig][{}] Loaded config properties" , sourceName );
500
499
}
501
500
}
502
501
}
0 commit comments