Add proper handling for lost server connections
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@581 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
d2df76cae4
commit
ada8c1869c
8 changed files with 98 additions and 6 deletions
|
@ -54,6 +54,8 @@ public class MockConnectionControl implements IConnectionControl {
|
|||
/** */
|
||||
public MockEvent1<String> participantLeftEvent = new MockEvent1<String>();
|
||||
/** */
|
||||
public MockEvent connectionLostEvent = new MockEvent();
|
||||
/** */
|
||||
public GameData currentGame;
|
||||
/** */
|
||||
public GameData offeredGame;
|
||||
|
@ -177,6 +179,11 @@ public class MockConnectionControl implements IConnectionControl {
|
|||
return participantLeftEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getConnectionLostEvent() {
|
||||
return connectionLostEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offerGame(GameData data) {
|
||||
offeredGame = data;
|
||||
|
|
|
@ -79,6 +79,8 @@ public class MockView implements IView {
|
|||
/** */
|
||||
public MockEvent acknowledgeInvalidEvent = new MockEvent();
|
||||
/** */
|
||||
public MockEvent acknowledgeConnectionLostEvent = new MockEvent();
|
||||
/** */
|
||||
public MockEvent1<File> loadFileEvent = new MockEvent1<File>();
|
||||
|
||||
@Override
|
||||
|
@ -116,6 +118,11 @@ public class MockView implements IView {
|
|||
return acknowledgeInvalidEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getAcknowledgeConnectionLostEvent() {
|
||||
return acknowledgeConnectionLostEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getEndProgramEvent() {
|
||||
return quitEvent;
|
||||
|
@ -173,7 +180,7 @@ public class MockView implements IView {
|
|||
|
||||
@Override
|
||||
public void showSidePanel(boolean show) {
|
||||
isSidePanelVisible=show;
|
||||
isSidePanelVisible = show;
|
||||
}
|
||||
|
||||
public void showQuitWarningPanel(boolean show) {
|
||||
|
@ -192,7 +199,7 @@ public class MockView implements IView {
|
|||
|
||||
@Override
|
||||
public void showConnectPanel(boolean show) {
|
||||
isConnectPanelVisible=show;
|
||||
isConnectPanelVisible = show;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -261,6 +263,11 @@ public class ConnectionControl implements IConnectionControl {
|
|||
return participantLeftEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getConnectionLostEvent() {
|
||||
return connectionLostEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offerGame(GameData data) {
|
||||
offeredGame = 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) {
|
||||
|
|
|
@ -54,6 +54,8 @@ interface IConnectionControl {
|
|||
|
||||
public IEvent1<String> getParticipantLeftEvent();
|
||||
|
||||
public IEvent getConnectionLostEvent();
|
||||
|
||||
public void offerGame(GameData data);
|
||||
|
||||
public void withdrawGame();
|
||||
|
|
|
@ -15,7 +15,6 @@ import jrummikub.util.IEvent;
|
|||
import jrummikub.util.IListener;
|
||||
import jrummikub.util.IListener1;
|
||||
import jrummikub.util.LoginData;
|
||||
import jrummikub.view.IQuitWarningPanel.QuitMode;
|
||||
import jrummikub.view.IView;
|
||||
import jrummikub.view.IView.BottomPanelType;
|
||||
import jrummikub.view.LoginError;
|
||||
|
@ -141,6 +140,23 @@ public class NetworkControl {
|
|||
}
|
||||
}
|
||||
}));
|
||||
connections.add(connectionControl.getConnectionLostEvent().add(
|
||||
new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
abort();
|
||||
view.setBottomPanel(BottomPanelType.NETWORK_SERVER_CONNECTION_LOST_PANEL);
|
||||
connections.add(view.getAcknowledgeConnectionLostEvent().add(
|
||||
new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
abort();
|
||||
view.setBottomPanel(BottomPanelType.START_GAME_PANEL);
|
||||
backToLoginEvent.emit();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void addOfferUpdateListener() {
|
||||
|
@ -342,6 +358,13 @@ public class NetworkControl {
|
|||
view.showGameListPanel(true);
|
||||
}
|
||||
});
|
||||
gameControl.getEndOfGameEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
view.setBottomPanel(BottomPanelType.START_GAME_PANEL);
|
||||
view.showGameListPanel(true);
|
||||
}
|
||||
});
|
||||
|
||||
gameControl.startGame();
|
||||
}
|
||||
|
|
|
@ -86,7 +86,9 @@ public interface IView {
|
|||
*
|
||||
* @return the event
|
||||
*/
|
||||
IEvent getAcknowledgeInvalidEvent();
|
||||
public IEvent getAcknowledgeInvalidEvent();
|
||||
|
||||
public IEvent getAcknowledgeConnectionLostEvent();
|
||||
|
||||
/**
|
||||
* The quit event is emitted when the player wants to quit the game
|
||||
|
@ -367,6 +369,6 @@ public interface IView {
|
|||
* Different types of bottom panels
|
||||
*/
|
||||
public enum BottomPanelType {
|
||||
START_GAME_PANEL, START_TURN_PANEL, START_REDEAL_TURN_PANEL, START_LAST_TURN_PANEL, INVALID_TURN_PANEL, HUMAN_HAND_PANEL, NONHUMAN_HAND_PANEL, WIN_PANEL, NETWORK_WIN_PANEL, NETWORK_CONNECTION_LOST_PANEL
|
||||
START_GAME_PANEL, START_TURN_PANEL, START_REDEAL_TURN_PANEL, START_LAST_TURN_PANEL, INVALID_TURN_PANEL, HUMAN_HAND_PANEL, NONHUMAN_HAND_PANEL, WIN_PANEL, NETWORK_WIN_PANEL, NETWORK_CONNECTION_LOST_PANEL, NETWORK_SERVER_CONNECTION_LOST_PANEL
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ class StartTurnPanel extends JPanel {
|
|||
|
||||
private Event startTurnEvent = new Event();
|
||||
private Event acknowledgeInvalidEvent = new Event();
|
||||
private Event acknowledgeConnectionLostEvent = new Event();
|
||||
|
||||
private Event buttonEvent = startTurnEvent;
|
||||
private BottomPanelType type;
|
||||
|
@ -97,6 +98,10 @@ class StartTurnPanel extends JPanel {
|
|||
return acknowledgeInvalidEvent;
|
||||
}
|
||||
|
||||
IEvent getAcknowledgeConnectionLostEvent() {
|
||||
return acknowledgeConnectionLostEvent;
|
||||
}
|
||||
|
||||
private void rescale() {
|
||||
Insets insets = getInsets();
|
||||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
||||
|
@ -184,6 +189,13 @@ class StartTurnPanel extends JPanel {
|
|||
startTurnButton.setText("N\u00E4chster Spieler");
|
||||
buttonEvent = acknowledgeInvalidEvent;
|
||||
break;
|
||||
|
||||
case NETWORK_SERVER_CONNECTION_LOST_PANEL:
|
||||
startTurnLabel.setIcon(null);
|
||||
startTurnLabel.setText("Die Verbindung zum Server wurde getrennt.");
|
||||
startTurnButton.setText("OK");
|
||||
buttonEvent = acknowledgeConnectionLostEvent;
|
||||
break;
|
||||
}
|
||||
|
||||
rescale();
|
||||
|
|
|
@ -604,6 +604,11 @@ public class View extends JFrame implements IView {
|
|||
return startTurnPanel.getAcknowledgeInvalidEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getAcknowledgeConnectionLostEvent() {
|
||||
return startTurnPanel.getAcknowledgeConnectionLostEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getNewRoundEvent() {
|
||||
return roundEndPanel.getNewRoundEvent();
|
||||
|
@ -667,7 +672,8 @@ public class View extends JFrame implements IView {
|
|||
private void doSetBottomPanel(BottomPanelType type) {
|
||||
boolean showStartTurnPanel = (type == BottomPanelType.START_TURN_PANEL
|
||||
|| type == BottomPanelType.START_REDEAL_TURN_PANEL
|
||||
|| type == BottomPanelType.START_LAST_TURN_PANEL || type == BottomPanelType.INVALID_TURN_PANEL);
|
||||
|| type == BottomPanelType.START_LAST_TURN_PANEL
|
||||
|| type == BottomPanelType.INVALID_TURN_PANEL || type == BottomPanelType.NETWORK_SERVER_CONNECTION_LOST_PANEL);
|
||||
startTurnPanel.setType(type);
|
||||
startTurnPanel.setVisible(showStartTurnPanel);
|
||||
|
||||
|
|
Reference in a new issue