Skip to content

Commit 38070bd

Browse files
committed
Grizzly changes for PR AsyncHttpClient#214.
1 parent 56815d5 commit 38070bd

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

providers/grizzly/src/main/java/com/ning/http/client/providers/grizzly/GrizzlyAsyncHttpProvider.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012 Sonatype, Inc. All rights reserved.
2+
* Copyright (c) 2012-2013 Sonatype, Inc. All rights reserved.
33
*
44
* This program is licensed to you under the Apache License Version 2.0,
55
* and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -18,6 +18,7 @@
1818
import com.ning.http.client.AsyncHttpProvider;
1919
import com.ning.http.client.Body;
2020
import com.ning.http.client.BodyGenerator;
21+
import com.ning.http.client.ConnectionPoolKeyStrategy;
2122
import com.ning.http.client.ConnectionsPool;
2223
import com.ning.http.client.Cookie;
2324
import com.ning.http.client.FluentCaseInsensitiveStringsMap;
@@ -214,9 +215,7 @@ public void completed(final Connection c) {
214215
try {
215216
execute(c, request, handler, future);
216217
} catch (Exception e) {
217-
if (e instanceof RuntimeException) {
218-
failed(e);
219-
} else if (e instanceof IOException) {
218+
if (e instanceof RuntimeException || e instanceof IOException) {
220219
failed(e);
221220
}
222221
if (LOGGER.isWarnEnabled()) {
@@ -1452,7 +1451,7 @@ private static HttpTransactionContext cleanup(final FilterChainContext ctx,
14521451
if (!context.provider.connectionManager.canReturnConnection(c)) {
14531452
context.abort(new IOException("Maximum pooled connections exceeded"));
14541453
} else {
1455-
if (!context.provider.connectionManager.returnConnection(context.requestUrl, c)) {
1454+
if (!context.provider.connectionManager.returnConnection(context.request, c)) {
14561455
ctx.getConnection().close();
14571456
}
14581457
}
@@ -2412,7 +2411,7 @@ void doAsyncTrackedConnection(final Request request,
24122411
final CompletionHandler<Connection> connectHandler)
24132412
throws IOException, ExecutionException, InterruptedException {
24142413
final String url = request.getUrl();
2415-
Connection c = pool.poll(AsyncHttpProviderUtils.getBaseUrl(url));
2414+
Connection c = pool.poll(getPoolKey(request));
24162415
if (c == null) {
24172416
if (!connectionMonitor.acquire()) {
24182417
throw new IOException("Max connections exceeded");
@@ -2497,9 +2496,9 @@ private ProxyServer getProxyServer(Request request) {
24972496

24982497
}
24992498

2500-
boolean returnConnection(final String url, final Connection c) {
2499+
boolean returnConnection(final Request request, final Connection c) {
25012500
final boolean result = (DO_NOT_CACHE.get(c) == null
2502-
&& pool.offer(AsyncHttpProviderUtils.getBaseUrl(url), c));
2501+
&& pool.offer(getPoolKey(request), c));
25032502
if (result) {
25042503
if (provider.resolver != null) {
25052504
provider.resolver.setTimeoutMillis(c, IdleTimeoutFilter.FOREVER);
@@ -2560,6 +2559,11 @@ public void updated(Connection result) {
25602559
};
25612560
}
25622561

2562+
private static String getPoolKey(final Request request) {
2563+
final ConnectionPoolKeyStrategy keyStrategy = request.getConnectionPoolKeyStrategy();
2564+
return keyStrategy.getKey(AsyncHttpProviderUtils.createUri(AsyncHttpProviderUtils.getBaseUrl(request.getUrl())));
2565+
}
2566+
25632567
// ------------------------------------------------------ Nested Classes
25642568

25652569
private static class ConnectionMonitor implements Connection.CloseListener {

0 commit comments

Comments
 (0)