summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java19
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);
}
}