commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <>
Subject Re: detecting file reload in Apache Commons Configuration2
Date Sat, 03 Dec 2016 15:09:39 GMT

Am 02.12.2016 um 15:48 schrieb Garret Wilson:
> Using `org.apache.commons:commons-configuration2:2.1` my application
> needs to know when a configuration file has been reloaded so that it can
> update some things in the program. Apache Commons Configuration2 uses a
> lot of strategies and factories, and usually that's great, but here it's
> getting so complicated I can't figure out where I need to install a
> listener.
> The application has this:
>     configConfigurationBuilder = new
> ReloadingFileBasedConfigurationBuilder<FileBasedConfiguration>(
>         PropertiesConfiguration.class)
>             .configure(new
> Parameters().properties().setFile(getConfigFile()));
>     final PeriodicReloadingTrigger configReloadingTrigger = new
> PeriodicReloadingTrigger(
>         configConfigurationBuilder.getReloadingController(), null, 1,
> TimeUnit.MINUTES);
>     configReloadingTrigger.start();
> Which of these various things can I install a listener on? I just want
> to be notified when the configuration file is reloaded.
> I notice that the `ReloadingDetector` interface has a
> `reloadingPerformed()` method, and that sounds like what I want. But how
> do I add my own `ReloadingDetector`? It seems like the
> `ReloadingController` only keeps one `ReloadingDetector` around. Surely
> I don't have to subclass `ReloadingDetector` and install a custom one,
> would I? I'm not wanting to specialize the reloading detection, so
> subclassing would not be appropriate --- I just want to be notified when
> something happens. Besides, it's not obvious to me where I would even
> hook into the `ReloadingFileBasedConfigurationBuilder` chain of events
> where it uses some internal factor to create the detector.
> So how can I easily get Apache Commons Configuration2 to notify me when
> it reloads a configuration?

You can add an event listener at the ReloadingController, then you
receive notifications of type ReloadingEvent.

Alternatively, you could also register a more generic listener for
events on the configuration builder itself. When the builder's managed
configuration is reset, a corresponding event is produced. This also
happens during a reload operation.


> Garret
> P.S Does no one monitor Stack Overflow? It is a real pain to subscribe
> to this old-fashioned mailing list---a general one for all Apache
> Commons, at that!---just to ask a technical question. Below is the
> unanswered Stack Overflow question I posted.
> If you were to answer this question on Stack Overflow it would help a
> lot more people than simply replying on this obscure mailing list. Just
> a suggestion.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message