Skip to content

Commit

Permalink
Merge pull request #11 from italiangrid/issue-10
Browse files Browse the repository at this point in the history
Issue 10
  • Loading branch information
andreaceccanti authored Nov 25, 2021
2 parents 145ea6d + 67db718 commit c0b8217
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 26 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.italiangrid</groupId>
<artifactId>jetty-utils</artifactId>
<version>0.4.2.v20200516</version>
<version>0.4.5.v20211125</version>
<packaging>jar</packaging>

<name>jetty-utils</name>
Expand Down Expand Up @@ -52,10 +52,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<jetty.version>9.4.28.v20200408</jetty.version>
<jetty.version>9.4.30.v20200611</jetty.version>
<slf4j.version>1.7.2</slf4j.version>
<logback.version>1.0.9</logback.version>
<voms-api-java.version>3.3.0</voms-api-java.version>
<voms-api-java.version>3.3.2</voms-api-java.version>
<metrics.version>4.0.5</metrics.version>

<plugin.compiler.version>3.1</plugin.compiler.version>
Expand Down Expand Up @@ -200,7 +200,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,22 @@ public class TLSServerConnectorBuilder {
* Custom TLS hostname verifier
*/
private HostnameVerifier hostnameVerifier = null;

/**
* Disable JSSE hostname verification
*/
private boolean disableJsseHostnameVerification = false;

/**
* Number of acceptors threads for the connector
*/
private int acceptors = -1;

/**
* Number of selector threads for the connector
*/
private int selectors = -1;

/**
* Returns an instance of the {@link TLSServerConnectorBuilder}.
*
Expand Down Expand Up @@ -247,7 +257,7 @@ private void loadCredentials() {
*
* @param contextFactory the {@link SslContextFactory} being configured
*/
private void configureContextFactory(SslContextFactory contextFactory) {
private void configureContextFactory(SslContextFactory.Server contextFactory) {

if (excludeProtocols != null) {
contextFactory.setExcludeProtocols(excludeProtocols);
Expand All @@ -273,15 +283,15 @@ private void configureContextFactory(SslContextFactory contextFactory) {
} else {
contextFactory.setProvider(BouncyCastleProvider.PROVIDER_NAME);
}

if (hostnameVerifier != null) {
contextFactory.setHostnameVerifier(hostnameVerifier);
}

if (disableJsseHostnameVerification) {
contextFactory.setEndpointIdentificationAlgorithm(null);
}

}

/**
Expand Down Expand Up @@ -501,12 +511,23 @@ public TLSServerConnectorBuilder withHostnameVerifier(HostnameVerifier verifier)
this.hostnameVerifier = verifier;
return this;
}

public TLSServerConnectorBuilder withDisableJsseHostnameVerification(boolean disableJsseHostnameVerification) {

public TLSServerConnectorBuilder withDisableJsseHostnameVerification(
boolean disableJsseHostnameVerification) {
this.disableJsseHostnameVerification = disableJsseHostnameVerification;
return this;
}

public TLSServerConnectorBuilder withAcceptors(int acceptors) {
this.acceptors = acceptors;
return this;
}

public TLSServerConnectorBuilder withSelectors(int selectors) {
this.selectors = selectors;
return this;
}

private SSLContext buildSSLContext() {

SSLContext sslCtx;
Expand Down Expand Up @@ -553,7 +574,7 @@ public ServerConnector build() {
}

SSLContext sslContext = buildSSLContext();
SslContextFactory cf = new SslContextFactory();
SslContextFactory.Server cf = new SslContextFactory.Server();

cf.setSslContext(sslContext);

Expand Down Expand Up @@ -593,11 +614,12 @@ public ServerConnector build() {

SslConnectionFactory sslCf = new SslConnectionFactory(cf, alpn.getProtocol());

connector = new ServerConnector(server, sslCf, alpn, h2ConnFactory, httpConnFactory);
connector = new ServerConnector(server, acceptors, selectors, sslCf, alpn, h2ConnFactory,
httpConnFactory);

} else {

connector = new ServerConnector(server,
connector = new ServerConnector(server, acceptors, selectors,
new SslConnectionFactory(cf, HttpVersion.HTTP_1_1.asString()), connFactory);
}

Expand Down
40 changes: 28 additions & 12 deletions src/main/java/org/italiangrid/utils/jetty/ThreadPoolBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
*/
public class ThreadPoolBuilder {

public static final int MAX_REQUEST_QUEUE_SIZE = 200;
public static final int DEFAULT_MAX_REQUEST_QUEUE_SIZE = 200;

public static final int MAX_THREADS = 50;
public static final int MIN_THREADS = 1;
public static final int DEFAULT_MAX_THREADS = 50;
public static final int DEFAULT_MIN_THREADS = 1;

public static final int IDLE_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(60);
public static final int DEFAULT_IDLE_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(60);

private int maxThreads = MAX_THREADS;
private int minThreads = MIN_THREADS;
private int maxThreads = DEFAULT_MAX_THREADS;
private int minThreads = DEFAULT_MIN_THREADS;

private int idleTimeout = IDLE_TIMEOUT;
private int maxRequestQueueSize;
private int idleTimeout = DEFAULT_IDLE_TIMEOUT;
private int maxRequestQueueSize = DEFAULT_MAX_REQUEST_QUEUE_SIZE;

private MetricRegistry registry;

Expand Down Expand Up @@ -98,6 +98,7 @@ public ThreadPoolBuilder withMaxRequestQueueSize(int queueSize) {

/**
* Sets the registry for this thread pool
*
* @param registry the metric registry
* @return this builder
*/
Expand All @@ -106,6 +107,17 @@ public ThreadPoolBuilder registry(MetricRegistry registry) {
return this;
}

/**
* Sets the idle timeout in msec for this thread pool
*
* @param idleTimeout the timeout in milliseconds
* @return this builder
*/
public ThreadPoolBuilder withIdleTimeoutMsec(int idleTimeout) {
this.idleTimeout = idleTimeout;
return this;
}

/**
* ctor.
*
Expand All @@ -122,18 +134,22 @@ private ThreadPoolBuilder() {
public ThreadPool build() {

if (maxRequestQueueSize <= 0) {
maxRequestQueueSize = MAX_REQUEST_QUEUE_SIZE;
maxRequestQueueSize = DEFAULT_MAX_REQUEST_QUEUE_SIZE;
}

if (maxThreads <= 0) {
maxThreads = MAX_THREADS;
maxThreads = DEFAULT_MAX_THREADS;
}

if (minThreads <= 0) {
minThreads = MIN_THREADS;
minThreads = DEFAULT_MIN_THREADS;
}

if (idleTimeout <= 0) {
idleTimeout = DEFAULT_IDLE_TIMEOUT;
}

BlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(MAX_REQUEST_QUEUE_SIZE);
BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(maxRequestQueueSize);

QueuedThreadPool tp = null;

Expand Down

0 comments on commit c0b8217

Please sign in to comment.