public class ReloadingController extends Object implements EventSource
A class for adding support for reload operations in a generic way.
ReloadingController monitors a specific source and triggers
reloading 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:
ReloadingControllerinstance is created and initialized with a
EventListenerobjects for reloading events can be registered at the controller.
checkForReloading()method is called whenever 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.
resetReloadingState()method must be called. It tells the controller that the last notification has been processed and that new checks are possible again. It is important that this method is called. Otherwise,
checkForReloading()will not do any new checks or send out event notifications any more.
This class can be accessed from multiple threads concurrently. It shields the
ReloadingDetector object for concurrent access, so that a
concrete detector implementation does not have to be thread-safe.
|Constructor and Description|
Creates a new instance of
|Modifier and Type||Method and Description|
Adds an event listener for the specified event type.
Performs a check whether a reload operation is necessary.
Tests whether this controller is in reloading state.
Removes the event listener registration for the given event type and listener.
Resets the reloading state.
public ReloadingController(ReloadingDetector detect)
ReloadingControllerand associates it with the given
ReloadingDetector(must not be null)
IllegalArgumentException- if the detector is undefined
public ReloadingDetector getDetector()
ReloadingDetectorused by this controller.
public <T extends Event> void addEventListener(EventType<T> eventType, EventListener<? super T> listener)
public <T extends Event> boolean removeEventListener(EventType<T> eventType, EventListener<? super T> listener)
public boolean isInReloadingState()
checkForReloading()has detected the necessity for a reload operation, but
resetReloadingState()has not been called yet. In this state no further reloading checks are possible.
public boolean checkForReloading(Object data)
ReloadingDetectorand sends out notifications if necessary. The argument can be an arbitrary data object; it will be part of the event notification sent out when a reload operation should be performed. The return value indicates whether a change was detected and an event was sent. Once a need for a reload is detected, this controller is in reloading state. Until this state is reset (by calling
resetReloadingState()), no further reloading checks are performed by this method, and no events are fired; it then returns always true.
data- additional data for an event notification
public void resetReloadingState()
Copyright © 2001–2020 The Apache Software Foundation. All rights reserved.