mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
connection: improved error processing and stability in connect dialog
This commit is contained in:
parent
adf57a0677
commit
0b0e947741
6 changed files with 55 additions and 24 deletions
|
|
@ -34,7 +34,7 @@ public class MageUI {
|
|||
super.afterExecute(r, t);
|
||||
|
||||
// catch errors in popup threads (example: card popup over cards or chat/log messages)
|
||||
t = ThreadUtils.findRealException(r, t);
|
||||
t = ThreadUtils.findRunnableException(r, t);
|
||||
if (t != null && !(t instanceof CancellationException)) {
|
||||
logger.error("Catch unhandled error in POPUP thread: " + t.getMessage(), t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import mage.client.util.gui.countryBox.CountryItemEditor;
|
|||
import mage.client.util.sets.ConstructedFormats;
|
||||
import mage.remote.Connection;
|
||||
import mage.utils.StreamUtils;
|
||||
import mage.utils.ThreadUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
|
|
@ -61,6 +62,7 @@ public class ConnectDialog extends MageDialog {
|
|||
}
|
||||
|
||||
public void showDialog() {
|
||||
this.lblStatus.setText("");
|
||||
String serverAddress = MagePreferences.getServerAddressWithDefault(ClientDefaultSettings.serverName);
|
||||
this.txtServer.setText(serverAddress);
|
||||
this.txtPort.setText(Integer.toString(MagePreferences.getServerPortWithDefault(ClientDefaultSettings.port)));
|
||||
|
|
@ -83,6 +85,7 @@ public class ConnectDialog extends MageDialog {
|
|||
}
|
||||
|
||||
private void saveSettings() {
|
||||
ThreadUtils.sleep(3000);
|
||||
String serverAddress = txtServer.getText().trim();
|
||||
MagePreferences.setServerAddress(serverAddress);
|
||||
MagePreferences.setServerPort(Integer.parseInt(txtPort.getText().trim()));
|
||||
|
|
@ -678,8 +681,10 @@ public class ConnectDialog extends MageDialog {
|
|||
|
||||
@Override
|
||||
protected Boolean doInBackground() throws Exception {
|
||||
lblStatus.setText("Connecting...");
|
||||
setConnectButtonsState(false);
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
lblStatus.setText("Connecting...");
|
||||
setConnectButtonsState(false);
|
||||
});
|
||||
result = MageFrame.connect(connection);
|
||||
lastConnectError = SessionHandler.getLastConnectError();
|
||||
return result;
|
||||
|
|
@ -688,32 +693,44 @@ public class ConnectDialog extends MageDialog {
|
|||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
if (result) {
|
||||
lblStatus.setText("");
|
||||
connected();
|
||||
MageFrame.getInstance().prepareAndShowTablesPane();
|
||||
} else {
|
||||
lblStatus.setText("Could not connect: " + lastConnectError);
|
||||
}
|
||||
get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS); // catch exceptions
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if (result) {
|
||||
lblStatus.setText("Connected");
|
||||
|
||||
// for ux: after connection client can load additional resources and data,
|
||||
// so the connection dialog will be visible all that time
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
doAfterConnected();
|
||||
MageFrame.getInstance().prepareAndShowTablesPane();
|
||||
btnConnect.setEnabled(true);
|
||||
});
|
||||
} else {
|
||||
lblStatus.setText("Could not connect: " + lastConnectError);
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
logger.fatal("Update Players Task error", ex);
|
||||
logger.fatal("Connection: can't load data from server", ex);
|
||||
} catch (CancellationException ex) {
|
||||
logger.info("Connect: canceled");
|
||||
lblStatus.setText("Connect was canceled");
|
||||
} catch (TimeoutException ex) {
|
||||
logger.fatal("Connection timeout: ", ex);
|
||||
logger.fatal("Connection: timeout", ex);
|
||||
} finally {
|
||||
MageFrame.stopConnecting();
|
||||
setConnectButtonsState(true);
|
||||
if (!result) {
|
||||
MageFrame.stopConnecting();
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
setConnectButtonsState(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void connected() {
|
||||
private void doAfterConnected() {
|
||||
this.saveSettings();
|
||||
this.hideDialog();
|
||||
ConstructedFormats.ensureLists();
|
||||
}
|
||||
|
||||
private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class LinePool {
|
|||
@Override
|
||||
protected void afterExecute(Runnable r, Throwable t) {
|
||||
super.afterExecute(r, t);
|
||||
t = ThreadUtils.findRealException(r, t);
|
||||
t = ThreadUtils.findRunnableException(r, t);
|
||||
if (t != null && !(t instanceof CancellationException)) {
|
||||
// TODO: show sound errors in client logs?
|
||||
//logger.error("Catch unhandled error in SOUND thread: " + t.getMessage(), t);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue