A class for adding support for reload operations in a generic way.
A {@code ReloadingController} monitors a specific source and triggersreloading events if necessary. So it does not perform reloading itself, but only sends out notifications when it thinks that this should be done. This allows for a very generic setup in which different components involved in reloading are loosely coupled via events.
A typical usage scenario is as follows:
- A {@code ReloadingController} instance is created and initialized with a{@link ReloadingDetector} object.
- A number of {@link EventListener} objects for reloading events can beregistered at the controller.
- Now the controller's {@code checkForReloading()} method is calledwhenever a check is to be performed. This could be done for instance by a timer in regular intervals or by any other means appropriate for a specific application.
- When a check reveals that a reload operation is necessary all registered event listeners are notified.
- Typically one of the listeners is responsible to perform the actual reload operation. (How this is done is not in the scope of the controller object.) After this has been done, the controller's {@code resetReloadingState()} method must be called. It tells the controllerthat the last notification has been processed and that new checks are possible again. It is important that this method is called. Otherwise, {@code checkForReloading()} will not do any new checks or send out eventnotifications any more.
This class can be accessed from multiple threads concurrently. It shields the associated {@link ReloadingDetector} object for concurrent access, so that aconcrete detector implementation does not have to be thread-safe.
@version $Id: ReloadingController.java 1624601 2014-09-12 18:04:36Z oheger $
@since 2.0