Browse Source

Fixes concurrent Modification errors

Andreas T. Meyer-Berg 6 năm trước cách đây
mục cha
commit
d1bd75bf72

+ 9 - 3
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/Controller.java

@@ -600,8 +600,10 @@ public class Controller {
 	 */
 	public void deleteConnection(Connection c) {
 		if(c == null)return;
-		for(Port p:c.getParticipants())
+		LinkedList<Port> ports = new LinkedList<Port>(c.getParticipants());
+		for(Port p:ports)
 			removeDeviceFromConnection(p, c);
+		ports.clear();
 		removeConnectionFromLink(c, c.getLink());
 		c.setStatus(Connection.TERMINATED);
 		removeConnection(c);
@@ -613,10 +615,14 @@ public class Controller {
 	 */
 	public void deleteLink(Link l) {
 		if(l==null)return;
-		for(SmartDevice d : l.getDevices())
+		LinkedList<SmartDevice> devices = new LinkedList<SmartDevice>(l.getDevices());
+		for(SmartDevice d : devices)
 			removeLinkFromDevice(l, d);
-		for(Connection c:l.getConnections())
+		devices.clear();
+		LinkedList<Connection> connections = new LinkedList<Connection>(l.getConnections());
+		for(Connection c:connections)
 			removeConnectionFromLink(c,l);
+		connections.clear();
 		l.getPackets().clear();
 		removeLink(l);
 	}