22
22
import java .io .InputStream ;
23
23
import java .lang .ref .WeakReference ;
24
24
import java .net .URI ;
25
+ import java .net .URISyntaxException ;
25
26
import java .util .ArrayList ;
26
27
import java .util .Arrays ;
27
28
import java .util .Collection ;
@@ -132,6 +133,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
132
133
private ConcurrentMap <String , Appender > appenders = new ConcurrentHashMap <>();
133
134
private ConcurrentMap <String , LoggerConfig > loggerConfigs = new ConcurrentHashMap <>();
134
135
private List <CustomLevelConfig > customLevels = Collections .emptyList ();
136
+ private List <URI > uris = Collections .emptyList ();
135
137
private final ConcurrentMap <String , String > propertyMap = new ConcurrentHashMap <>();
136
138
private final Interpolator tempLookup = new Interpolator (propertyMap );
137
139
private final StrSubstitutor runtimeStrSubstitutor = new RuntimeStrSubstitutor (tempLookup );
@@ -275,14 +277,6 @@ protected void initializeWatchers(
275
277
final Reconfigurable reconfigurable ,
276
278
final ConfigurationSource configSource ,
277
279
final int monitorIntervalSeconds ) {
278
- initializeWatchers (reconfigurable , configSource , Collections .emptySet (), monitorIntervalSeconds );
279
- }
280
-
281
- protected void initializeWatchers (
282
- final Reconfigurable reconfigurable ,
283
- final ConfigurationSource configSource ,
284
- final Collection <Source > auxiliarySources ,
285
- final int monitorIntervalSeconds ) {
286
280
if (configSource != null && (configSource .getFile () != null || configSource .getURL () != null )) {
287
281
if (monitorIntervalSeconds > 0 ) {
288
282
watchManager .setIntervalSeconds (monitorIntervalSeconds );
@@ -292,7 +286,7 @@ protected void initializeWatchers(
292
286
final long lastModified = file .lastModified ();
293
287
final ConfigurationFileWatcher watcher =
294
288
new ConfigurationFileWatcher (this , reconfigurable , listeners , lastModified );
295
- watchManager .watch (cfgSource , auxiliarySources , watcher );
289
+ watchManager .watch (cfgSource , watcher );
296
290
} else if (configSource .getURL () != null ) {
297
291
monitorSource (reconfigurable , configSource );
298
292
}
@@ -331,10 +325,19 @@ public void start() {
331
325
LOGGER .info ("Starting configuration {}..." , this );
332
326
this .setStarting ();
333
327
if (watchManager .getIntervalSeconds () >= 0 ) {
334
- LOGGER .info (
335
- "Start watching for changes to {} every {} seconds" ,
336
- getConfigurationSource (),
337
- watchManager .getIntervalSeconds ());
328
+ if (uris != null && uris .size () > 0 ) {
329
+ LOGGER .info (
330
+ "Start watching for changes to {} and {} every {} seconds" ,
331
+ getConfigurationSource (),
332
+ uris ,
333
+ watchManager .getIntervalSeconds ());
334
+ watchManager .addMonitorUris (configurationSource .getSource (), uris );
335
+ } else {
336
+ LOGGER .info (
337
+ "Start watching for changes to {} every {} seconds" ,
338
+ getConfigurationSource (),
339
+ watchManager .getIntervalSeconds ());
340
+ }
338
341
watchManager .start ();
339
342
}
340
343
if (hasAsyncLoggers ()) {
@@ -737,9 +740,16 @@ protected void doConfigure() {
737
740
} else if (child .isInstanceOf (AsyncWaitStrategyFactoryConfig .class )) {
738
741
final AsyncWaitStrategyFactoryConfig awsfc = child .getObject (AsyncWaitStrategyFactoryConfig .class );
739
742
asyncWaitStrategyFactory = awsfc .createWaitStrategyFactory ();
743
+ } else if (child .isInstanceOf (MonitorUris .class )) {
744
+ uris = convertToJavaNetUris (child .getObject (MonitorUris .class ).getUris ());
740
745
} else {
741
746
final List <String > expected = Arrays .asList (
742
- "\" Appenders\" " , "\" Loggers\" " , "\" Properties\" " , "\" Scripts\" " , "\" CustomLevels\" " );
747
+ "\" Appenders\" " ,
748
+ "\" Loggers\" " ,
749
+ "\" Properties\" " ,
750
+ "\" Scripts\" " ,
751
+ "\" CustomLevels\" " ,
752
+ "\" MonitorUris\" " );
743
753
LOGGER .error (
744
754
"Unknown object \" {}\" of type {} is ignored: try nesting it inside one of: {}." ,
745
755
child .getName (),
@@ -775,6 +785,18 @@ protected void doConfigure() {
775
785
setParents ();
776
786
}
777
787
788
+ private List <URI > convertToJavaNetUris (final List <Uri > uris ) {
789
+ final List <URI > javaNetUris = new ArrayList <>();
790
+ for (Uri uri : uris ) {
791
+ try {
792
+ javaNetUris .add (new URI (uri .getUri ()));
793
+ } catch (URISyntaxException e ) {
794
+ LOGGER .error ("Error parsing monitor URI: " + uri , e );
795
+ }
796
+ }
797
+ return javaNetUris ;
798
+ }
799
+
778
800
public static Level getDefaultLevel () {
779
801
final String levelName = PropertiesUtil .getProperties ()
780
802
.getStringProperty (DefaultConfiguration .DEFAULT_LEVEL , Level .ERROR .name ());
0 commit comments