mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-07-13 02:29:01 +00:00
[cooja] plugins/sinks/TrafficVisualizerSkin: Synchronized to avoid ConcurrentModificationExcpetions
This commit is contained in:
parent
cd9164d5e2
commit
d4f7cf6a83
@ -73,18 +73,21 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
|
|||||||
private Visualizer visualizer = null;
|
private Visualizer visualizer = null;
|
||||||
private AbstractRadioMedium radioMedium = null;
|
private AbstractRadioMedium radioMedium = null;
|
||||||
|
|
||||||
private List<RadioConnectionArrow> historyList = new LinkedList<>();
|
private final List<RadioConnectionArrow> historyList = new LinkedList<>();
|
||||||
|
|
||||||
private Observer radioMediumObserver = new Observer() {
|
private Observer radioMediumObserver = new Observer() {
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
RadioConnection last = radioMedium.getLastConnection();
|
RadioConnection last = radioMedium.getLastConnection();
|
||||||
if (last != null && historyList.size() < MAX_HISTORY_SIZE) {
|
if (last != null && historyList.size() < MAX_HISTORY_SIZE) {
|
||||||
|
synchronized(historyList) {
|
||||||
historyList.add(new RadioConnectionArrow(last));
|
historyList.add(new RadioConnectionArrow(last));
|
||||||
visualizer.repaint(500);
|
visualizer.repaint(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final TimeEvent ageArrowsTimeEvent = new TimeEvent(0) {
|
private final TimeEvent ageArrowsTimeEvent = new TimeEvent(0) {
|
||||||
@Override
|
@Override
|
||||||
public void execute(long t) {
|
public void execute(long t) {
|
||||||
@ -94,6 +97,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
|
|||||||
|
|
||||||
if (historyList.size() > 0) {
|
if (historyList.size() > 0) {
|
||||||
|
|
||||||
|
synchronized (historyList) {
|
||||||
/* Increase age and remove too old arrows */
|
/* Increase age and remove too old arrows */
|
||||||
Iterator<RadioConnectionArrow> iter = historyList.iterator();
|
Iterator<RadioConnectionArrow> iter = historyList.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
@ -103,6 +107,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
|
|||||||
iter.remove();
|
iter.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
visualizer.repaint(500);
|
visualizer.repaint(500);
|
||||||
}
|
}
|
||||||
@ -182,6 +187,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintBeforeMotes(Graphics g) {
|
public void paintBeforeMotes(Graphics g) {
|
||||||
|
synchronized (historyList) {
|
||||||
for (RadioConnectionArrow connArrow : historyList) {
|
for (RadioConnectionArrow connArrow : historyList) {
|
||||||
float colorHistoryIndex = 1.0f - connArrow.getAge();
|
float colorHistoryIndex = 1.0f - connArrow.getAge();
|
||||||
Radio source = connArrow.getConnection().getSource();
|
Radio source = connArrow.getConnection().getSource();
|
||||||
@ -201,6 +207,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintAfterMotes(Graphics g) {
|
public void paintAfterMotes(Graphics g) {
|
||||||
|
Loading…
Reference in New Issue
Block a user