aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-application/src/main
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-11-05 12:10:00 +0100
committerDavid Gageot <david@gageot.net>2012-11-06 09:21:00 +0100
commit597f22fd86971529077f5e854e72c09be1dc7b73 (patch)
tree9755891d02f03c330d1697ee50ee02b769496410 /sonar-application/src/main
parent6e6cea30338f31063d68fcd867946e09d60a6006 (diff)
downloadsonarqube-597f22fd86971529077f5e854e72c09be1dc7b73.tar.gz
sonarqube-597f22fd86971529077f5e854e72c09be1dc7b73.zip
SONAR-3830 Configure embedded Jetty's thread pool
Diffstat (limited to 'sonar-application/src/main')
-rw-r--r--sonar-application/src/main/assembly/conf/sonar.properties3
-rw-r--r--sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java60
-rw-r--r--sonar-application/src/main/java/org/sonar/application/StartServer.java2
3 files changed, 39 insertions, 26 deletions
diff --git a/sonar-application/src/main/assembly/conf/sonar.properties b/sonar-application/src/main/assembly/conf/sonar.properties
index c392d500b58..381505f5b8f 100644
--- a/sonar-application/src/main/assembly/conf/sonar.properties
+++ b/sonar-application/src/main/assembly/conf/sonar.properties
@@ -22,6 +22,9 @@
# Log HTTP requests. Deactivated by default.
#sonar.web.jettyRequestLogs: ../../logs/jetty-yyyy_mm_dd.request.log
+#sonar.web.jetty.threads.min: 5
+#sonar.web.jetty.threads.max: 50
+#sonar.web.jetty.threads.low: 10
#-----------------------------------------------------------------------
# DATABASE
diff --git a/sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java b/sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java
index 53cdc2aadba..55c6639a85e 100644
--- a/sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java
+++ b/sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java
@@ -35,6 +35,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Properties;
public class JettyEmbedder {
@@ -42,22 +43,23 @@ public class JettyEmbedder {
private final String host;
private final int port;
private final String contextPath;
+ private final Properties configuration;
- public JettyEmbedder(String host, int port, String contextPath, URL configurationURL) throws Exception {
+ public JettyEmbedder(String host, int port, String contextPath, URL configurationURL, Properties configuration) throws Exception {
this.host = host.trim();
this.port = port;
this.contextPath = contextPath;
+ this.configuration = configuration;
server = new Server();
if (configurationURL == null) {
configureProgrammatically();
-
} else {
System.setProperty("jetty.host", this.host);
System.setProperty("jetty.port", String.valueOf(port));
System.setProperty("jetty.context", contextPath);
- XmlConfiguration configuration = new XmlConfiguration(configurationURL);
- configuration.configure(server);
+ XmlConfiguration xmlConfiguration = new XmlConfiguration(configurationURL);
+ xmlConfiguration.configure(server);
}
}
@@ -65,7 +67,7 @@ public class JettyEmbedder {
* for tests
*/
JettyEmbedder(String host, int port) throws Exception {
- this(host, port, null, null);
+ this(host, port, null, null, new Properties());
}
public void start() throws Exception {
@@ -104,9 +106,9 @@ public class JettyEmbedder {
private void configureServer() {
QueuedThreadPool threadPool = new QueuedThreadPool();
- threadPool.setMinThreads(5);
- threadPool.setMaxThreads(50);
- threadPool.setLowThreads(10);
+ threadPool.setMinThreads(getIntProperty("sonar.web.jetty.threads.min", 5));
+ threadPool.setMaxThreads(getIntProperty("sonar.web.jetty.threads.max", 50));
+ threadPool.setLowThreads(getIntProperty("sonar.web.jetty.threads.low", 10));
server.setThreadPool(threadPool);
SelectChannelConnector connector = new SelectChannelConnector();
connector.setHost(host);
@@ -121,33 +123,41 @@ public class JettyEmbedder {
server.setGracefulShutdown(1000);
}
+ private int getIntProperty(String name, int defaultValue) {
+ String value = configuration.getProperty(name);
+ if (null == value) {
+ return defaultValue;
+ }
+
+ return Integer.parseInt(value);
+ }
+
final String getPluginsClasspath(String pluginsPathFromClassloader) throws URISyntaxException, IOException {
- final URL resource = getClass().getResource(pluginsPathFromClassloader);
- if (resource != null) {
- File pluginsDir = new File(resource.toURI());
- List<String> paths = new ArrayList<String>();
- paths.add(pluginsDir.getCanonicalPath() + System.getProperty("file.separator"));
-
- Collection<File> files = FileUtils.listFiles(pluginsDir, new String[] {"jar"}, false);
- if (files != null) {
- for (File file : files) {
- paths.add(file.getCanonicalPath());
- }
- }
- return join(paths, ",");
+ URL resource = getClass().getResource(pluginsPathFromClassloader);
+ if (resource == null) {
+ return null;
}
- return null;
+
+ List<String> paths = new ArrayList<String>();
+
+ File pluginsDir = new File(resource.toURI());
+ paths.add(pluginsDir.getCanonicalPath() + System.getProperty("file.separator"));
+
+ Collection<File> files = FileUtils.listFiles(pluginsDir, new String[] {"jar"}, false);
+ for (File file : files) {
+ paths.add(file.getCanonicalPath());
+ }
+
+ return join(paths, ",");
}
private String join(List<String> paths, String separator) {
StringBuilder sb = new StringBuilder();
- boolean first = true;
for (String path : paths) {
- if (!first) {
+ if (sb.length() > 0) {
sb.append(separator);
}
sb.append(path);
- first = false;
}
return sb.toString();
}
diff --git a/sonar-application/src/main/java/org/sonar/application/StartServer.java b/sonar-application/src/main/java/org/sonar/application/StartServer.java
index 8c2f48181b0..6d241327c42 100644
--- a/sonar-application/src/main/java/org/sonar/application/StartServer.java
+++ b/sonar-application/src/main/java/org/sonar/application/StartServer.java
@@ -42,7 +42,7 @@ public final class StartServer {
String host = configuration.getProperty("sonar.web.host", DEFAULT_WEB_HOST);
int port = Integer.parseInt(configuration.getProperty("sonar.web.port", "" + DEFAULT_WEB_PORT));
String context = configuration.getProperty("sonar.web.context", DEFAULT_WEB_CONTEXT);
- JettyEmbedder jetty = new JettyEmbedder(host, port, context, StartServer.class.getResource("/jetty.xml"));
+ JettyEmbedder jetty = new JettyEmbedder(host, port, context, StartServer.class.getResource("/jetty.xml"), configuration);
configureRequestLogs(jetty, configuration);
jetty.start();