[cooja] plugins/sinks/TrafficVisualizerSkin: Synchronized to avoid ConcurrentModificationExcpetions

This commit is contained in:
Enrico Joerns 2014-06-25 17:02:01 +02:00
parent cd9164d5e2
commit d4f7cf6a83

View file

@ -73,18 +73,21 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
private Visualizer visualizer = null;
private AbstractRadioMedium radioMedium = null;
private List<RadioConnectionArrow> historyList = new LinkedList<>();
private final List<RadioConnectionArrow> historyList = new LinkedList<>();
private Observer radioMediumObserver = new Observer() {
@Override
public void update(Observable obs, Object obj) {
RadioConnection last = radioMedium.getLastConnection();
if (last != null && historyList.size() < MAX_HISTORY_SIZE) {
synchronized(historyList) {
historyList.add(new RadioConnectionArrow(last));
visualizer.repaint(500);
}
}
}
};
private final TimeEvent ageArrowsTimeEvent = new TimeEvent(0) {
@Override
public void execute(long t) {
@ -94,6 +97,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
if (historyList.size() > 0) {
synchronized (historyList) {
/* Increase age and remove too old arrows */
Iterator<RadioConnectionArrow> iter = historyList.iterator();
while (iter.hasNext()) {
@ -103,6 +107,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
iter.remove();
}
}
}
visualizer.repaint(500);
}
@ -182,6 +187,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
@Override
public void paintBeforeMotes(Graphics g) {
synchronized (historyList) {
for (RadioConnectionArrow connArrow : historyList) {
float colorHistoryIndex = 1.0f - connArrow.getAge();
Radio source = connArrow.getConnection().getSource();
@ -201,6 +207,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
}
}
}
}
@Override
public void paintAfterMotes(Graphics g) {