I have this data stream, roughly:
DataGenerator -> DataFormatter -> UI
DataGenerator is what quickly generates data; DataFormatter is what formats it for display; and the user interface is just a bunch of Swing elements.
I want to make my DataGenerator something like this:
class DataGenerator { final private PropertyChangeSupport pcs; ... public void addPropertyChangeListener(PropertyChangeListener pcl) { this.pcs.addPropertyChangeListener(pcl); } public void removePropertyChangeListener(PropertyChangeListener pcl) { this.pcs.removePropertyChangeListener(pcl); } }
and just call this.pcs.firePropertyChange(...)
when my data generator has new data; then I can just do dataGenerator.addPropertyListener(listener)
, where the listener
is responsible for redirecting the change to the DataFormatter and then to the user interface.
The problem with this approach is that there are thousands of changes to the DataGenerator per second (from 10,000 to 60,000 per second depending on my situation), and the computational cost of formatting it for the user interface is quite high, which makes it unnecessary to load my processor; in fact, everything that interests me visually is not more than 10-20 changes per second.
Is it possible to use a similar approach, but combine change events before they get into the DataFormatter? If I get several update events on the same topic, I just need to display the latest version and skip all the previous ones.
source share