For Issue#524: added connect task timeout, reduced number of auto connection retries to one

This commit is contained in:
magenoxx 2014-08-20 08:25:30 +04:00
parent 089a990b26
commit 3454b2db8a
2 changed files with 11 additions and 3 deletions

View file

@ -54,6 +54,8 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -321,6 +323,8 @@ public class ConnectDialog extends MageDialog {
private boolean result = false; private boolean result = false;
private static final int CONNECTION_TIMEOUT_MS = 2100;
@Override @Override
protected Boolean doInBackground() throws Exception { protected Boolean doInBackground() throws Exception {
lblStatus.setText("Connecting..."); lblStatus.setText("Connecting...");
@ -332,7 +336,7 @@ public class ConnectDialog extends MageDialog {
@Override @Override
protected void done() { protected void done() {
try { try {
get(); get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if (result) { if (result) {
lblStatus.setText(""); lblStatus.setText("");
@ -348,8 +352,10 @@ public class ConnectDialog extends MageDialog {
} catch (CancellationException ex) { } catch (CancellationException ex) {
logger.info("Connect was canceled"); logger.info("Connect was canceled");
lblStatus.setText("Connect was canceled"); lblStatus.setText("Connect was canceled");
MageFrame.stopConnecting(); } catch (TimeoutException ex) {
logger.fatal("Connection timeout: ", ex);
} finally { } finally {
MageFrame.stopConnecting();
btnConnect.setEnabled(true); btnConnect.setEnabled(true);
} }
} }

View file

@ -36,6 +36,7 @@ import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository; import mage.cards.repository.ExpansionRepository;
import mage.constants.Constants.SessionState; import mage.constants.Constants.SessionState;
import mage.constants.ManaType;
import mage.game.GameException; import mage.game.GameException;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions; import mage.game.tournament.TournamentOptions;
@ -56,7 +57,6 @@ import org.jboss.remoting.transporter.TransporterClient;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import mage.constants.ManaType;
/** /**
* *
@ -159,6 +159,8 @@ public class SessionImpl implements Session {
* the server, and on the server side an org.jboss.remoting.Lease informs registered listeners * the server, and on the server side an org.jboss.remoting.Lease informs registered listeners
* if the PING doesn't arrive withing the specified timeout period. */ * if the PING doesn't arrive withing the specified timeout period. */
clientMetadata.put(Client.ENABLE_LEASE, "true"); clientMetadata.put(Client.ENABLE_LEASE, "true");
clientMetadata.put("numberOfCallRetries", "1");
// Indicated the max number of threads used within oneway thread pool. // Indicated the max number of threads used within oneway thread pool.
clientMetadata.put(Client.MAX_NUM_ONEWAY_THREADS, "10"); clientMetadata.put(Client.MAX_NUM_ONEWAY_THREADS, "10");
clientMetadata.put(Remoting.USE_CLIENT_CONNECTION_IDENTITY, "true"); clientMetadata.put(Remoting.USE_CLIENT_CONNECTION_IDENTITY, "true");