public class EventRateLimiter extends Object implements EventListener
EventListener and forwards the received UpdateEvents to a secondary
EventListener at a predefined maximum rate. This class may be useful in an UI contexts where the
visualisation cannot be updated in time due to its numerical complexity, or for contexts where the numerical
post-processing can be skipped or dropped if new UpdateEvents arrive.
Basic usage:
evtSource.addListener(new EventRateLimiter(evt -> { ... do stuff with the event ... }, MAX_UPDATE_PERIOD));
// or, more explicitly:
evtSource.addListener(new EventRateLimiter(evt -> { ... do stuff with the event ... }, MAX_UPDATE_PERIOD,
UpdateStrategy.INSTANTANEOUS_RATE));
| Modifier and Type | Class and Description |
|---|---|
protected class |
EventRateLimiter.DelayedUpdateTask |
static class |
EventRateLimiter.UpdateStrategy
EventRateLimter UpdateStrategy
EventRateLimiter.UpdateStrategy.INSTANTANEOUS_RATE notify if the time w.r.t. |
| Constructor and Description |
|---|
EventRateLimiter(EventListener eventListener,
long minUpdatePeriod) |
EventRateLimiter(EventListener eventListener,
long minUpdatePeriod,
EventRateLimiter.UpdateStrategy updateStrategy) |
| Modifier and Type | Method and Description |
|---|---|
double |
getRateEstimate() |
void |
handle(UpdateEvent event)
This method needs to be provided by an implementation of
UpdateListener. |
public EventRateLimiter(EventListener eventListener, long minUpdatePeriod)
eventListener - the secondary event listener that should be called if the time-out or rate-limited is not
activatedminUpdatePeriod - the minimum time in milliseconds. With EventRateLimiter.UpdateStrategy.INSTANTANEOUS_RATE this implies
a minimum update time-out
defaults to EventRateLimiter.UpdateStrategy.INSTANTANEOUS_RATE, see EventRateLimiter.UpdateStrategy for detailspublic EventRateLimiter(EventListener eventListener, long minUpdatePeriod, EventRateLimiter.UpdateStrategy updateStrategy)
eventListener - the secondary event listener that should be called if the time-out or rate-limited is not
activatedminUpdatePeriod - the minimum time in milliseconds. With EventRateLimiter.UpdateStrategy.INSTANTANEOUS_RATE this implies
a minimum update time-outupdateStrategy - if null defaults to EventRateLimiter.UpdateStrategy.INSTANTANEOUS_RATE, see EventRateLimiter.UpdateStrategy for
detailspublic double getRateEstimate()
public void handle(UpdateEvent event)
EventListenerUpdateListener. It is called if an
EventSource has been modified/updated.
In general is is considered bad practice to modify the observed value in this method.
handle in interface EventListenerevent - The UpdateEvent issued by the modified UpdateSourceCopyright © 2020 GSI Helmholtzzentrum für Schwerionenforschung GmbH. All rights reserved.