diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-22 07:04:15 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-22 07:04:15 +0200 |
commit | ada8c1869c5b2b007e690e4c028fd20b34a41706 (patch) | |
tree | 894a27b7f4f7ae874c53882690c45805d5780a44 /src/jrummikub/control/network/ConnectionControl.java | |
parent | d2df76cae49bf31b28d422b5ddfbfb5b1e7651d0 (diff) | |
download | JRummikub-ada8c1869c5b2b007e690e4c028fd20b34a41706.tar JRummikub-ada8c1869c5b2b007e690e4c028fd20b34a41706.zip |
Add proper handling for lost server connections
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@581 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/network/ConnectionControl.java')
-rw-r--r-- | src/jrummikub/control/network/ConnectionControl.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index 7491938..0de8776 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -25,6 +25,7 @@ import jrummikub.view.LoginError; import org.jivesoftware.smack.Connection; import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.ConnectionListener; import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; @@ -117,6 +118,7 @@ public class ConnectionControl implements IConnectionControl { private Event turnStartEvent = new Event(); private Event1<String> participantLeftEvent = new Event1<String>(); + private Event connectionLostEvent = new Event(); private GameData currentGame; @@ -262,6 +264,11 @@ public class ConnectionControl implements IConnectionControl { } @Override + public IEvent getConnectionLostEvent() { + return connectionLostEvent; + } + + @Override public void offerGame(GameData data) { offeredGame = data; currentGame = data; @@ -612,6 +619,7 @@ public class ConnectionControl implements IConnectionControl { config.setSendPresence(false); config.setRosterLoadedAtLogin(false); config.setCompressionEnabled(true); + config.setReconnectionAllowed(false); connection = new XMPPConnection(config); @@ -651,6 +659,7 @@ public class ConnectionControl implements IConnectionControl { private LoginError doConnect() { try { connection.connect(); + connection.addConnectionListener(new DisconnectListener()); return null; } catch (XMPPException e) { XMPPError xmppError = e.getXMPPError(); @@ -714,6 +723,30 @@ public class ConnectionControl implements IConnectionControl { return null; } + private class DisconnectListener implements ConnectionListener { + @Override + public void connectionClosed() { + emitLater(connectionLostEvent); + } + + @Override + public void connectionClosedOnError(Exception arg0) { + connectionClosed(); + } + + @Override + public void reconnectingIn(int arg0) { + } + + @Override + public void reconnectionFailed(Exception arg0) { + } + + @Override + public void reconnectionSuccessful() { + } + } + private class LeaveListener implements ParticipantStatusListener { @Override public void voiceRevoked(String arg0) { |