From 35791ac6b77ba20590335535e89f1fb15f212e69 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 17 Apr 2017 00:01:39 +0200 Subject: [PATCH] Set SocketWriteTimeout to 10 seconds. --- .../src/main/java/mage/client/MageFrame.java | 33 ++-- Mage.Common/src/mage/remote/Connection.java | 7 +- Mage.Common/src/mage/remote/SessionImpl.java | 71 ++++--- Mage.Server/config/config.xml | 2 + Mage.Server/release/config/config.xml | 2 + .../src/main/java/mage/server/Main.java | 16 +- .../java/mage/server/util/ConfigSettings.java | 9 +- .../mage/server/util/resources/config.xml | 1 + .../main/xml-resources/jaxb/Config/Config.xsd | 177 +++++++++--------- 9 files changed, 164 insertions(+), 154 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/MageFrame.java b/Mage.Client/src/main/java/mage/client/MageFrame.java index 18f1713533..3d6d685e4c 100644 --- a/Mage.Client/src/main/java/mage/client/MageFrame.java +++ b/Mage.Client/src/main/java/mage/client/MageFrame.java @@ -27,6 +27,21 @@ */ package mage.client; +import java.awt.*; +import java.awt.event.*; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.prefs.Preferences; +import javax.imageio.ImageIO; +import javax.swing.*; +import javax.swing.event.PopupMenuEvent; +import javax.swing.event.PopupMenuListener; import mage.cards.decks.Deck; import mage.cards.repository.CardCriteria; import mage.cards.repository.CardInfo; @@ -77,22 +92,6 @@ import org.mage.plugins.card.images.DownloadPictures; import org.mage.plugins.card.info.CardInfoPaneImpl; import org.mage.plugins.card.utils.impl.ImageManagerImpl; -import javax.imageio.ImageIO; -import javax.swing.*; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import java.awt.*; -import java.awt.event.*; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; -import java.util.*; -import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.prefs.Preferences; - /** * @author BetaSteward_at_googlemail.com */ @@ -1056,7 +1055,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { // use already open editor Component[] windows = desktopPane.getComponentsInLayer(JLayeredPane.DEFAULT_LAYER); for (Component window : windows) { - if (window instanceof DeckEditorPane && ((MagePane)window).getTitle().equals(name)) { + if (window instanceof DeckEditorPane && ((MagePane) window).getTitle().equals(name)) { setActive((MagePane) window); return; } diff --git a/Mage.Common/src/mage/remote/Connection.java b/Mage.Common/src/mage/remote/Connection.java index 3dca8ebdfd..cfd27d1812 100644 --- a/Mage.Common/src/mage/remote/Connection.java +++ b/Mage.Common/src/mage/remote/Connection.java @@ -56,6 +56,7 @@ public class Connection { private int clientCardDatabaseVersion; private boolean forceDBComparison; private String userIdStr; + private int socketWriteTimeout; private UserData userData; @@ -76,6 +77,7 @@ public class Connection { public Connection(String parameter) { this.parameter = parameter; + socketWriteTimeout = 10000; } @Override @@ -276,7 +278,6 @@ public class Connection { return allMACs.toString(); } - public void setUserData(UserData userData) { this.userData = userData; } @@ -292,4 +293,8 @@ public class Connection { public void setForceDBComparison(boolean forceDBComparison) { this.forceDBComparison = forceDBComparison; } + + public int getSocketWriteTimeout() { + return socketWriteTimeout; + } } diff --git a/Mage.Common/src/mage/remote/SessionImpl.java b/Mage.Common/src/mage/remote/SessionImpl.java index b2c46a9396..90e68afb91 100644 --- a/Mage.Common/src/mage/remote/SessionImpl.java +++ b/Mage.Common/src/mage/remote/SessionImpl.java @@ -27,6 +27,12 @@ */ package mage.remote; +import java.io.IOException; +import java.lang.reflect.UndeclaredThrowableException; +import java.net.*; +import java.util.*; +import java.util.concurrent.TimeUnit; +import javax.swing.*; import mage.MageException; import mage.cards.decks.DeckCardLists; import mage.cards.decks.InvalidDeckException; @@ -56,13 +62,6 @@ import org.jboss.remoting.transport.bisocket.Bisocket; import org.jboss.remoting.transport.socket.SocketWrapper; import org.jboss.remoting.transporter.TransporterClient; -import javax.swing.*; -import java.io.IOException; -import java.lang.reflect.UndeclaredThrowableException; -import java.net.*; -import java.util.*; -import java.util.concurrent.TimeUnit; - /** * @author BetaSteward_at_googlemail.com */ @@ -220,34 +219,35 @@ public class SessionImpl implements Session { public synchronized boolean connect(final Connection connection) { return establishJBossRemotingConnection(connection) && handleRemotingTaskExceptions(new RemotingTask() { - @Override - public boolean run() throws Throwable { - logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ':' + connection.getPort()); - boolean registerResult; - if (connection.getAdminPassword() == null) { - // for backward compatibility. don't remove twice call - first one does nothing but for version checking - registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion(), connection.getUserIdStr()); - if (registerResult) { - server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr()); + @Override + public boolean run() throws Throwable { + logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ':' + connection.getPort()); + boolean registerResult; + if (connection.getAdminPassword() == null) { + // for backward compatibility. don't remove twice call - first one does nothing but for version checking + registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion(), connection.getUserIdStr()); + if (registerResult) { + server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr()); + } + } else { + registerResult = server.connectAdmin(connection.getAdminPassword(), sessionId, client.getVersion()); + } + if (registerResult) { + serverState = server.getServerState(); + if (!connection.getUsername().equals("Admin")) { + updateDatabase(connection.isForceDBComparison(), serverState); + } + logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ':' + connection.getPort()); + client.connected(getUserName() + '@' + connection.getHost() + ':' + connection.getPort() + ' '); + return true; + } + disconnect(false); + return false; } - } else { - registerResult = server.connectAdmin(connection.getAdminPassword(), sessionId, client.getVersion()); - } - if (registerResult) { - serverState = server.getServerState(); - if (!connection.getUsername().equals("Admin")) { - updateDatabase(connection.isForceDBComparison(), serverState); - } - logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ':' + connection.getPort()); - client.connected(getUserName() + '@' + connection.getHost() + ':' + connection.getPort() + ' '); - return true; - } - disconnect(false); - return false; - } - }); + }); } + @Override public Optional getServerHostname() { return isConnected() ? Optional.of(connection.getHost()) : Optional.empty(); } @@ -305,14 +305,14 @@ public class SessionImpl implements Session { to a value greater than 1, an invocation interrupted by a write timeout can be retried. Note. The write timeout facility applies to writing of both invocations and responses. It applies to push callbacks as well. */ - metadata.put(SocketWrapper.WRITE_TIMEOUT, "2000"); + metadata.put(SocketWrapper.WRITE_TIMEOUT, String.valueOf(connection.getSocketWriteTimeout())); metadata.put("generalizeSocketException", "true"); server = (MageServer) TransporterClient.createTransporterClient(clientLocator.getLocatorURI(), MageServer.class, metadata); // http://docs.jboss.org/jbossremoting/docs/guide/2.5/html_single/#d0e1057 Map clientMetadata = new HashMap<>(); - clientMetadata.put(SocketWrapper.WRITE_TIMEOUT, "2000"); + clientMetadata.put(SocketWrapper.WRITE_TIMEOUT, String.valueOf(connection.getSocketWriteTimeout())); /* generalizeSocketException * If set to false, a failed invocation will be retried in the case of * SocketExceptions. If set to true, a failed invocation will be retried in the case of @@ -473,7 +473,7 @@ public class SessionImpl implements Session { /** * @param askForReconnect - true = connection was lost because of error and - * ask the user if he want to try to reconnect + * ask the user if he want to try to reconnect */ @Override public synchronized void disconnect(boolean askForReconnect) { @@ -967,7 +967,6 @@ public class SessionImpl implements Session { return false; } - @Override public boolean joinGame(UUID gameId) { try { diff --git a/Mage.Server/config/config.xml b/Mage.Server/config/config.xml index 458c3c1772..46c1bf4232 100644 --- a/Mage.Server/config/config.xml +++ b/Mage.Server/config/config.xml @@ -12,6 +12,7 @@ leasePeriod - To turn on server side connection failure detection of remoting clients, it is necessary to satisfy two criteria. The first is that the client lease period is set and is a value greater than 0. The value is represented in milliseconds. The client lease period can be set by either the 'clientLeasePeriod' attribute within the Connector configuration or by calling the Connector method + socketWriteTimeout - All write operations will time out if they do not complete within the configured period. maxGameThreads - Number of games that can be started simultanously on the server maxSecondsIdle - Number of seconds after that a game is auto conceded by the player that was idle for such a time minUserNameLength - minmal allowed length of a user name to connect to the server @@ -40,6 +41,7 @@ numAcceptThreads="2" maxPoolSize="300" leasePeriod="5000" + socketWriteTimeout="10000" maxGameThreads="10" maxSecondsIdle="600" minUserNameLength="3" diff --git a/Mage.Server/release/config/config.xml b/Mage.Server/release/config/config.xml index eecf481863..dbd3408663 100644 --- a/Mage.Server/release/config/config.xml +++ b/Mage.Server/release/config/config.xml @@ -12,6 +12,7 @@ leasePeriod - To turn on server side connection failure detection of remoting clients, it is necessary to satisfy two criteria. The first is that the client lease period is set and is a value greater than 0. The value is represented in milliseconds. The client lease period can be set by either the 'clientLeasePeriod' attribute within the Connector configuration or by calling the Connector method + socketWriteTimeout - All write operations will time out if they do not complete within the configured period. maxGameThreads - Number of games that can be started simultanously on the server maxSecondsIdle - Number of seconds after that a game is auto conceded by the player that was idle for such a time minUserNameLength - minmal allowed length of a user name to connect to the server @@ -39,6 +40,7 @@ numAcceptThreads="2" maxPoolSize="300" leasePeriod="5000" + socketWriteTimeout="10000" maxGameThreads="10" maxSecondsIdle="600" minUserNameLength="3" diff --git a/Mage.Server/src/main/java/mage/server/Main.java b/Mage.Server/src/main/java/mage/server/Main.java index 52fe274ae1..713517fc59 100644 --- a/Mage.Server/src/main/java/mage/server/Main.java +++ b/Mage.Server/src/main/java/mage/server/Main.java @@ -27,6 +27,12 @@ */ package mage.server; +import java.io.File; +import java.io.IOException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.util.*; +import javax.management.MBeanServer; import mage.cards.ExpansionSet; import mage.cards.Sets; import mage.cards.repository.CardScanner; @@ -59,13 +65,6 @@ import org.jboss.remoting.transporter.TransporterClient; import org.jboss.remoting.transporter.TransporterServer; import org.w3c.dom.Element; -import javax.management.MBeanServer; -import java.io.File; -import java.io.IOException; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.util.*; - /** * @author BetaSteward_at_googlemail.com */ @@ -202,6 +201,7 @@ public final class Main { logger.info("Config - save game active: " + (config.isSaveGameActivated() ? "true" : "false")); logger.info("Config - backlog size : " + config.getBacklogSize()); logger.info("Config - lease period : " + config.getLeasePeriod()); + logger.info("Config - sock wrt timeout: " + config.getSocketWriteTimeout()); logger.info("Config - max pool size : " + config.getMaxPoolSize()); logger.info("Config - num accp.threads: " + config.getNumAcceptThreads()); logger.info("Config - second.bind port: " + config.getSecondaryBindPort()); @@ -244,7 +244,7 @@ public final class Main { static boolean isAlreadyRunning(InvokerLocator serverLocator) { Map metadata = new HashMap<>(); - metadata.put(SocketWrapper.WRITE_TIMEOUT, "2000"); + metadata.put(SocketWrapper.WRITE_TIMEOUT, String.valueOf(ConfigSettings.instance.getSocketWriteTimeout())); metadata.put("generalizeSocketException", "true"); try { MageServer testServer = (MageServer) TransporterClient.createTransporterClient(serverLocator.getLocatorURI(), MageServer.class, metadata); diff --git a/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java b/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java index 4acf8c98b0..a4e8e9d610 100644 --- a/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java +++ b/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java @@ -24,8 +24,7 @@ * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. -*/ - + */ package mage.server.util; import java.io.File; @@ -33,7 +32,6 @@ import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; - import mage.server.util.config.Config; import mage.server.util.config.GamePlugin; import mage.server.util.config.Plugin; @@ -48,7 +46,6 @@ public enum ConfigSettings { private Config config; - ConfigSettings() { try { JAXBContext jaxbContext = JAXBContext.newInstance("mage.server.util.config"); @@ -79,6 +76,10 @@ public enum ConfigSettings { return config.getServer().getLeasePeriod().intValue(); } + public int getSocketWriteTimeout() { + return config.getServer().getSocketWriteTimeout().intValue(); + } + public int getMaxPoolSize() { return config.getServer().getMaxPoolSize().intValue(); } diff --git a/Mage.Server/src/main/java/mage/server/util/resources/config.xml b/Mage.Server/src/main/java/mage/server/util/resources/config.xml index f5696f6522..a351f218a7 100644 --- a/Mage.Server/src/main/java/mage/server/util/resources/config.xml +++ b/Mage.Server/src/main/java/mage/server/util/resources/config.xml @@ -9,6 +9,7 @@ numAcceptThreads="2" maxPoolSize="300" leasePeriod="5000" + socketWriteTimeout="10000" maxGameThreads="10" maxSecondsIdle="600" minUserNameLength="3" diff --git a/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd b/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd index 0a82ec9bae..ac33721e7c 100644 --- a/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd +++ b/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd @@ -2,102 +2,103 @@ - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - - - - + + + + + + - - - - - - - + + + + + + +