Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita09d9ba

Browse files
author
Stephane Landelle
committed
Add an option for disabling zero-copy in Netty provider,closeAsyncHttpClient#380
1 parent8b58fe1 commita09d9ba

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

‎src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,17 @@ public boolean remove(Object o) {
202202
};
203203
privatefinalConnectionsPool<String,Channel>connectionsPool;
204204
privateSemaphorefreeConnections =null;
205-
privatefinalNettyAsyncHttpProviderConfigasyncHttpProviderConfig;
205+
privatefinalNettyAsyncHttpProviderConfigproviderConfig;
206206
privatebooleanexecuteConnectAsync =true;
207207
publicstaticfinalThreadLocal<Boolean>IN_IO_THREAD =newThreadLocalBoolean();
208208
privatefinalbooleantrackConnections;
209209
privatefinalbooleanuseRawUrl;
210+
privatefinalbooleandisableZeroCopy;
210211
privatefinalstaticNTLMEnginentlmEngine =newNTLMEngine();
211212
privatestaticSpnegoEnginespnegoEngine =null;
212213
privatefinalProtocolhttpProtocol =newHttpProtocol();
213214
privatefinalProtocolwebSocketProtocol =newWebSocketProtocol();
214-
privateHashedWheelTimerhashedWheelTimer;
215+
privatefinalHashedWheelTimerhashedWheelTimer;
215216

216217
privatestaticbooleanisNTLM(List<String>auth) {
217218
returnisNonEmpty(auth) &&auth.get(0).startsWith("NTLM");
@@ -220,29 +221,29 @@ private static boolean isNTLM(List<String> auth) {
220221
publicNettyAsyncHttpProvider(AsyncHttpClientConfigconfig) {
221222

222223
if (config.getAsyncHttpProviderConfig()instanceofNettyAsyncHttpProviderConfig) {
223-
asyncHttpProviderConfig =NettyAsyncHttpProviderConfig.class.cast(config.getAsyncHttpProviderConfig());
224+
providerConfig =NettyAsyncHttpProviderConfig.class.cast(config.getAsyncHttpProviderConfig());
224225
}else {
225-
asyncHttpProviderConfig =newNettyAsyncHttpProviderConfig();
226+
providerConfig =newNettyAsyncHttpProviderConfig();
226227
}
227228

228229
if (config.getRequestCompressionLevel() >0) {
229230
LOGGER.warn("Request was enabled but Netty actually doesn't support this feature");
230231
}
231232

232-
if (asyncHttpProviderConfig.getProperty(USE_BLOCKING_IO) !=null) {
233+
if (providerConfig.getProperty(USE_BLOCKING_IO) !=null) {
233234
socketChannelFactory =newOioClientSocketChannelFactory(config.executorService());
234235
this.allowReleaseSocketChannelFactory =true;
235236
}else {
236237
// check if external NioClientSocketChannelFactory is defined
237-
Objectoo =asyncHttpProviderConfig.getProperty(SOCKET_CHANNEL_FACTORY);
238+
Objectoo =providerConfig.getProperty(SOCKET_CHANNEL_FACTORY);
238239
if (ooinstanceofNioClientSocketChannelFactory) {
239240
this.socketChannelFactory =NioClientSocketChannelFactory.class.cast(oo);
240241

241242
// cannot allow releasing shared channel factory
242243
this.allowReleaseSocketChannelFactory =false;
243244
}else {
244245
ExecutorServicee;
245-
Objecto =asyncHttpProviderConfig.getProperty(BOSS_EXECUTOR_SERVICE);
246+
Objecto =providerConfig.getProperty(BOSS_EXECUTOR_SERVICE);
246247
if (oinstanceofExecutorService) {
247248
e =ExecutorService.class.cast(o);
248249
}else {
@@ -279,7 +280,7 @@ public NettyAsyncHttpProvider(AsyncHttpClientConfig config) {
279280
}
280281

281282
useRawUrl =config.isUseRawUrl();
282-
283+
disableZeroCopy =providerConfig.isDisableZeroCopy();
283284
hashedWheelTimer =newHashedWheelTimer();
284285
hashedWheelTimer.start();
285286
}
@@ -294,8 +295,8 @@ public String toString() {
294295
}
295296

296297
voidconfigureNetty() {
297-
if (asyncHttpProviderConfig !=null) {
298-
for (Entry<String,Object>entry :asyncHttpProviderConfig.propertiesSet()) {
298+
if (providerConfig !=null) {
299+
for (Entry<String,Object>entry :providerConfig.propertiesSet()) {
299300
plainBootstrap.setOption(entry.getKey(),entry.getValue());
300301
}
301302
configureHttpClientCodec();
@@ -304,7 +305,6 @@ void configureNetty() {
304305

305306
plainBootstrap.setPipelineFactory(newChannelPipelineFactory() {
306307

307-
/* @Override */
308308
publicChannelPipelinegetPipeline()throwsException {
309309
ChannelPipelinepipeline =pipeline();
310310

@@ -320,11 +320,11 @@ public ChannelPipeline getPipeline() throws Exception {
320320
});
321321
DefaultChannelFuture.setUseDeadLockChecker(false);
322322

323-
if (asyncHttpProviderConfig !=null) {
324-
Objectvalue =asyncHttpProviderConfig.getProperty(EXECUTE_ASYNC_CONNECT);
323+
if (providerConfig !=null) {
324+
Objectvalue =providerConfig.getProperty(EXECUTE_ASYNC_CONNECT);
325325
if (valueinstanceofBoolean) {
326326
executeConnectAsync =Boolean.class.cast(value);
327-
}elseif (asyncHttpProviderConfig.getProperty(DISABLE_NESTED_REQUEST) !=null) {
327+
}elseif (providerConfig.getProperty(DISABLE_NESTED_REQUEST) !=null) {
328328
DefaultChannelFuture.setUseDeadLockChecker(true);
329329
}
330330
}
@@ -343,15 +343,15 @@ public ChannelPipeline getPipeline() throws Exception {
343343
}
344344

345345
protectedvoidconfigureHttpClientCodec() {
346-
httpClientCodecMaxInitialLineLength =asyncHttpProviderConfig.getProperty(HTTP_CLIENT_CODEC_MAX_INITIAL_LINE_LENGTH,Integer.class,httpClientCodecMaxInitialLineLength);
347-
httpClientCodecMaxHeaderSize =asyncHttpProviderConfig.getProperty(HTTP_CLIENT_CODEC_MAX_HEADER_SIZE,Integer.class,httpClientCodecMaxHeaderSize);
348-
httpClientCodecMaxChunkSize =asyncHttpProviderConfig.getProperty(HTTP_CLIENT_CODEC_MAX_CHUNK_SIZE,Integer.class,httpClientCodecMaxChunkSize);
346+
httpClientCodecMaxInitialLineLength =providerConfig.getProperty(HTTP_CLIENT_CODEC_MAX_INITIAL_LINE_LENGTH,Integer.class,httpClientCodecMaxInitialLineLength);
347+
httpClientCodecMaxHeaderSize =providerConfig.getProperty(HTTP_CLIENT_CODEC_MAX_HEADER_SIZE,Integer.class,httpClientCodecMaxHeaderSize);
348+
httpClientCodecMaxChunkSize =providerConfig.getProperty(HTTP_CLIENT_CODEC_MAX_CHUNK_SIZE,Integer.class,httpClientCodecMaxChunkSize);
349349
}
350350

351351
protectedvoidconfigureHttpsClientCodec() {
352-
httpsClientCodecMaxInitialLineLength =asyncHttpProviderConfig.getProperty(HTTPS_CLIENT_CODEC_MAX_INITIAL_LINE_LENGTH,Integer.class,httpsClientCodecMaxInitialLineLength);
353-
httpsClientCodecMaxHeaderSize =asyncHttpProviderConfig.getProperty(HTTPS_CLIENT_CODEC_MAX_HEADER_SIZE,Integer.class,httpsClientCodecMaxHeaderSize);
354-
httpsClientCodecMaxChunkSize =asyncHttpProviderConfig.getProperty(HTTPS_CLIENT_CODEC_MAX_CHUNK_SIZE,Integer.class,httpsClientCodecMaxChunkSize);
352+
httpsClientCodecMaxInitialLineLength =providerConfig.getProperty(HTTPS_CLIENT_CODEC_MAX_INITIAL_LINE_LENGTH,Integer.class,httpsClientCodecMaxInitialLineLength);
353+
httpsClientCodecMaxHeaderSize =providerConfig.getProperty(HTTPS_CLIENT_CODEC_MAX_HEADER_SIZE,Integer.class,httpsClientCodecMaxHeaderSize);
354+
httpsClientCodecMaxChunkSize =providerConfig.getProperty(HTTPS_CLIENT_CODEC_MAX_CHUNK_SIZE,Integer.class,httpsClientCodecMaxChunkSize);
355355
}
356356

357357
voidconstructSSLPipeline(finalNettyConnectListener<?>cl) {
@@ -399,8 +399,8 @@ public ChannelPipeline getPipeline() throws Exception {
399399
}
400400
});
401401

402-
if (asyncHttpProviderConfig !=null) {
403-
for (Entry<String,Object>entry :asyncHttpProviderConfig.propertiesSet()) {
402+
if (providerConfig !=null) {
403+
for (Entry<String,Object>entry :providerConfig.propertiesSet()) {
404404
secureBootstrap.setOption(entry.getKey(),entry.getValue());
405405
secureWebSocketBootstrap.setOption(entry.getKey(),entry.getValue());
406406
}
@@ -544,7 +544,7 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
544544
fileLength =raf.length();
545545

546546
ChannelFuturewriteFuture;
547-
if (ssl) {
547+
if (ssl ||disableZeroCopy) {
548548
writeFuture =channel.write(newChunkedFile(raf,0,fileLength,MAX_BUFFERED_BYTES));
549549
}else {
550550
finalFileRegionregion =newOptimizedFileRegion(raf,0,fileLength);
@@ -572,7 +572,7 @@ public void operationComplete(ChannelFuture cf) {
572572
}elseif (body !=null) {
573573

574574
ChannelFuturewriteFuture;
575-
if (!ssl &&bodyinstanceofRandomAccessBody) {
575+
if (!ssl &&!disableZeroCopy &&bodyinstanceofRandomAccessBody) {
576576
BodyFileRegionbodyFileRegion =newBodyFileRegion((RandomAccessBody)body);
577577
writeFuture =channel.write(bodyFileRegion);
578578
}else {
@@ -1059,7 +1059,7 @@ private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHand
10591059

10601060
// Do no enable this with win.
10611061
if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win")) {
1062-
bootstrap.setOption("reuseAddress",asyncHttpProviderConfig.getProperty(REUSE_ADDRESS));
1062+
bootstrap.setOption("reuseAddress",providerConfig.getProperty(REUSE_ADDRESS));
10631063
}
10641064

10651065
try {

‎src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProviderConfig.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig<Str
7878

7979
privatefinalConcurrentHashMap<String,Object>properties =newConcurrentHashMap<String,Object>();
8080

81+
/**
82+
* Allow one to disable zero copy for bodies and use chunking instead;
83+
*/
84+
privatebooleandisableZeroCopy;
85+
8186
publicNettyAsyncHttpProviderConfig() {
8287
properties.put(REUSE_ADDRESS,"false");
8388
}
@@ -136,4 +141,12 @@ public Object removeProperty(String name) {
136141
publicSet<Map.Entry<String,Object>>propertiesSet() {
137142
returnproperties.entrySet();
138143
}
144+
145+
publicvoidsetDisableZeroCopy(booleandisableZeroCopy) {
146+
this.disableZeroCopy =disableZeroCopy;
147+
}
148+
149+
publicbooleanisDisableZeroCopy() {
150+
returndisableZeroCopy;
151+
}
139152
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp