Skip to content

Commit c7d3ef8

Browse files
author
Stephane Landelle
committed
Make ChannelPool Netty specific, close AsyncHttpClient#376
1 parent 2ded572 commit c7d3ef8

File tree

12 files changed

+85
-219
lines changed

12 files changed

+85
-219
lines changed

api/src/main/java/org/asynchttpclient/AsyncHttpClient.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ protected void finalize() throws Throwable {
417417
*
418418
* @return true if closed
419419
*/
420-
@SuppressWarnings("UnusedDeclaration")
421420
public boolean isClosed() {
422421
return isClosed.get();
423422
}
@@ -427,15 +426,13 @@ public boolean isClosed() {
427426
*
428427
* @return {@link AsyncHttpClientConfig}
429428
*/
430-
@SuppressWarnings("UnusedDeclaration")
431429
public AsyncHttpClientConfig getConfig() {
432430
return config;
433431
}
434432

435433
/**
436434
* Set default signature calculator to use for requests build by this client instance
437435
*/
438-
@SuppressWarnings("UnusedDeclaration")
439436
public AsyncHttpClient setSignatureCalculator(SignatureCalculator signatureCalculator) {
440437
this.signatureCalculator = signatureCalculator;
441438
return this;
@@ -457,7 +454,6 @@ public BoundRequestBuilder prepareGet(String url) {
457454
* @param url A well formed URL.
458455
* @return {@link RequestBuilder}
459456
*/
460-
@SuppressWarnings("UnusedDeclaration")
461457
public BoundRequestBuilder prepareConnect(String url) {
462458
return requestBuilder("CONNECT", url);
463459
}
@@ -508,7 +504,6 @@ public BoundRequestBuilder preparePut(String url) {
508504
* @param url A well formed URL.
509505
* @return {@link RequestBuilder}
510506
*/
511-
@SuppressWarnings("UnusedDeclaration")
512507
public BoundRequestBuilder prepareDelete(String url) {
513508
return requestBuilder("DELETE", url);
514509
}
@@ -519,7 +514,6 @@ public BoundRequestBuilder prepareDelete(String url) {
519514
* @param url A well formed URL.
520515
* @return {@link RequestBuilder}
521516
*/
522-
@SuppressWarnings("UnusedDeclaration")
523517
public BoundRequestBuilder preparePatch(String url) {
524518
return requestBuilder("PATCH", url);
525519
}
@@ -530,7 +524,6 @@ public BoundRequestBuilder preparePatch(String url) {
530524
* @param url A well formed URL.
531525
* @return {@link RequestBuilder}
532526
*/
533-
@SuppressWarnings("UnusedDeclaration")
534527
public BoundRequestBuilder prepareTrace(String url) {
535528
return requestBuilder("TRACE", url);
536529
}
@@ -541,7 +534,6 @@ public BoundRequestBuilder prepareTrace(String url) {
541534
* @param request a {@link Request}
542535
* @return {@link RequestBuilder}
543536
*/
544-
@SuppressWarnings("UnusedDeclaration")
545537
public BoundRequestBuilder prepareRequest(Request request) {
546538
return requestBuilder(request);
547539
}

api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public class AsyncHttpClientConfig {
9393
protected SSLContext sslContext;
9494
protected SSLEngineFactory sslEngineFactory;
9595
protected AsyncHttpProviderConfig<?, ?> providerConfig;
96-
protected ConnectionsPool<?, ?> connectionsPool;
9796
protected Realm realm;
9897
protected List<RequestFilter> requestFilters;
9998
protected List<ResponseFilter> responseFilters;
@@ -136,7 +135,7 @@ private AsyncHttpClientConfig(int maxTotalConnections,
136135
SSLContext sslContext,
137136
SSLEngineFactory sslEngineFactory,
138137
AsyncHttpProviderConfig<?, ?> providerConfig,
139-
ConnectionsPool<?, ?> connectionsPool, Realm realm,
138+
Realm realm,
140139
List<RequestFilter> requestFilters,
141140
List<ResponseFilter> responseFilters,
142141
List<IOExceptionFilter> ioExceptionFilters,
@@ -171,7 +170,6 @@ private AsyncHttpClientConfig(int maxTotalConnections,
171170
this.sslContext = sslContext;
172171
this.sslEngineFactory = sslEngineFactory;
173172
this.providerConfig = providerConfig;
174-
this.connectionsPool = connectionsPool;
175173
this.realm = realm;
176174
this.requestFilters = requestFilters;
177175
this.responseFilters = responseFilters;
@@ -333,15 +331,6 @@ public SSLContext getSSLContext() {
333331
return sslContext;
334332
}
335333

336-
/**
337-
* Return an instance of {@link ConnectionsPool}
338-
*
339-
* @return an instance of {@link ConnectionsPool}
340-
*/
341-
public ConnectionsPool<?, ?> getConnectionsPool() {
342-
return connectionsPool;
343-
}
344-
345334
/**
346335
* Return an instance of {@link SSLEngineFactory} used for SSL connection.
347336
*
@@ -605,7 +594,6 @@ public static class Builder {
605594
private SSLContext sslContext;
606595
private SSLEngineFactory sslEngineFactory;
607596
private AsyncHttpProviderConfig<?, ?> providerConfig;
608-
private ConnectionsPool<?, ?> connectionsPool;
609597
private Realm realm;
610598
private int requestCompressionLevel = -1;
611599
private int maxRequestRetry = 5;
@@ -845,17 +833,6 @@ public Builder setAsyncHttpClientProviderConfig(AsyncHttpProviderConfig<?, ?> pr
845833
return this;
846834
}
847835

848-
/**
849-
* Set the {@link ConnectionsPool}
850-
*
851-
* @param connectionsPool the {@link ConnectionsPool}
852-
* @return a {@link Builder}
853-
*/
854-
public Builder setConnectionsPool(ConnectionsPool<?, ?> connectionsPool) {
855-
this.connectionsPool = connectionsPool;
856-
return this;
857-
}
858-
859836
/**
860837
* Set the {@link Realm} that will be used for all requests.
861838
*
@@ -1167,7 +1144,6 @@ public Builder setAsyncConnectMode(boolean asyncConnectMode) {
11671144
public Builder(AsyncHttpClientConfig prototype) {
11681145
allowPoolingConnection = prototype.getAllowPoolingConnection();
11691146
providerConfig = prototype.getAsyncHttpProviderConfig();
1170-
connectionsPool = prototype.getConnectionsPool();
11711147
defaultConnectionTimeOutInMs = prototype.getConnectionTimeoutInMs();
11721148
defaultIdleConnectionInPoolTimeoutInMs = prototype.getIdleConnectionInPoolTimeoutInMs();
11731149
defaultIdleConnectionTimeoutInMs = prototype.getIdleConnectionTimeoutInMs();
@@ -1254,7 +1230,6 @@ public Thread newThread(Runnable r) {
12541230
sslContext,
12551231
sslEngineFactory,
12561232
providerConfig,
1257-
connectionsPool,
12581233
realm,
12591234
requestFilters,
12601235
responseFilters,

api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ public AsyncHttpClientConfigBean setProviderConfig(AsyncHttpProviderConfig<?, ?>
175175
return this;
176176
}
177177

178-
public AsyncHttpClientConfigBean setConnectionsPool(ConnectionsPool<?, ?> connectionsPool) {
179-
this.connectionsPool = connectionsPool;
180-
return this;
181-
}
182-
183178
public AsyncHttpClientConfigBean setRealm(Realm realm) {
184179
this.realm = realm;
185180
return this;

api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ public Response onCompleted(Response response) throws Exception {
127127
}
128128
}
129129

130-
@Test(groups = { "standalone", "default_provider" })
131-
public abstract void testInvalidConnectionsPool();
132-
133-
@Test(groups = { "standalone", "default_provider" })
134-
public abstract void testValidConnectionsPool();
135-
136130
@Test(groups = { "standalone", "default_provider" })
137131
public void multipleMaxConnectionOpenTest() throws Exception {
138132
AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true).setConnectionTimeoutInMs(5000).setMaximumConnectionsTotal(1).build();

providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616
import org.asynchttpclient.AsyncHttpClient;
1717
import org.asynchttpclient.AsyncHttpClientConfig;
18-
import org.asynchttpclient.ConnectionsPool;
1918
import org.asynchttpclient.Response;
2019
import org.asynchttpclient.async.ConnectionPoolTest;
21-
import org.glassfish.grizzly.Connection;
2220
import org.testng.annotations.Test;
2321

2422
import java.util.concurrent.TimeUnit;
@@ -35,111 +33,6 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) {
3533
@Override
3634
@Test(enabled=false)
3735
public void testMaxTotalConnectionsException() {
38-
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true).setMaximumConnectionsTotal(1).build());
39-
try {
40-
String url = getTargetUrl();
41-
int i;
42-
Exception exception = null;
43-
for (i = 0; i < 20; i++) {
44-
try {
45-
log.info("{} requesting url [{}]...", i, url);
46-
47-
if (i < 5) {
48-
client.prepareGet(url).execute().get();
49-
} else {
50-
client.prepareGet(url).execute();
51-
}
52-
} catch (Exception ex) {
53-
exception = ex;
54-
break;
55-
}
56-
}
57-
assertNotNull(exception);
58-
assertNotNull(exception.getMessage());
59-
} finally {
60-
client.close();
61-
}
62-
}
63-
64-
@Override
65-
public void testValidConnectionsPool() {
66-
ConnectionsPool<String, Connection> cp = new ConnectionsPool<String, Connection>() {
67-
68-
public boolean offer(String key, Connection connection) {
69-
return true;
70-
}
71-
72-
public Connection poll(String connection) {
73-
return null;
74-
}
75-
76-
public boolean removeAll(Connection connection) {
77-
return false;
78-
}
79-
80-
public boolean canCacheConnection() {
81-
return true;
82-
}
83-
84-
public void destroy() {
85-
86-
}
87-
};
88-
89-
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionsPool(cp).build());
90-
try {
91-
Exception exception = null;
92-
try {
93-
client.prepareGet(getTargetUrl()).execute().get(TIMEOUT, TimeUnit.SECONDS);
94-
} catch (Exception ex) {
95-
ex.printStackTrace();
96-
exception = ex;
97-
}
98-
assertNull(exception);
99-
} finally {
100-
client.close();
101-
}
102-
}
103-
104-
@Test(groups = { "standalone", "default_provider" }, enabled=false)
105-
public void testInvalidConnectionsPool() {
106-
107-
ConnectionsPool<String, Connection> cp = new ConnectionsPool<String, Connection>() {
108-
109-
public boolean offer(String key, Connection connection) {
110-
return false;
111-
}
112-
113-
public Connection poll(String connection) {
114-
return null;
115-
}
116-
117-
public boolean removeAll(Connection connection) {
118-
return false;
119-
}
120-
121-
public boolean canCacheConnection() {
122-
return false;
123-
}
124-
125-
public void destroy() {
126-
127-
}
128-
};
129-
130-
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionsPool(cp).build());
131-
try {
132-
Exception exception = null;
133-
try {
134-
client.prepareGet(getTargetUrl()).execute().get(TIMEOUT, TimeUnit.SECONDS);
135-
} catch (Exception ex) {
136-
ex.printStackTrace();
137-
exception = ex;
138-
}
139-
assertNotNull(exception);
140-
} finally {
141-
client.close();
142-
}
14336
}
14437

14538
@Override

providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public NettyAsyncHttpProvider(AsyncHttpClientConfig config) {
5757
public String toString() {
5858
int availablePermits = channels.freeConnections != null ? channels.freeConnections.availablePermits() : 0;
5959
return String.format("NettyAsyncHttpProvider4:\n\t- maxConnections: %d\n\t- openChannels: %s\n\t- connectionPools: %s", config.getMaxTotalConnections()
60-
- availablePermits, channels.openChannels.toString(), channels.connectionsPool.toString());
60+
- availablePermits, channels.openChannels.toString(), channels.channelPool.toString());
6161
}
6262

6363
@Override

providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Set;
2727

2828
import org.asynchttpclient.AsyncHttpProviderConfig;
29+
import org.asynchttpclient.providers.netty.channel.ChannelPool;
2930
import org.asynchttpclient.providers.netty.response.EagerResponseBodyPart;
3031
import org.asynchttpclient.providers.netty.response.LazyResponseBodyPart;
3132
import org.asynchttpclient.providers.netty.response.ResponseBodyPart;
@@ -83,6 +84,8 @@ public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig<Str
8384

8485
private ResponseBodyPartFactory bodyPartFactory = new EagerResponseBodyPartFactory();
8586

87+
private ChannelPool channelPool;
88+
8689
public NettyAsyncHttpProviderConfig() {
8790
properties.put(REUSE_ADDRESS, Boolean.FALSE);
8891
}
@@ -208,6 +211,14 @@ public void setBodyPartFactory(ResponseBodyPartFactory bodyPartFactory) {
208211
this.bodyPartFactory = bodyPartFactory;
209212
}
210213

214+
public ChannelPool getChannelPool() {
215+
return channelPool;
216+
}
217+
218+
public void setChannelPool(ChannelPool channelPool) {
219+
this.channelPool = channelPool;
220+
}
221+
211222
public static interface AdditionalChannelInitializer {
212223

213224
void initChannel(Channel ch) throws Exception;

0 commit comments

Comments
 (0)