Class PeriodicReloadingTrigger
- java.lang.Object
-
- org.apache.commons.configuration2.reloading.PeriodicReloadingTrigger
-
public class PeriodicReloadingTrigger extends Object
A timer-based trigger for reloading checks.
An instance of this class is constructed with a reference to a
ReloadingControllerand a period. After calling thestart()method a periodic task is started which callsReloadingController.checkForReloading(Object)on the associated reloading controller. This way changes on a configuration source can be detected without client code having to poll actively. TheReloadingControllerwill perform its checks and generates events if it detects the need for a reloading operation.Triggering of the controller can be disabled by calling the
stop()method and later be resumed by callingstart()again. When the trigger is no more needed itsshutdown()method should be called.When creating an instance a
ScheduledExecutorServicecan be provided which is then used by the object. Otherwise, a default executor service is created and used. When shutting down this object it can be specified whether theScheduledExecutorServiceshould be shut down, too.- Since:
- 2.0
- See Also:
ReloadingController
-
-
Constructor Summary
Constructors Constructor Description PeriodicReloadingTrigger(ReloadingController ctrl, Object ctrlParam, long triggerPeriod, TimeUnit unit)Creates a new instance ofPeriodicReloadingTriggerwith a default executor service.PeriodicReloadingTrigger(ReloadingController ctrl, Object ctrlParam, long triggerPeriod, TimeUnit unit, ScheduledExecutorService exec)Creates a new instance ofPeriodicReloadingTriggerand sets all parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisRunning()Returns a flag whether this trigger is currently active.voidshutdown()Shuts down this trigger and itsScheduledExecutorService.voidshutdown(boolean shutdownExecutor)Shuts down this trigger and optionally shuts down theScheduledExecutorServiceused by this object.voidstart()Starts this trigger.voidstop()Stops this trigger.
-
-
-
Constructor Detail
-
PeriodicReloadingTrigger
public PeriodicReloadingTrigger(ReloadingController ctrl, Object ctrlParam, long triggerPeriod, TimeUnit unit, ScheduledExecutorService exec)
Creates a new instance ofPeriodicReloadingTriggerand sets all parameters.- Parameters:
ctrl- theReloadingController(must not be null)ctrlParam- the optional parameter to be passed to the controller when doing reloading checkstriggerPeriod- the period in which the controller is triggeredunit- the time unit for the periodexec- the executor service to use (can be null, then a default executor service is created- Throws:
IllegalArgumentException- if a required argument is missing
-
PeriodicReloadingTrigger
public PeriodicReloadingTrigger(ReloadingController ctrl, Object ctrlParam, long triggerPeriod, TimeUnit unit)
Creates a new instance ofPeriodicReloadingTriggerwith a default executor service.- Parameters:
ctrl- theReloadingController(must not be null)ctrlParam- the optional parameter to be passed to the controller when doing reloading checkstriggerPeriod- the period in which the controller is triggeredunit- the time unit for the period- Throws:
IllegalArgumentException- if a required argument is missing
-
-
Method Detail
-
start
public void start()
Starts this trigger. The associatedReloadingControllerwill be triggered according to the specified period. The first triggering happens after a period. If this trigger is already started, this invocation has no effect.
-
stop
public void stop()
Stops this trigger. The associatedReloadingControlleris no more triggered. If this trigger is already stopped, this invocation has no effect.
-
isRunning
public boolean isRunning()
Returns a flag whether this trigger is currently active.- Returns:
- a flag whether this trigger is running
-
shutdown
public void shutdown(boolean shutdownExecutor)
Shuts down this trigger and optionally shuts down theScheduledExecutorServiceused by this object. This method should be called if this trigger is no more needed. It ensures that the trigger is stopped. If the parameter is true, the executor service is also shut down. This should be done if this trigger is the only user of this executor service.- Parameters:
shutdownExecutor- a flag whether the associatedScheduledExecutorServiceis to be shut down
-
shutdown
public void shutdown()
Shuts down this trigger and itsScheduledExecutorService. This is a shortcut forshutdown(true).- See Also:
shutdown(boolean)
-
-