Skip to content

Commit dd92f36

Browse files
author
Stephane Landelle
committed
Make AHC 1.9 and AHC2 code converge, close AsyncHttpClient#638
1 parent 34a95f0 commit dd92f36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1290
-1421
lines changed

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

100644100755
File mode changed.

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

100644100755
Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,74 @@
11
/*
2-
* Copyright 2010-2013 Ning, Inc.
2+
* Copyright (c) 2014 AsyncHttpClient Project. All rights reserved.
33
*
4-
* Ning licenses this file to you under the Apache License, version 2.0
5-
* (the "License"); you may not use this file except in compliance with the
6-
* License. You may obtain a copy of the License at:
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at
7+
* http://www.apache.org/licenses/LICENSE-2.0.
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations
14-
* under the License.
9+
* Unless required by applicable law or agreed to in writing,
10+
* software distributed under the Apache License Version 2.0 is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1513
*/
1614
package org.asynchttpclient.providers.netty;
1715

16+
import io.netty.util.HashedWheelTimer;
17+
import io.netty.util.Timer;
18+
19+
import java.io.IOException;
20+
import java.util.concurrent.atomic.AtomicBoolean;
21+
1822
import org.asynchttpclient.AsyncHandler;
1923
import org.asynchttpclient.AsyncHttpClientConfig;
2024
import org.asynchttpclient.AsyncHttpProvider;
2125
import org.asynchttpclient.ListenableFuture;
2226
import org.asynchttpclient.Request;
23-
import org.asynchttpclient.providers.netty.channel.Channels;
27+
import org.asynchttpclient.providers.netty.channel.ChannelManager;
2428
import org.asynchttpclient.providers.netty.request.NettyRequestSender;
2529
import org.slf4j.Logger;
2630
import org.slf4j.LoggerFactory;
2731

28-
import java.io.IOException;
29-
import java.util.concurrent.atomic.AtomicBoolean;
30-
3132
public class NettyAsyncHttpProvider implements AsyncHttpProvider {
3233

3334
private static final Logger LOGGER = LoggerFactory.getLogger(NettyAsyncHttpProvider.class);
3435

3536
private final NettyAsyncHttpProviderConfig nettyConfig;
3637
private final AtomicBoolean closed = new AtomicBoolean(false);
37-
private final Channels channels;
38+
private final ChannelManager channelManager;
3839
private final NettyRequestSender requestSender;
40+
private final boolean allowStopNettyTimer;
41+
private final Timer nettyTimer;
3942

4043
public NettyAsyncHttpProvider(AsyncHttpClientConfig config) {
4144

4245
nettyConfig = config.getAsyncHttpProviderConfig() instanceof NettyAsyncHttpProviderConfig ? //
4346
(NettyAsyncHttpProviderConfig) config.getAsyncHttpProviderConfig()
4447
: new NettyAsyncHttpProviderConfig();
4548

46-
channels = new Channels(config, nettyConfig);
47-
requestSender = new NettyRequestSender(closed, config, nettyConfig, channels);
48-
channels.configureProcessor(requestSender, closed);
49+
allowStopNettyTimer = nettyConfig.getNettyTimer() == null;
50+
nettyTimer = allowStopNettyTimer ? newNettyTimer() : nettyConfig.getNettyTimer();
51+
52+
channelManager = new ChannelManager(config, nettyConfig, nettyTimer);
53+
requestSender = new NettyRequestSender(config, nettyConfig, channelManager, nettyTimer, closed);
54+
channelManager.configureBootstraps(requestSender, closed);
55+
}
56+
57+
private Timer newNettyTimer() {
58+
HashedWheelTimer timer = new HashedWheelTimer();
59+
timer.start();
60+
return timer;
4961
}
5062

5163
@Override
5264
public void close() {
5365
if (closed.compareAndSet(false, true)) {
5466
try {
55-
channels.close();
67+
channelManager.close();
68+
69+
if (allowStopNettyTimer)
70+
nettyTimer.stop();
71+
5672
} catch (Throwable t) {
5773
LOGGER.warn("Unexpected error on close", t);
5874
}

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

100644100755
Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
/*
2-
* Copyright 2010 Ning, Inc.
2+
* Copyright (c) 2014 AsyncHttpClient Project. All rights reserved.
33
*
4-
* Ning licenses this file to you under the Apache License, version 2.0
5-
* (the "License"); you may not use this file except in compliance with the
6-
* License. You may obtain a copy of the License at:
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations
14-
* under the License.
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at
7+
* http://www.apache.org/licenses/LICENSE-2.0.
158
*
9+
* Unless required by applicable law or agreed to in writing,
10+
* software distributed under the Apache License Version 2.0 is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1613
*/
1714
package org.asynchttpclient.providers.netty;
1815

@@ -127,17 +124,17 @@ public NettyResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) {
127124
/**
128125
* HttpClientCodec's maxInitialLineLength
129126
*/
130-
private int maxInitialLineLength = 4096;
127+
private int httpClientCodecMaxInitialLineLength = 4096;
131128

132129
/**
133130
* HttpClientCodec's maxHeaderSize
134131
*/
135-
private int maxHeaderSize = 8192;
132+
private int httpClientCodecMaxHeaderSize = 8192;
136133

137134
/**
138135
* HttpClientCodec's maxChunkSize
139136
*/
140-
private int maxChunkSize = 8192;
137+
private int httpClientCodecMaxChunkSize = 8192;
141138

142139
private ResponseBodyPartFactory bodyPartFactory = new EagerResponseBodyPartFactory();
143140

@@ -191,28 +188,28 @@ public void setWssAdditionalChannelInitializer(AdditionalChannelInitializer wssA
191188
this.wssAdditionalChannelInitializer = wssAdditionalChannelInitializer;
192189
}
193190

194-
public int getMaxInitialLineLength() {
195-
return maxInitialLineLength;
191+
public int getHttpClientCodecMaxInitialLineLength() {
192+
return httpClientCodecMaxInitialLineLength;
196193
}
197194

198-
public void setMaxInitialLineLength(int maxInitialLineLength) {
199-
this.maxInitialLineLength = maxInitialLineLength;
195+
public void setHttpClientCodecMaxInitialLineLength(int httpClientCodecMaxInitialLineLength) {
196+
this.httpClientCodecMaxInitialLineLength = httpClientCodecMaxInitialLineLength;
200197
}
201198

202-
public int getMaxHeaderSize() {
203-
return maxHeaderSize;
199+
public int getHttpClientCodecMaxHeaderSize() {
200+
return httpClientCodecMaxHeaderSize;
204201
}
205202

206-
public void setMaxHeaderSize(int maxHeaderSize) {
207-
this.maxHeaderSize = maxHeaderSize;
203+
public void setHttpClientCodecMaxHeaderSize(int httpClientCodecMaxHeaderSize) {
204+
this.httpClientCodecMaxHeaderSize = httpClientCodecMaxHeaderSize;
208205
}
209206

210-
public int getMaxChunkSize() {
211-
return maxChunkSize;
207+
public int getHttpClientCodecMaxChunkSize() {
208+
return httpClientCodecMaxChunkSize;
212209
}
213210

214-
public void setMaxChunkSize(int maxChunkSize) {
215-
this.maxChunkSize = maxChunkSize;
211+
public void setHttpClientCodecMaxChunkSize(int httpClientCodecMaxChunkSize) {
212+
this.httpClientCodecMaxChunkSize = httpClientCodecMaxChunkSize;
216213
}
217214

218215
public ResponseBodyPartFactory getBodyPartFactory() {

0 commit comments

Comments
 (0)