22
22
import org .asynchttpclient .providers .netty .response .EagerResponseBodyPart ;
23
23
import org .asynchttpclient .providers .netty .response .LazyResponseBodyPart ;
24
24
import org .asynchttpclient .providers .netty .response .NettyResponseBodyPart ;
25
- import org .slf4j .Logger ;
26
- import org .slf4j .LoggerFactory ;
27
25
28
26
import io .netty .buffer .ByteBuf ;
29
27
import io .netty .channel .Channel ;
38
36
/**
39
37
* This class can be used to pass Netty's internal configuration options. See Netty documentation for more information.
40
38
*/
41
- public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig <String , Object > {
39
+ public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig <ChannelOption < Object > , Object > {
42
40
43
- private final static Logger LOGGER = LoggerFactory .getLogger (NettyAsyncHttpProviderConfig .class );
44
-
45
- /**
46
- * Allow configuring the Netty's event loop.
47
- */
48
- private EventLoopGroup eventLoopGroup ;
49
-
50
- private AdditionalChannelInitializer httpAdditionalChannelInitializer ;
51
- private AdditionalChannelInitializer wsAdditionalChannelInitializer ;
52
- private AdditionalChannelInitializer httpsAdditionalChannelInitializer ;
53
- private AdditionalChannelInitializer wssAdditionalChannelInitializer ;
54
-
55
- /**
56
- * HttpClientCodec's maxInitialLineLength
57
- */
58
- private int maxInitialLineLength = 4096 ;
59
-
60
- /**
61
- * HttpClientCodec's maxHeaderSize
62
- */
63
- private int maxHeaderSize = 8192 ;
64
-
65
- /**
66
- * HttpClientCodec's maxChunkSize
67
- */
68
- private int maxChunkSize = 8192 ;
69
-
70
- /**
71
- * Use direct {@link java.nio.ByteBuffer}
72
- */
73
- public final static String USE_DIRECT_BYTEBUFFER = "bufferFactory" ;
74
-
75
- /**
76
- * Allow nested request from any {@link org.asynchttpclient.AsyncHandler}
77
- */
78
- public final static String DISABLE_NESTED_REQUEST = "disableNestedRequest" ;
79
-
80
- /**
81
- * See {@link java.net.Socket#setReuseAddress(boolean)}
82
- */
83
- public final static String REUSE_ADDRESS = ChannelOption .SO_REUSEADDR .name ();
84
-
85
- private final Map <String , Object > properties = new HashMap <String , Object >();
86
-
87
- private ResponseBodyPartFactory bodyPartFactory = new EagerResponseBodyPartFactory ();
88
-
89
- private ChannelPool channelPool ;
90
-
91
- private boolean disableZeroCopy ;
92
-
93
- private Timer nettyTimer ;
94
-
95
- private long handshakeTimeoutInMillis ;
96
-
97
- private SSLEngineFactory sslEngineFactory ;
98
-
99
- public NettyAsyncHttpProviderConfig () {
100
- properties .put (REUSE_ADDRESS , Boolean .FALSE );
101
- }
41
+ private final Map <ChannelOption <Object >, Object > properties = new HashMap <ChannelOption <Object >, Object >();
102
42
103
43
/**
104
44
* Add a property that will be used when the AsyncHttpClient initialize its
@@ -108,16 +48,14 @@ public NettyAsyncHttpProviderConfig() {
108
48
* @param value the value of the property
109
49
* @return this instance of AsyncHttpProviderConfig
110
50
*/
111
- public NettyAsyncHttpProviderConfig addProperty (String name , Object value ) {
112
-
113
- if (name .equals (REUSE_ADDRESS )//
114
- && value == Boolean .TRUE //
115
- && System .getProperty ("os.name" ).toLowerCase ().contains ("win" )) {
116
- LOGGER .warn ("Can't enable {} on Windows" , REUSE_ADDRESS );
117
- } else {
118
- properties .put (name , value );
119
- }
51
+ public NettyAsyncHttpProviderConfig addProperty (ChannelOption <Object > name , Object value ) {
52
+ properties .put (name , value );
53
+ return this ;
54
+ }
120
55
56
+ @ SuppressWarnings ("unchecked" )
57
+ public <T > NettyAsyncHttpProviderConfig addChannelOption (ChannelOption <T > name , T value ) {
58
+ properties .put ((ChannelOption <Object >) name , value );
121
59
return this ;
122
60
}
123
61
@@ -127,7 +65,7 @@ public NettyAsyncHttpProviderConfig addProperty(String name, Object value) {
127
65
* @param name
128
66
* @return this instance of AsyncHttpProviderConfig
129
67
*/
130
- public Object getProperty (String name ) {
68
+ public Object getProperty (ChannelOption < Object > name ) {
131
69
return properties .get (name );
132
70
}
133
71
@@ -137,7 +75,7 @@ public Object getProperty(String name) {
137
75
* @param name
138
76
* @return true if removed
139
77
*/
140
- public Object removeProperty (String name ) {
78
+ public Object removeProperty (ChannelOption < Object > name ) {
141
79
return properties .remove (name );
142
80
}
143
81
@@ -146,40 +84,79 @@ public Object removeProperty(String name) {
146
84
*
147
85
* @return a the curent entry set.
148
86
*/
149
- public Set <Map .Entry <String , Object >> propertiesSet () {
87
+ public Set <Map .Entry <ChannelOption < Object > , Object >> propertiesSet () {
150
88
return properties .entrySet ();
151
89
}
152
90
153
- public EventLoopGroup getEventLoopGroup () {
154
- return eventLoopGroup ;
155
- }
91
+ public static interface AdditionalChannelInitializer {
156
92
157
- public void setEventLoopGroup (EventLoopGroup eventLoopGroup ) {
158
- this .eventLoopGroup = eventLoopGroup ;
93
+ void initChannel (Channel ch ) throws Exception ;
159
94
}
160
95
161
- public int getMaxInitialLineLength () {
162
- return maxInitialLineLength ;
163
- }
96
+ public static interface ResponseBodyPartFactory {
164
97
165
- public void setMaxInitialLineLength (int maxInitialLineLength ) {
166
- this .maxInitialLineLength = maxInitialLineLength ;
98
+ NettyResponseBodyPart newResponseBodyPart (ByteBuf buf , boolean last );
167
99
}
168
100
169
- public int getMaxHeaderSize () {
170
- return maxHeaderSize ;
101
+ public static class EagerResponseBodyPartFactory implements ResponseBodyPartFactory {
102
+
103
+ @ Override
104
+ public NettyResponseBodyPart newResponseBodyPart (ByteBuf buf , boolean last ) {
105
+ return new EagerResponseBodyPart (buf , last );
106
+ }
171
107
}
172
108
173
- public void setMaxHeaderSize (int maxHeaderSize ) {
174
- this .maxHeaderSize = maxHeaderSize ;
109
+ public static class LazyResponseBodyPartFactory implements ResponseBodyPartFactory {
110
+
111
+ @ Override
112
+ public NettyResponseBodyPart newResponseBodyPart (ByteBuf buf , boolean last ) {
113
+ return new LazyResponseBodyPart (buf , last );
114
+ }
175
115
}
176
116
177
- public int getMaxChunkSize () {
178
- return maxChunkSize ;
117
+ /**
118
+ * Allow configuring the Netty's event loop.
119
+ */
120
+ private EventLoopGroup eventLoopGroup ;
121
+
122
+ private AdditionalChannelInitializer httpAdditionalChannelInitializer ;
123
+ private AdditionalChannelInitializer wsAdditionalChannelInitializer ;
124
+ private AdditionalChannelInitializer httpsAdditionalChannelInitializer ;
125
+ private AdditionalChannelInitializer wssAdditionalChannelInitializer ;
126
+
127
+ /**
128
+ * HttpClientCodec's maxInitialLineLength
129
+ */
130
+ private int maxInitialLineLength = 4096 ;
131
+
132
+ /**
133
+ * HttpClientCodec's maxHeaderSize
134
+ */
135
+ private int maxHeaderSize = 8192 ;
136
+
137
+ /**
138
+ * HttpClientCodec's maxChunkSize
139
+ */
140
+ private int maxChunkSize = 8192 ;
141
+
142
+ private ResponseBodyPartFactory bodyPartFactory = new EagerResponseBodyPartFactory ();
143
+
144
+ private ChannelPool channelPool ;
145
+
146
+ private boolean disableZeroCopy ;
147
+
148
+ private Timer nettyTimer ;
149
+
150
+ private long handshakeTimeoutInMillis ;
151
+
152
+ private SSLEngineFactory sslEngineFactory ;
153
+
154
+ public EventLoopGroup getEventLoopGroup () {
155
+ return eventLoopGroup ;
179
156
}
180
157
181
- public void setMaxChunkSize ( int maxChunkSize ) {
182
- this .maxChunkSize = maxChunkSize ;
158
+ public void setEventLoopGroup ( EventLoopGroup eventLoopGroup ) {
159
+ this .eventLoopGroup = eventLoopGroup ;
183
160
}
184
161
185
162
public AdditionalChannelInitializer getHttpAdditionalChannelInitializer () {
@@ -214,6 +191,30 @@ public void setWssAdditionalChannelInitializer(AdditionalChannelInitializer wssA
214
191
this .wssAdditionalChannelInitializer = wssAdditionalChannelInitializer ;
215
192
}
216
193
194
+ public int getMaxInitialLineLength () {
195
+ return maxInitialLineLength ;
196
+ }
197
+
198
+ public void setMaxInitialLineLength (int maxInitialLineLength ) {
199
+ this .maxInitialLineLength = maxInitialLineLength ;
200
+ }
201
+
202
+ public int getMaxHeaderSize () {
203
+ return maxHeaderSize ;
204
+ }
205
+
206
+ public void setMaxHeaderSize (int maxHeaderSize ) {
207
+ this .maxHeaderSize = maxHeaderSize ;
208
+ }
209
+
210
+ public int getMaxChunkSize () {
211
+ return maxChunkSize ;
212
+ }
213
+
214
+ public void setMaxChunkSize (int maxChunkSize ) {
215
+ this .maxChunkSize = maxChunkSize ;
216
+ }
217
+
217
218
public ResponseBodyPartFactory getBodyPartFactory () {
218
219
return bodyPartFactory ;
219
220
}
@@ -253,38 +254,12 @@ public long getHandshakeTimeoutInMillis() {
253
254
public void setHandshakeTimeoutInMillis (long handshakeTimeoutInMillis ) {
254
255
this .handshakeTimeoutInMillis = handshakeTimeoutInMillis ;
255
256
}
256
-
257
+
257
258
public SSLEngineFactory getSslEngineFactory () {
258
259
return sslEngineFactory ;
259
260
}
260
261
261
262
public void setSslEngineFactory (SSLEngineFactory sslEngineFactory ) {
262
263
this .sslEngineFactory = sslEngineFactory ;
263
264
}
264
-
265
- public static interface AdditionalChannelInitializer {
266
-
267
- void initChannel (Channel ch ) throws Exception ;
268
- }
269
-
270
- public static interface ResponseBodyPartFactory {
271
-
272
- NettyResponseBodyPart newResponseBodyPart (ByteBuf buf , boolean last );
273
- }
274
-
275
- public static class EagerResponseBodyPartFactory implements ResponseBodyPartFactory {
276
-
277
- @ Override
278
- public NettyResponseBodyPart newResponseBodyPart (ByteBuf buf , boolean last ) {
279
- return new EagerResponseBodyPart (buf , last );
280
- }
281
- }
282
-
283
- public static class LazyResponseBodyPartFactory implements ResponseBodyPartFactory {
284
-
285
- @ Override
286
- public NettyResponseBodyPart newResponseBodyPart (ByteBuf buf , boolean last ) {
287
- return new LazyResponseBodyPart (buf , last );
288
- }
289
- }
290
265
}
0 commit comments