Added possibility to set some more JBoss Remoting parameters with config.xml on server start.

This commit is contained in:
LevelX2 2014-10-01 16:04:26 +02:00
parent f62b7ee1d9
commit e0ffef40cc
10 changed files with 127 additions and 24 deletions

View file

@ -695,7 +695,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
String server = prefs.get("serverAddress", ""); String server = prefs.get("serverAddress", "");
int port = Integer.parseInt(prefs.get("serverPort", "")); int port = Integer.parseInt(prefs.get("serverPort", ""));
String proxyServer = prefs.get("proxyAddress", ""); String proxyServer = prefs.get("proxyAddress", "");
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "")); int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
ProxyType proxyType = ProxyType.valueByText(prefs.get("proxyType", "None")); ProxyType proxyType = ProxyType.valueByText(prefs.get("proxyType", "None"));
String proxyUsername = prefs.get("proxyUsername", ""); String proxyUsername = prefs.get("proxyUsername", "");
String proxyPassword = prefs.get("proxyPassword", ""); String proxyPassword = prefs.get("proxyPassword", "");

View file

@ -59,6 +59,16 @@ public class Connection {
private static final String serialization = "?serializationtype=jboss"; private static final String serialization = "?serializationtype=jboss";
private static final String transport = "bisocket"; private static final String transport = "bisocket";
private final String parameter;
public Connection() {
this("");
}
public Connection(String parameter) {
this.parameter = parameter;
}
@Override @Override
public int hashCode() { public int hashCode() {
return (transport + host + Integer.toString(port) + proxyType.toString()).hashCode(); return (transport + host + Integer.toString(port) + proxyType.toString()).hashCode();
@ -75,7 +85,7 @@ public class Connection {
@Override @Override
public String toString() { public String toString() {
return host + ":" + Integer.toString(port) + "/" + serialization; return host + ":" + Integer.toString(port) + "/" + serialization + parameter;
} }
public String getURI() { public String getURI() {
@ -83,13 +93,13 @@ public class Connection {
try { try {
InetAddress inet = getLocalAddress(); InetAddress inet = getLocalAddress();
if (inet != null) { if (inet != null) {
return transport + "://" + inet.getHostAddress() + ":" + port + "/" + serialization; return transport + "://" + inet.getHostAddress() + ":" + port + "/" + serialization + parameter;
} }
} catch (SocketException ex) { } catch (SocketException ex) {
// just use localhost if can't find local ip // just use localhost if can't find local ip
} }
} }
return transport + "://" + host + ":" + port + "/" + serialization; return transport + "://" + host + ":" + port + "/" + serialization + parameter;
} }
public ProxyType getProxyType() { public ProxyType getProxyType() {

View file

@ -1,9 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
<!--
serverAddress - ip of the XMage server. Set it to "0.0.0.0" for local host or to the IP the server should use
port - the port the primary server socket is bound to
secondaryBindPort - the port to which the secondary server socket is to be bound. if "-1" is set , an arbitrary port is selected.
backlogSize - the preferred number of unaccepted incoming connections allowed at a given time. The actual number may be greater
than the specified backlog. When the queue is full, further connection requests are rejected. The JBoss default value is 200
numAcceptThreads - the number of threads listening on the ServerSocket. The JBoss default value is 1
maxPoolSize - the maximum number of ServerThreads that can exist at any given time. The JBoss default value is 300
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
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
maxUserNameLength - maximal allowed length of a user name to connect to the server
userNamePattern - pattern for user name validity check
maxAiOpponents - number of allowed AI opponents on the server
saveGameActivated - allow game save and replay options (not working correctly yet)
-->
<server serverAddress="0.0.0.0" <server serverAddress="0.0.0.0"
serverName="mage-server" serverName="mage-server"
port="17171" port="17171"
secondaryBindPort="17179"
backlogSize="200"
numAcceptThreads="2"
maxPoolSize="300"
leasePeriod="5000"
maxGameThreads="10" maxGameThreads="10"
maxSecondsIdle="600" maxSecondsIdle="600"
minUserNameLength="3" minUserNameLength="3"

View file

@ -1,7 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
<server serverAddress="0.0.0.0" serverName="mage-server" port="17171" <server serverAddress="0.0.0.0"
serverName="mage-server"
port="17171"
secondaryBindPort="-1"
backlogSize="200"
numAcceptThreads="2"
maxPoolSize="300"
leasePeriod="5000"
maxGameThreads="10" maxGameThreads="10"
maxSecondsIdle="600" maxSecondsIdle="600"
minUserNameLength="3" minUserNameLength="3"

View file

@ -63,6 +63,7 @@ import java.net.InetAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.jboss.remoting.transport.bisocket.BisocketServerInvoker;
/** /**
@ -140,10 +141,17 @@ public class Main {
logger.info("Config - max user name l.: " + config.getMaxUserNameLength()); logger.info("Config - max user name l.: " + config.getMaxUserNameLength());
logger.info("Config - save game active: " + (config.isSaveGameActivated() ? "True":"false")); logger.info("Config - save game active: " + (config.isSaveGameActivated() ? "True":"false"));
Connection connection = new Connection(); logger.info("Config - backlog size : " + config.getBacklogSize());
logger.info("Config - lease period : " + config.getLeasePeriod());
logger.info("Config - max pool size : " + config.getMaxPoolSize());
logger.info("Config - num accp.threads: " + config.getNumAcceptThreads());
logger.info("Config - second.bind port: " + config.getSecondaryBindPort());
Connection connection = new Connection("&maxPoolSize=" + config.getMaxPoolSize());
connection.setHost(config.getServerAddress()); connection.setHost(config.getServerAddress());
connection.setPort(config.getPort()); connection.setPort(config.getPort());
try { try {
// Parameter: serializationtype => jboss
InvokerLocator serverLocator = new InvokerLocator(connection.getURI()); InvokerLocator serverLocator = new InvokerLocator(connection.getURI());
if (!isAlreadyRunning(serverLocator)) { if (!isAlreadyRunning(serverLocator)) {
server = new MageTransporterServer(serverLocator, new MageServerImpl(adminPassword, testMode), MageServer.class.getName(), new MageServerInvocationHandler()); server = new MageTransporterServer(serverLocator, new MageServerImpl(adminPassword, testMode), MageServer.class.getName(), new MageServerInvocationHandler());
@ -231,7 +239,7 @@ public class Main {
public MageTransporterServer(InvokerLocator locator, Object target, String subsystem, MageServerInvocationHandler callback) throws Exception { public MageTransporterServer(InvokerLocator locator, Object target, String subsystem, MageServerInvocationHandler callback) throws Exception {
super(locator, target, subsystem); super(locator, target, subsystem);
connector.addInvocationHandler("callback", callback); connector.addInvocationHandler("callback", callback);
connector.setLeasePeriod(5000); connector.setLeasePeriod(ConfigSettings.getInstance().getLeasePeriod());
connector.addConnectionListener(new ClientConnectionListener()); connector.addConnectionListener(new ClientConnectionListener());
} }
@ -250,10 +258,16 @@ public class Main {
static class MageServerInvocationHandler implements ServerInvocationHandler { static class MageServerInvocationHandler implements ServerInvocationHandler {
@Override @Override
public void setMBeanServer(MBeanServer server) {} public void setMBeanServer(MBeanServer server) {
}
@Override @Override
public void setInvoker(ServerInvoker invoker) {} public void setInvoker(ServerInvoker invoker) {
((BisocketServerInvoker) invoker).setSecondaryBindPort(ConfigSettings.getInstance().getSecondaryBindPort());
((BisocketServerInvoker) invoker).setBacklog(ConfigSettings.getInstance().getBacklogSize());
((BisocketServerInvoker) invoker).setNumAcceptThreads(ConfigSettings.getInstance().getNumAcceptThreads());
}
@Override @Override
public Object invoke(final InvocationRequest invocation) throws Throwable { public Object invoke(final InvocationRequest invocation) throws Throwable {

View file

@ -48,6 +48,12 @@ public class Config {
logger.fatal("Config error", ex); logger.fatal("Config error", ex);
} }
port = Integer.parseInt(p.getProperty("port")); port = Integer.parseInt(p.getProperty("port"));
secondaryBindPort = Integer.parseInt(p.getProperty("secondaryBindPort"));
backlogSize = Integer.parseInt(p.getProperty("backlogSize"));
numAcceptThreads = Integer.parseInt(p.getProperty("numAcceptThreads"));
maxPoolSize = Integer.parseInt(p.getProperty("numPoolSize"));
leasePeriod = Integer.parseInt(p.getProperty("leasePeriod"));
remoteServer = p.getProperty("remote-server"); remoteServer = p.getProperty("remote-server");
maxGameThreads = Integer.parseInt(p.getProperty("max-game-threads")); maxGameThreads = Integer.parseInt(p.getProperty("max-game-threads"));
maxSecondsIdle = Integer.parseInt(p.getProperty("max-seconds-idle")); maxSecondsIdle = Integer.parseInt(p.getProperty("max-seconds-idle"));
@ -59,6 +65,11 @@ public class Config {
public static final String remoteServer; public static final String remoteServer;
public static final int port; public static final int port;
public static final int secondaryBindPort;
public static final int backlogSize;
public static final int numAcceptThreads;
public static final int maxPoolSize;
public static final int leasePeriod;
public static final int maxGameThreads; public static final int maxGameThreads;
public static final int maxSecondsIdle; public static final int maxSecondsIdle;
public static final int minUserNameLength; public static final int minUserNameLength;

View file

@ -19,6 +19,11 @@
<xs:attribute name="serverAddress" type="xs:string" use="required"/> <xs:attribute name="serverAddress" type="xs:string" use="required"/>
<xs:attribute name="serverName" type="xs:string" use="required"/> <xs:attribute name="serverName" type="xs:string" use="required"/>
<xs:attribute name="port" type="xs:positiveInteger" use="required"/> <xs:attribute name="port" type="xs:positiveInteger" use="required"/>
<xs:attribute name="secondaryBindPort" type="xs:integer" use="required"/>
<xs:attribute name="backlogSize" type="xs:positiveInteger" use="required"/>
<xs:attribute name="numAcceptThreads" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxPoolSize" type="xs:positiveInteger" use="required"/>
<xs:attribute name="leasePeriod" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/> <xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxSecondsIdle" type="xs:positiveInteger" use="required"/> <xs:attribute name="maxSecondsIdle" type="xs:positiveInteger" use="required"/>
<xs:attribute name="minUserNameLength" type="xs:positiveInteger" use="required"/> <xs:attribute name="minUserNameLength" type="xs:positiveInteger" use="required"/>

View file

@ -75,6 +75,26 @@ public class ConfigSettings {
return config.getServer().getPort().intValue(); return config.getServer().getPort().intValue();
} }
public int getSecondaryBindPort() {
return config.getServer().getSecondaryBindPort().intValue();
}
public int getLeasePeriod() {
return config.getServer().getLeasePeriod().intValue();
}
public int getMaxPoolSize() {
return config.getServer().getMaxPoolSize().intValue();
}
public int getNumAcceptThreads() {
return config.getServer().getNumAcceptThreads().intValue();
}
public int getBacklogSize() {
return config.getServer().getBacklogSize().intValue();
}
public int getMaxGameThreads() { public int getMaxGameThreads() {
return config.getServer().getMaxGameThreads().intValue(); return config.getServer().getMaxGameThreads().intValue();
} }

View file

@ -1,12 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
<server serverAddress="0.0.0.0" serverName="mage-server" port="17171" maxGameThreads="10" <server serverAddress="0.0.0.0"
serverName="mage-server"
port="17171"
secondaryBindPort="-1"
backlogSize="200"
numAcceptThreads="2"
maxPoolSize="300"
leasePeriod="5000"
maxGameThreads="10"
maxSecondsIdle="600" maxSecondsIdle="600"
minUserNameLength="3" minUserNameLength="3"
maxUserNameLength="14" maxUserNameLength="14"
userNamePattern="[^a-z0-9_]" userNamePattern="[^a-z0-9_]"
saveGameActivated="true"
maxAiOpponents="15" maxAiOpponents="15"
saveGameActivated="false" saveGameActivated="false"
/> />

View file

@ -22,6 +22,11 @@
<xs:attribute name="port" type="xs:positiveInteger" use="required"/> <xs:attribute name="port" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/> <xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxSecondsIdle" type="xs:positiveInteger" use="required"/> <xs:attribute name="maxSecondsIdle" type="xs:positiveInteger" use="required"/>
<xs:attribute name="secondaryBindPort" type="xs:integer" use="required"/>
<xs:attribute name="backlogSize" type="xs:positiveInteger" use="required"/>
<xs:attribute name="numAcceptThreads" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxPoolSize" type="xs:positiveInteger" use="required"/>
<xs:attribute name="leasePeriod" type="xs:positiveInteger" use="required"/>
<xs:attribute name="minUserNameLength" type="xs:positiveInteger" use="required"/> <xs:attribute name="minUserNameLength" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxUserNameLength" type="xs:positiveInteger" use="required"/> <xs:attribute name="maxUserNameLength" type="xs:positiveInteger" use="required"/>
<xs:attribute name="userNamePattern" type="xs:string" use="required"/> <xs:attribute name="userNamePattern" type="xs:string" use="required"/>