43
43
* across multiple clients.
44
44
*
45
45
* @author Arjen Poutsma
46
- * @since 4.2
46
+ * @since 4.1. 2
47
47
*/
48
48
public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory ,
49
49
AsyncClientHttpRequestFactory , InitializingBean , DisposableBean {
@@ -59,11 +59,11 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
59
59
60
60
private final boolean defaultEventLoopGroup ;
61
61
62
- private SslContext sslContext ;
63
-
64
62
private int maxRequestSize = DEFAULT_MAX_REQUEST_SIZE ;
65
63
66
- private Bootstrap bootstrap ;
64
+ private SslContext sslContext ;
65
+
66
+ private volatile Bootstrap bootstrap ;
67
67
68
68
69
69
/**
@@ -79,13 +79,12 @@ public Netty4ClientHttpRequestFactory() {
79
79
/**
80
80
* Create a new {@code Netty4ClientHttpRequestFactory} with the given
81
81
* {@link EventLoopGroup}.
82
- *
83
82
* <p><b>NOTE:</b> the given group will <strong>not</strong> be
84
- * {@linkplain EventLoopGroup#shutdownGracefully() shutdown} by this factory; doing
85
- * so becomes the responsibility of the caller.
83
+ * {@linkplain EventLoopGroup#shutdownGracefully() shutdown} by this factory;
84
+ * doing so becomes the responsibility of the caller.
86
85
*/
87
86
public Netty4ClientHttpRequestFactory (EventLoopGroup eventLoopGroup ) {
88
- Assert .notNull (eventLoopGroup , "'eventLoopGroup' must not be null" );
87
+ Assert .notNull (eventLoopGroup , "EventLoopGroup must not be null" );
89
88
this .eventLoopGroup = eventLoopGroup ;
90
89
this .defaultEventLoopGroup = false ;
91
90
}
@@ -117,7 +116,6 @@ private Bootstrap getBootstrap() {
117
116
@ Override
118
117
protected void initChannel (SocketChannel channel ) throws Exception {
119
118
ChannelPipeline pipeline = channel .pipeline ();
120
-
121
119
if (sslContext != null ) {
122
120
pipeline .addLast (sslContext .newHandler (channel .alloc ()));
123
121
}
@@ -131,10 +129,11 @@ protected void initChannel(SocketChannel channel) throws Exception {
131
129
}
132
130
133
131
@ Override
134
- public void afterPropertiesSet () throws Exception {
132
+ public void afterPropertiesSet () {
135
133
getBootstrap ();
136
134
}
137
135
136
+
138
137
@ Override
139
138
public ClientHttpRequest createRequest (URI uri , HttpMethod httpMethod ) throws IOException {
140
139
return createRequestInternal (uri , httpMethod );
@@ -149,10 +148,11 @@ private Netty4ClientHttpRequest createRequestInternal(URI uri, HttpMethod httpMe
149
148
return new Netty4ClientHttpRequest (getBootstrap (), uri , httpMethod , this .maxRequestSize );
150
149
}
151
150
151
+
152
152
@ Override
153
153
public void destroy () throws InterruptedException {
154
154
if (this .defaultEventLoopGroup ) {
155
- // clean up the EventLoopGroup if we created it in the constructor
155
+ // Clean up the EventLoopGroup if we created it in the constructor
156
156
this .eventLoopGroup .shutdownGracefully ().sync ();
157
157
}
158
158
}
0 commit comments