Skip to content

Commit 75de57a

Browse files
committed
Initial connection pool changes to support SPDY.
1 parent e3af1bc commit 75de57a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
package org.asynchttpclient.providers.grizzly;
1515

16+
import org.glassfish.grizzly.CompletionHandler;
17+
import org.glassfish.grizzly.Connection;
18+
import org.glassfish.grizzly.EmptyCompletionHandler;
19+
import org.glassfish.grizzly.GrizzlyFuture;
1620
import org.glassfish.grizzly.connectionpool.EndpointKey;
1721
import org.glassfish.grizzly.connectionpool.MultiEndpointPool;
1822
import org.glassfish.grizzly.connectionpool.SingleEndpointPool;
@@ -29,6 +33,7 @@
2933
*/
3034
public class ConnectionPool extends MultiEndpointPool<SocketAddress>{
3135

36+
private final Object lock = new Object();
3237

3338
// ------------------------------------------------------------ Constructors
3439

@@ -69,6 +74,62 @@ protected SingleEndpointPool<SocketAddress> obtainSingleEndpointPool(
6974
return sePool;
7075
}
7176

77+
@Override
78+
public GrizzlyFuture<Connection> take(final EndpointKey<SocketAddress> endpointKey) {
79+
synchronized (lock) {
80+
final GrizzlyFuture<Connection> f = super.take(endpointKey);
81+
f.addCompletionHandler(new EmptyCompletionHandler<Connection>() {
82+
@Override
83+
public void completed(Connection result) {
84+
if (Utils.isSpdyConnection(result)) {
85+
release(result);
86+
}
87+
super.completed(result);
88+
}
89+
});
90+
return f;
91+
}
92+
}
93+
94+
@Override
95+
public void take(final EndpointKey<SocketAddress> endpointKey,
96+
final CompletionHandler<Connection> completionHandler) {
97+
synchronized (lock) {
98+
if (completionHandler == null) {
99+
throw new IllegalStateException("CompletionHandler argument cannot be null.");
100+
}
101+
102+
super.take(endpointKey, new CompletionHandler<Connection>() {
103+
@Override
104+
public void cancelled() {
105+
completionHandler.cancelled();
106+
}
107+
108+
@Override
109+
public void failed(Throwable throwable) {
110+
completionHandler.failed(throwable);
111+
}
112+
113+
@Override
114+
public void completed(Connection result) {
115+
release(result);
116+
completionHandler.completed(result);
117+
}
118+
119+
@Override
120+
public void updated(Connection result) {
121+
completionHandler.updated(result);
122+
}
123+
});
124+
}
125+
}
126+
127+
@Override
128+
public boolean release(Connection connection) {
129+
synchronized (lock) {
130+
return super.release(connection);
131+
}
132+
}
72133

73134
// ---------------------------------------------------------- Nested Classes
74135

0 commit comments

Comments
 (0)