Package de.gsi.dataset.event
Class EventRateLimiter
- java.lang.Object
-
- de.gsi.dataset.event.EventRateLimiter
-
- All Implemented Interfaces:
EventListener
public class EventRateLimiter extends java.lang.Object implements EventListener
EventRateLimiter that acts as anEventListenerand forwards the receivedUpdateEvents to a secondaryEventListenerat 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));- Author:
- rstein
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classEventRateLimiter.DelayedUpdateTaskstatic classEventRateLimiter.UpdateStrategyEventRateLimter UpdateStrategyEventRateLimiter.UpdateStrategy.INSTANTANEOUS_RATEnotify if the time w.r.t.
-
Constructor Summary
Constructors Constructor Description EventRateLimiter(EventListener eventListener, long minUpdatePeriod)EventRateLimiter(EventListener eventListener, long minUpdatePeriod, EventRateLimiter.UpdateStrategy updateStrategy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetRateEstimate()voidhandle(UpdateEvent event)This method needs to be provided by an implementation ofUpdateListener.
-
-
-
Constructor Detail
-
EventRateLimiter
public EventRateLimiter(EventListener eventListener, long minUpdatePeriod)
- Parameters:
eventListener- the secondary event listener that should be called if the time-out or rate-limited is not activatedminUpdatePeriod- the minimum time in milliseconds. WithEventRateLimiter.UpdateStrategy.INSTANTANEOUS_RATEthis implies a minimum update time-out defaults toEventRateLimiter.UpdateStrategy.INSTANTANEOUS_RATE, seeEventRateLimiter.UpdateStrategyfor details
-
EventRateLimiter
public EventRateLimiter(EventListener eventListener, long minUpdatePeriod, EventRateLimiter.UpdateStrategy updateStrategy)
- Parameters:
eventListener- the secondary event listener that should be called if the time-out or rate-limited is not activatedminUpdatePeriod- the minimum time in milliseconds. WithEventRateLimiter.UpdateStrategy.INSTANTANEOUS_RATEthis implies a minimum update time-outupdateStrategy- if null defaults toEventRateLimiter.UpdateStrategy.INSTANTANEOUS_RATE, seeEventRateLimiter.UpdateStrategyfor details
-
-
Method Detail
-
getRateEstimate
public double getRateEstimate()
-
handle
public void handle(UpdateEvent event)
Description copied from interface:EventListenerThis method needs to be provided by an implementation ofUpdateListener. It is called if anEventSourcehas been modified/updated.In general is is considered bad practice to modify the observed value in this method.
- Specified by:
handlein interfaceEventListener- Parameters:
event- TheUpdateEventissued by the modifiedUpdateSource
-
-