Kaynağa Gözat

make selector/worker thread counts configurable

tags/2.0.1
Jonathan Cobb 4 yıl önce
ebeveyn
işleme
c9c0ae2823
3 değiştirilmiş dosya ile 24 ekleme ve 5 silme
  1. +4
    -1
      wizard-common/src/main/java/org/cobbzilla/wizard/client/ApiClientBase.java
  2. +13
    -4
      wizard-server/src/main/java/org/cobbzilla/wizard/server/RestServerBase.java
  3. +7
    -0
      wizard-server/src/main/java/org/cobbzilla/wizard/server/config/HttpConfiguration.java

+ 4
- 1
wizard-common/src/main/java/org/cobbzilla/wizard/client/ApiClientBase.java Dosyayı Görüntüle

@@ -129,12 +129,15 @@ public class ApiClientBase implements Cloneable, Closeable {
.setSocketTimeout(socketTimeout) .setSocketTimeout(socketTimeout)
.setConnectionRequestTimeout(requestTimeout); .setConnectionRequestTimeout(requestTimeout);


httpClient = HttpClientBuilder.create()
httpClient = getHttpClientBuilder()
.setDefaultRequestConfig(requestBuilder.build()) .setDefaultRequestConfig(requestBuilder.build())
.build(); .build();
} }
return httpClient; return httpClient;
} }

public HttpClientBuilder getHttpClientBuilder() { return HttpClientBuilder.create(); }

public void setHttpClient(HttpClient httpClient) { this.httpClient = httpClient; } public void setHttpClient(HttpClient httpClient) { this.httpClient = httpClient; }


public RestResponse process(HttpRequestBean requestBean) throws Exception { public RestResponse process(HttpRequestBean requestBean) throws Exception {


+ 13
- 4
wizard-server/src/main/java/org/cobbzilla/wizard/server/RestServerBase.java Dosyayı Görüntüle

@@ -183,12 +183,21 @@ public abstract class RestServerBase<C extends RestServerConfiguration> implemen
rc.property("contextConfig", applicationContext); rc.property("contextConfig", applicationContext);


// pick a port // pick a port
if (!configuration.getHttp().hasPort()) {
configuration.getHttp().setPort(PortPicker.pick());
final HttpConfiguration httpConfig = configuration.getHttp();
if (!httpConfig.hasPort()) {
httpConfig.setPort(PortPicker.pick());
} }


final HttpServer httpServer = new HttpServer(); final HttpServer httpServer = new HttpServer();
final NetworkListener listener = new NetworkListener("grizzly-"+serverName, getListenAddress(), configuration.getHttp().getPort());
final NetworkListener listener = new NetworkListener("grizzly-"+serverName, getListenAddress(), httpConfig.getPort());
if (httpConfig.hasSelectorThreads()) {
log.info("buildServer: using "+httpConfig.getSelectorThreads()+" selector threads");
listener.getTransport().setSelectorRunnersCount(httpConfig.getSelectorThreads());
}
if (httpConfig.hasWorkerThreads()) {
log.info("buildServer: using "+httpConfig.getWorkerThreads()+" worker threads");
listener.getTransport().getWorkerThreadPoolConfig().setMaxPoolSize(httpConfig.getWorkerThreads());
}
httpServer.addListener(listener); httpServer.addListener(listener);


final ServerConfiguration serverConfig = httpServer.getServerConfiguration(); final ServerConfiguration serverConfig = httpServer.getServerConfiguration();
@@ -213,7 +222,7 @@ public abstract class RestServerBase<C extends RestServerConfiguration> implemen


// then the REST/Jersey handler // then the REST/Jersey handler
final HttpHandler processor = ContainerFactory.createContainer(GrizzlyHttpContainer.class, rc); final HttpHandler processor = ContainerFactory.createContainer(GrizzlyHttpContainer.class, rc);
final String restBase = configuration.getHttp().getBaseUri();
final String restBase = httpConfig.getBaseUri();
serverConfig.addHttpHandler(processor, restBase); serverConfig.addHttpHandler(processor, restBase);


// then optional static asset handler // then optional static asset handler


+ 7
- 0
wizard-server/src/main/java/org/cobbzilla/wizard/server/config/HttpConfiguration.java Dosyayı Görüntüle

@@ -19,4 +19,11 @@ public class HttpConfiguration {
public String getHost () throws URISyntaxException { public String getHost () throws URISyntaxException {
return new URI(baseUri).getHost(); return new URI(baseUri).getHost();
} }

@Getter @Setter private Integer selectorThreads;
public boolean hasSelectorThreads () { return selectorThreads != null; }

@Getter @Setter private Integer workerThreads;
public boolean hasWorkerThreads () { return workerThreads != null; }

} }

Yükleniyor…
İptal
Kaydet