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

@ -63,6 +63,7 @@ import java.net.InetAddress;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import org.jboss.remoting.transport.bisocket.BisocketServerInvoker;
/**
@ -106,7 +107,7 @@ public class Main {
fastDbMode = Boolean.valueOf(arg.replace(fastDBModeArg, ""));
}
}
logger.info("Loading cards...");
if (fastDbMode) {
CardScanner.scanned = true;
@ -140,11 +141,18 @@ public class Main {
logger.info("Config - max user name l.: " + config.getMaxUserNameLength());
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.setPort(config.getPort());
try {
InvokerLocator serverLocator = new InvokerLocator(connection.getURI());
// Parameter: serializationtype => jboss
InvokerLocator serverLocator = new InvokerLocator(connection.getURI());
if (!isAlreadyRunning(serverLocator)) {
server = new MageTransporterServer(serverLocator, new MageServerImpl(adminPassword, testMode), MageServer.class.getName(), new MageServerInvocationHandler());
server.start();
@ -231,7 +239,7 @@ public class Main {
public MageTransporterServer(InvokerLocator locator, Object target, String subsystem, MageServerInvocationHandler callback) throws Exception {
super(locator, target, subsystem);
connector.addInvocationHandler("callback", callback);
connector.setLeasePeriod(5000);
connector.setLeasePeriod(ConfigSettings.getInstance().getLeasePeriod());
connector.addConnectionListener(new ClientConnectionListener());
}
@ -250,10 +258,16 @@ public class Main {
static class MageServerInvocationHandler implements ServerInvocationHandler {
@Override
public void setMBeanServer(MBeanServer server) {}
public void setMBeanServer(MBeanServer server) {
}
@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
public Object invoke(final InvocationRequest invocation) throws Throwable {

View file

@ -48,6 +48,12 @@ public class Config {
logger.fatal("Config error", ex);
}
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");
maxGameThreads = Integer.parseInt(p.getProperty("max-game-threads"));
maxSecondsIdle = Integer.parseInt(p.getProperty("max-seconds-idle"));
@ -59,6 +65,11 @@ public class Config {
public static final String remoteServer;
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 maxSecondsIdle;
public static final int minUserNameLength;

View file

@ -19,13 +19,18 @@
<xs:attribute name="serverAddress" 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="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="maxSecondsIdle" 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="userNamePattern" type="xs:string" use="required"/>
<xs:attribute name="maxAiOpponents" type="xs:string" use="optional"/>
<xs:attribute name="saveGameActivated" type="xs:boolean" use="optional"/>
<xs:attribute name="minUserNameLength" 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="maxAiOpponents" type="xs:string" use="optional"/>
<xs:attribute name="saveGameActivated" type="xs:boolean" use="optional"/>
</xs:complexType>
</xs:element>

View file

@ -75,6 +75,26 @@ public class ConfigSettings {
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() {
return config.getServer().getMaxGameThreads().intValue();
}

View file

@ -1,12 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
minUserNameLength="3"
maxUserNameLength="14"
userNamePattern="[^a-z0-9_]"
saveGameActivated="true"
maxAiOpponents="15"
saveGameActivated="false"
/>

View file

@ -22,11 +22,16 @@
<xs:attribute name="port" 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="minUserNameLength" 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="maxAiOpponents" type="xs:string" use="optional"/>
<xs:attribute name="saveGameActivated" type="xs:boolean" use="optional"/>
<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="maxUserNameLength" type="xs:positiveInteger" use="required"/>
<xs:attribute name="userNamePattern" type="xs:string" use="required"/>
<xs:attribute name="maxAiOpponents" type="xs:string" use="optional"/>
<xs:attribute name="saveGameActivated" type="xs:boolean" use="optional"/>
</xs:complexType>
</xs:element>