Skip to content

Commit

Permalink
Support setting the HTTP JMX port.
Browse files Browse the repository at this point in the history
Support disabling the HTTP JMX interface.
  • Loading branch information
abrougher committed Nov 23, 2012
1 parent a3380f5 commit be20e44
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 28 deletions.
Expand Up @@ -58,6 +58,10 @@ public class SymmetricLauncher extends AbstractCommandLauncher {

private static final String OPTION_NO_DIRECT_BUFFER = "no-directbuffer";

private static final String OPTION_JMX_DISABLE = "jmx-disable";

private static final String OPTION_JMX_PORT = "jmx-port";

public SymmetricLauncher(String app, String argSyntax, String messageKeyPrefix) {
super(app, argSyntax, messageKeyPrefix);
}
Expand Down Expand Up @@ -96,16 +100,20 @@ protected void buildOptions(Options options) {
addOption(options, "Q", OPTION_SECURE_PORT_SERVER, true);
addOption(options, "I", OPTION_MAX_IDLE_TIME, true);
addOption(options, "nnio", OPTION_NO_NIO, false);
addOption(options, "ndb", OPTION_NO_DIRECT_BUFFER, false);
addOption(options, "ndb", OPTION_NO_DIRECT_BUFFER, false);
addOption(options, "hbau", OPTION_HTTP_BASIC_AUTH_USER, true);
addOption(options, "hbap", OPTION_HTTP_BASIC_AUTH_PASSWORD, true);
addOption(options, "JD", OPTION_JMX_DISABLE, false);
addOption(options, "J", OPTION_JMX_PORT, true);
}

protected boolean executeWithOptions(CommandLine line) throws Exception {

String host = null;
int port = Integer.parseInt(SymmetricWebServer.DEFAULT_HTTP_PORT);
int securePort = Integer.parseInt(SymmetricWebServer.DEFAULT_HTTPS_PORT);
int httpPort = Integer.parseInt(SymmetricWebServer.DEFAULT_HTTP_PORT);
int httpSecurePort = Integer.parseInt(SymmetricWebServer.DEFAULT_HTTPS_PORT);
int jmxPort = 0;

String webDir = SymmetricWebServer.DEFAULT_WEBAPP_DIR;
int maxIdleTime = SymmetricWebServer.DEFAULT_MAX_IDLE_TIME;
boolean noNio = false;
Expand All @@ -126,11 +134,11 @@ protected boolean executeWithOptions(CommandLine line) throws Exception {
}

if (line.hasOption(OPTION_PORT_SERVER)) {
port = new Integer(line.getOptionValue(OPTION_PORT_SERVER));
httpPort = new Integer(line.getOptionValue(OPTION_PORT_SERVER));
}

if (line.hasOption(OPTION_SECURE_PORT_SERVER)) {
securePort = new Integer(line.getOptionValue(OPTION_SECURE_PORT_SERVER));
httpSecurePort = new Integer(line.getOptionValue(OPTION_SECURE_PORT_SERVER));
}

if (line.hasOption(OPTION_MAX_IDLE_TIME)) {
Expand All @@ -145,6 +153,18 @@ protected boolean executeWithOptions(CommandLine line) throws Exception {
noDirectBuffer = true;
}

if (!line.hasOption(OPTION_JMX_DISABLE)) {
if (line.hasOption(OPTION_JMX_PORT)) {
jmxPort = new Integer(line.getOptionValue(OPTION_JMX_PORT));
} else {
if (line.hasOption(OPTION_START_SECURE_SERVER)) {
jmxPort = httpSecurePort + 1;
} else {
jmxPort = httpPort + 1;
}
}
}

if (line.hasOption(OPTION_START_CLIENT)) {
getSymmetricEngine(false).start();
return true;
Expand All @@ -156,11 +176,11 @@ protected boolean executeWithOptions(CommandLine line) throws Exception {
webServer.setBasicAuthUsername(httpBasicAuthUser);
webServer.setBasicAuthPassword(httpBasicAuthPassword);
if (line.hasOption(OPTION_START_MIXED_SERVER)) {
webServer.startMixed(port, securePort);
webServer.startMixed(httpPort, httpSecurePort, jmxPort);
} else if (line.hasOption(OPTION_START_SECURE_SERVER)) {
webServer.startSecure(securePort);
webServer.startSecure(httpSecurePort, jmxPort);
} else {
webServer.start(port);
webServer.start(httpPort, jmxPort);
}
return true;
}
Expand Down
Expand Up @@ -96,6 +96,8 @@ public enum Mode {
protected int httpPort = -1;

protected int httpsPort = -1;

protected int jmxPort = -1;

protected String basicAuthUsername = null;

Expand Down Expand Up @@ -139,44 +141,48 @@ public SymmetricWebServer(int maxIdleTime, String propertiesUrl) {
this.maxIdleTime = maxIdleTime;
}

public SymmetricWebServer start(int port, String propertiesUrl) throws Exception {
public SymmetricWebServer start(int httpPort, int jmxPort, String propertiesUrl) throws Exception {
this.propertiesFile = propertiesUrl;
return start(port);
return start(httpPort, jmxPort);
}

public SymmetricWebServer start() throws Exception {
if (httpPort > 0 && httpsPort > 0) {
return startMixed(httpPort, httpsPort);
return startMixed(httpPort, httpsPort, jmxPort);
} else if (httpPort > 0) {
return start(httpPort);
return start(httpPort, jmxPort);
} else if (httpsPort > 0) {
return startSecure(httpsPort);
return startSecure(httpsPort, jmxPort);
} else {
throw new IllegalStateException(
"Either an http or https port needs to be set before starting the server.");
}
}

public SymmetricWebServer start(int port) throws Exception {
return start(port, 0, Mode.HTTP);
public SymmetricWebServer start(int httpPort) throws Exception {
return start(httpPort, 0, httpPort + 1, Mode.HTTP);
}

public SymmetricWebServer startSecure(int port) throws Exception {
return start(0, port, Mode.HTTPS);
public SymmetricWebServer start(int httpPort, int jmxPort) throws Exception {
return start(httpPort, 0, jmxPort, Mode.HTTP);
}

public SymmetricWebServer startMixed(int port, int securePort) throws Exception {
return start(port, securePort, Mode.MIXED);
public SymmetricWebServer startSecure(int httpsPort, int jmxPort) throws Exception {
return start(0, httpsPort, jmxPort, Mode.HTTPS);
}

public SymmetricWebServer start(int port, int securePort, Mode mode) throws Exception {
public SymmetricWebServer startMixed(int httpPort, int secureHttpPort, int jmxPort) throws Exception {
return start(httpPort, secureHttpPort, jmxPort, Mode.MIXED);
}

public SymmetricWebServer start(int httpPort, int securePort, int httpJmxPort, Mode mode) throws Exception {

// indicate to the app that we are in standalone mode
// indicate to the app that we are in stand alone mode
System.setProperty(SystemConstants.SYSPROP_STANDALONE_WEB, "true");

server = new Server();

server.setConnectors(getConnectors(port, securePort, mode));
server.setConnectors(getConnectors(httpPort, securePort, mode));
setupBasicAuthIfNeeded(server);

webapp = new WebAppContext();
Expand All @@ -185,7 +191,7 @@ public SymmetricWebServer start(int port, int securePort, Mode mode) throws Exce
webapp.setWar(webAppDir);
SessionManager sm = webapp.getSessionHandler().getSessionManager();
sm.setMaxInactiveInterval(maxIdleTime / 1000);
sm.setSessionCookie(sm.getSessionCookie() + (port > 0 ? port : securePort));
sm.setSessionCookie(sm.getSessionCookie() + (httpPort > 0 ? httpPort : securePort));
webapp.getServletContext().getContextHandler().setMaxFormContentSize(Integer.parseInt(System.getProperty("org.eclipse.jetty.server.Request.maxFormContentSize", "800000")));
webapp.getServletContext().getContextHandler().setMaxFormKeys(Integer.parseInt(System.getProperty("org.eclipse.jetty.server.Request.maxFormKeys", "100000")));
if (propertiesFile != null) {
Expand All @@ -201,8 +207,9 @@ public SymmetricWebServer start(int port, int securePort, Mode mode) throws Exce

server.start();

int httpJmxPort = port != 0 ? port + 1 : securePort + 1;
registerHttpJmxAdaptor(httpJmxPort);
if (httpJmxPort > 0) {
registerHttpJmxAdaptor(httpJmxPort);
}

if (join) {
log.info("Joining the web server main thread");
Expand Down Expand Up @@ -366,7 +373,7 @@ public void stop() throws Exception {
}

public static void main(String[] args) throws Exception {
new SymmetricWebServer().start(8080);
new SymmetricWebServer().start(8080, 8081);
}

public boolean isJoin() {
Expand Down Expand Up @@ -441,4 +448,12 @@ public String getName() {
return name;
}

public int getJmxPort() {
return jmxPort;
}

public void setJmxPort(int jmxPort) {
this.jmxPort = jmxPort;
}

}

0 comments on commit be20e44

Please sign in to comment.