diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-21 21:03:32 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-21 21:03:32 +0200 |
commit | af128b65b599d09bfbabc837edca8280a64eb1df (patch) | |
tree | 54e3629bd4e15ccecf335c67541f44d71911a988 /src/jrummikub/control | |
parent | 6acf9d6078d89eef5d2f2b19372b99baefd122af (diff) | |
download | JRummikub-af128b65b599d09bfbabc837edca8280a64eb1df.tar JRummikub-af128b65b599d09bfbabc837edca8280a64eb1df.zip |
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
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r-- | src/jrummikub/control/network/ConnectionControl.java | 19 |
1 files changed, 14 insertions, 5 deletions
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<LoginError>(); 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); } } |