Re: detecting file reload in Apache Commons Configuration2

2016-12-03 Thread Garret Wilson

On 12/3/2016 9:21 AM, Oliver Heger wrote:

...

Does it happen _during_ a reload operation or _after_? When I receive
this event, is the configuration guaranteed to have the new, reloaded
information?

Why can't I just have a simple event saying "the configuration now has
new data"?

Maybe a misunderstanding of the reloading mechanism: New data is not
automatically pushed into a Configuration object you might have a
reference to. Rather, the configuration builder is reset. So the next
time you query the builder for a configuration you get a new one with
updated data.

When you receive one of the mentioned events the builder has been reset
and thus you know that new data is available.


Oh, right. I remember reading this now. I'll try one of these events and 
see how it works. Thank you.


Garret

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: detecting file reload in Apache Commons Configuration2

2016-12-03 Thread Oliver Heger


Am 03.12.2016 um 16:15 schrieb Garret Wilson:
> On 12/3/2016 9:09 AM, Oliver Heger wrote:
>> ...
>> You can add an event listener at the ReloadingController, then you
>> receive notifications of type ReloadingEvent.
> 
> But how does that help me? The Javadocs for
> [ReloadingEvent](https://commons.apache.org/proper/commons-configuration/apidocs/org/apache/commons/configuration2/reloading/ReloadingEvent.html)
> says that this is an "event that is fired when a reload operation is
> required." I don't want an event just when a reload is _required_. That
> helps the ReloadingController, but doesn't help my application much. I
> want an event when a reload _has occurred_, that is, I'm guaranteed that
> the configuration now has new information.
> 
>> 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.
> 
> Does it happen _during_ a reload operation or _after_? When I receive
> this event, is the configuration guaranteed to have the new, reloaded
> information?
> 
> Why can't I just have a simple event saying "the configuration now has
> new data"?

Maybe a misunderstanding of the reloading mechanism: New data is not
automatically pushed into a Configuration object you might have a
reference to. Rather, the configuration builder is reset. So the next
time you query the builder for a configuration you get a new one with
updated data.

When you receive one of the mentioned events the builder has been reset
and thus you know that new data is available.

Oliver

> 
> Garret
> 
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
> 

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: detecting file reload in Apache Commons Configuration2

2016-12-03 Thread Garret Wilson

On 12/3/2016 9:09 AM, Oliver Heger wrote:

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


But how does that help me? The Javadocs for 
[ReloadingEvent](https://commons.apache.org/proper/commons-configuration/apidocs/org/apache/commons/configuration2/reloading/ReloadingEvent.html) 
says that this is an "event that is fired when a reload operation is 
required." I don't want an event just when a reload is _required_. That 
helps the ReloadingController, but doesn't help my application much. I 
want an event when a reload _has occurred_, that is, I'm guaranteed that 
the configuration now has new information.



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.


Does it happen _during_ a reload operation or _after_? When I receive 
this event, is the configuration guaranteed to have the new, reloaded 
information?


Why can't I just have a simple event saying "the configuration now has 
new data"?


Garret

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: detecting file reload in Apache Commons Configuration2

2016-12-03 Thread Oliver Heger
Hi,

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(
> 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.

Oliver

> 
> 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.
> 
> http://stackoverflow.com/q/40917757/421049
> 
> 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: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
> 

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



detecting file reload in Apache Commons Configuration2

2016-12-02 Thread 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(

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?


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.


http://stackoverflow.com/q/40917757/421049

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: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org