From af128b65b599d09bfbabc837edca8280a64eb1df Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 21 Jun 2011 21:03:32 +0200 Subject: Make sure the connection control doesn't emit any events after disconnect is called git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@555 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/network/ConnectionControl.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index 785350e..b5886ca 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -157,14 +157,16 @@ public class ConnectionControl implements IConnectionControl { @Override public void disconnect() { + final Connection theConnection = connection; + connection = null; + connectedEvent = new Event(); connectionFailedEvent = new Event1(); run(new Runnable() { @Override public void run() { - if (connection != null) { - connection.disconnect(); - connection = null; + if (theConnection != null) { + theConnection.disconnect(); } ConnectionControl.this.run(STOP_ACTION); } @@ -502,6 +504,10 @@ public class ConnectionControl implements IConnectionControl { } private void processPacket(Packet packet) { + if (connection == null) { + return; + } + DefaultPacketExtension extension = (DefaultPacketExtension) packet .getExtension(ELEMENT_NAME, NAMESPACE); @@ -702,12 +708,15 @@ public class ConnectionControl implements IConnectionControl { private abstract class SendRunner implements Runnable { @Override public void run() { - if (connection != null) { + // For thread safety + Connection theConnection = connection; + + if (theConnection != null) { DefaultPacketExtension extension = createJRummikubExtension(); addData(extension); Message message = createMessage(extension); modifyMessage(message); - connection.sendPacket(message); + theConnection.sendPacket(message); } } -- cgit v1.2.3