Skip to content

Commit e570859

Browse files
author
Stephane Landelle
committed
clean up
1 parent 743e728 commit e570859

File tree

5 files changed

+51
-43
lines changed

5 files changed

+51
-43
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +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:
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;
1715

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
import java.util.Set;
3232

3333
/**
34-
* This class can be used to pass Netty's internal configuration options. See Netty documentation for more information.
34+
* This class can be used to pass Netty's internal configuration options. See
35+
* Netty documentation for more information.
3536
*/
3637
public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig<ChannelOption<Object>, Object> {
3738

@@ -41,8 +42,10 @@ public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig<Cha
4142
* Add a property that will be used when the AsyncHttpClient initialize its
4243
* {@link org.asynchttpclient.AsyncHttpProvider}
4344
*
44-
* @param name the name of the property
45-
* @param value the value of the property
45+
* @param name
46+
* the name of the property
47+
* @param value
48+
* the value of the property
4649
* @return this instance of AsyncHttpProviderConfig
4750
*/
4851
public NettyAsyncHttpProviderConfig addProperty(ChannelOption<Object> name, Object value) {
@@ -122,24 +125,19 @@ public NettyResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) {
122125
private AdditionalChannelInitializer wssAdditionalChannelInitializer;
123126

124127
/**
125-
* HttpClientCodec's maxInitialLineLength
128+
* Allow configuring Netty's HttpClientCodecs.
126129
*/
127130
private int httpClientCodecMaxInitialLineLength = 4096;
128-
129-
/**
130-
* HttpClientCodec's maxHeaderSize
131-
*/
132131
private int httpClientCodecMaxHeaderSize = 8192;
133-
134-
/**
135-
* HttpClientCodec's maxChunkSize
136-
*/
137132
private int httpClientCodecMaxChunkSize = 8192;
138133

139134
private ResponseBodyPartFactory bodyPartFactory = new EagerResponseBodyPartFactory();
140135

141136
private ChannelPool channelPool;
142137

138+
/**
139+
* Allow one to disable zero copy for bodies and use chunking instead
140+
*/
143141
private boolean disableZeroCopy;
144142

145143
private Timer nettyTimer;
@@ -148,6 +146,11 @@ public NettyResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) {
148146

149147
private SSLEngineFactory sslEngineFactory;
150148

149+
/**
150+
* chunkedFileChunkSize
151+
*/
152+
private int chunkedFileChunkSize = 8192;
153+
151154
public EventLoopGroup getEventLoopGroup() {
152155
return eventLoopGroup;
153156
}
@@ -259,4 +262,12 @@ public SSLEngineFactory getSslEngineFactory() {
259262
public void setSslEngineFactory(SSLEngineFactory sslEngineFactory) {
260263
this.sslEngineFactory = sslEngineFactory;
261264
}
265+
266+
public int getChunkedFileChunkSize() {
267+
return chunkedFileChunkSize;
268+
}
269+
270+
public void setChunkedFileChunkSize(int chunkedFileChunkSize) {
271+
this.chunkedFileChunkSize = chunkedFileChunkSize;
272+
}
262273
}

providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/ChannelManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,11 @@ public SslHandler createSslHandler(String peerHost, int peerPort) throws IOExcep
362362
return sslHandler;
363363
}
364364

365-
public SslHandler getSslHandler(ChannelPipeline pipeline) {
365+
public static SslHandler getSslHandler(ChannelPipeline pipeline) {
366366
return (SslHandler) pipeline.get(SSL_HANDLER);
367367
}
368368

369-
private boolean isSslHandlerConfigured(ChannelPipeline pipeline) {
369+
public static boolean isSslHandlerConfigured(ChannelPipeline pipeline) {
370370
return pipeline.get(SSL_HANDLER) != null;
371371
}
372372

providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/body/NettyBodyBody.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.asynchttpclient.BodyGenerator;
1919
import org.asynchttpclient.RandomAccessBody;
2020
import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig;
21+
import org.asynchttpclient.providers.netty.channel.ChannelManager;
2122
import org.asynchttpclient.providers.netty.channel.Channels;
2223
import org.asynchttpclient.providers.netty.future.NettyResponseFuture;
2324
import org.asynchttpclient.providers.netty.request.ProgressListener;
@@ -38,11 +39,11 @@ public class NettyBodyBody implements NettyBody {
3839
private static final Logger LOGGER = LoggerFactory.getLogger(NettyBodyBody.class);
3940

4041
private final Body body;
41-
private final boolean disableZeroCopy;
42+
private final NettyAsyncHttpProviderConfig nettyConfig;
4243

4344
public NettyBodyBody(Body body, NettyAsyncHttpProviderConfig nettyConfig) {
4445
this.body = body;
45-
disableZeroCopy = nettyConfig.isDisableZeroCopy();
46+
this.nettyConfig = nettyConfig;
4647
}
4748

4849
public Body getBody() {
@@ -61,9 +62,9 @@ public String getContentType() {
6162

6263
@Override
6364
public void write(final Channel channel, NettyResponseFuture<?> future, AsyncHttpClientConfig config) throws IOException {
64-
Object msg;
6565

66-
if (Channels.getSslHandler(channel) == null && body instanceof RandomAccessBody && !disableZeroCopy) {
66+
Object msg;
67+
if (!ChannelManager.isSslHandlerConfigured(channel.pipeline()) && body instanceof RandomAccessBody && !nettyConfig.isDisableZeroCopy()) {
6768
msg = new BodyFileRegion((RandomAccessBody) body);
6869

6970
} else {

providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/body/NettyFileBody.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313
*/
1414
package org.asynchttpclient.providers.netty.request.body;
1515

16-
import org.asynchttpclient.AsyncHttpClientConfig;
17-
import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig;
18-
import org.asynchttpclient.providers.netty.channel.Channels;
19-
import org.asynchttpclient.providers.netty.future.NettyResponseFuture;
20-
import org.asynchttpclient.providers.netty.request.ProgressListener;
21-
import org.slf4j.Logger;
22-
import org.slf4j.LoggerFactory;
23-
2416
import io.netty.channel.Channel;
2517
import io.netty.channel.ChannelFuture;
2618
import io.netty.channel.ChannelProgressiveFuture;
@@ -33,16 +25,22 @@
3325
import java.io.IOException;
3426
import java.io.RandomAccessFile;
3527

28+
import org.asynchttpclient.AsyncHttpClientConfig;
29+
import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig;
30+
import org.asynchttpclient.providers.netty.channel.ChannelManager;
31+
import org.asynchttpclient.providers.netty.future.NettyResponseFuture;
32+
import org.asynchttpclient.providers.netty.request.ProgressListener;
33+
import org.slf4j.Logger;
34+
import org.slf4j.LoggerFactory;
35+
3636
public class NettyFileBody implements NettyBody {
3737

3838
private static final Logger LOGGER = LoggerFactory.getLogger(NettyFileBody.class);
3939

40-
public final static int MAX_BUFFERED_BYTES = 8192;
41-
4240
private final File file;
4341
private final long offset;
4442
private final long length;
45-
private final boolean disableZeroCopy;
43+
private final NettyAsyncHttpProviderConfig nettyConfig;
4644

4745
public NettyFileBody(File file, NettyAsyncHttpProviderConfig nettyConfig) throws IOException {
4846
this(file, 0, file.length(), nettyConfig);
@@ -55,7 +53,7 @@ public NettyFileBody(File file, long offset, long length, NettyAsyncHttpProvider
5553
this.file = file;
5654
this.offset = offset;
5755
this.length = length;
58-
disableZeroCopy = nettyConfig.isDisableZeroCopy();
56+
this.nettyConfig = nettyConfig;
5957
}
6058

6159
public File getFile() {
@@ -82,8 +80,8 @@ public void write(Channel channel, NettyResponseFuture<?> future, AsyncHttpClien
8280

8381
try {
8482
ChannelFuture writeFuture;
85-
if (Channels.getSslHandler(channel) != null || disableZeroCopy) {
86-
writeFuture = channel.write(new ChunkedFile(raf, offset, length, MAX_BUFFERED_BYTES), channel.newProgressivePromise());
83+
if (ChannelManager.isSslHandlerConfigured(channel.pipeline()) || nettyConfig.isDisableZeroCopy()) {
84+
writeFuture = channel.write(new ChunkedFile(raf, offset, length, nettyConfig.getChunkedFileChunkSize()), channel.newProgressivePromise());
8785
} else {
8886
FileRegion region = new DefaultFileRegion(raf.getChannel(), offset, length);
8987
writeFuture = channel.write(region, channel.newProgressivePromise());

0 commit comments

Comments
 (0)