16
16
17
17
package org .springframework .messaging .simp .stomp ;
18
18
19
- import java .util .Collections ;
20
- import java .util .List ;
21
- import java .util .Properties ;
22
-
23
19
import io .netty .channel .EventLoopGroup ;
24
20
import reactor .Environment ;
25
- import reactor .core .config .ConfigurationReader ;
26
- import reactor .core .config .DispatcherConfiguration ;
27
- import reactor .core .config .DispatcherType ;
28
- import reactor .core .config .ReactorConfiguration ;
29
21
import reactor .io .net .NetStreams .TcpClientFactory ;
30
22
import reactor .io .net .Spec .TcpClientSpec ;
31
23
import reactor .io .net .impl .netty .NettyClientSocketOptions ;
@@ -61,9 +53,7 @@ public Reactor2TcpStompClient() {
61
53
}
62
54
63
55
/**
64
- * Create an instance with the given host and port.
65
- * @param host the host
66
- * @param port the port
56
+ * Create an instance with the given host and port to connect to
67
57
*/
68
58
public Reactor2TcpStompClient (String host , int port ) {
69
59
this .eventLoopGroup = Reactor2TcpClient .initEventLoopGroup ();
@@ -87,7 +77,6 @@ public Reactor2TcpStompClient(TcpOperations<byte[]> tcpClient) {
87
77
public void start () {
88
78
if (!isRunning ()) {
89
79
this .running = true ;
90
-
91
80
}
92
81
}
93
82
@@ -108,7 +97,6 @@ public void stop() {
108
97
logger .error ("Failed to shutdown gracefully" , ex );
109
98
}
110
99
}
111
-
112
100
}
113
101
}
114
102
@@ -149,52 +137,37 @@ public void shutdown() {
149
137
}
150
138
151
139
152
- /**
153
- * A ConfigurationReader with a thread pool-based dispatcher.
154
- */
155
- private static class StompClientDispatcherConfigReader implements ConfigurationReader {
156
-
157
- @ Override
158
- public ReactorConfiguration read () {
159
- String dispatcherName = "StompClient" ;
160
- DispatcherType dispatcherType = DispatcherType .DISPATCHER_GROUP ;
161
- DispatcherConfiguration config = new DispatcherConfiguration (dispatcherName , dispatcherType , 128 , 0 );
162
- List <DispatcherConfiguration > configList = Collections .<DispatcherConfiguration >singletonList (config );
163
- return new ReactorConfiguration (configList , dispatcherName , new Properties ());
164
- }
165
- }
166
-
167
-
168
140
private static class StompTcpClientSpecFactory implements TcpClientFactory <Message <byte []>, Message <byte []>> {
169
141
170
142
private final String host ;
171
143
172
144
private final int port ;
173
145
174
- private final EventLoopGroup eventLoopGroup ;
146
+ private final NettyClientSocketOptions socketOptions ;
175
147
176
148
private final Environment environment ;
177
149
150
+ private final Reactor2StompCodec codec ;
151
+
178
152
179
- public StompTcpClientSpecFactory (String host , int port , EventLoopGroup group , Environment environment ) {
153
+ StompTcpClientSpecFactory (String host , int port , EventLoopGroup group , Environment environment ) {
180
154
this .host = host ;
181
155
this .port = port ;
182
- this .eventLoopGroup = group ;
156
+ this .socketOptions = new NettyClientSocketOptions (). eventLoopGroup ( group ) ;
183
157
this .environment = environment ;
158
+ this .codec = new Reactor2StompCodec (new StompEncoder (), new StompDecoder ());
184
159
}
185
160
186
161
@ Override
187
162
public TcpClientSpec <Message <byte []>, Message <byte []>> apply (
188
- TcpClientSpec <Message <byte []>, Message <byte []>> tcpClientSpec ) {
189
-
190
- final Reactor2StompCodec codec = new Reactor2StompCodec (new StompEncoder (), new StompDecoder ());
163
+ TcpClientSpec <Message <byte []>, Message <byte []>> clientSpec ) {
191
164
192
- return tcpClientSpec
165
+ return clientSpec
193
166
.env (this .environment )
194
167
.dispatcher (this .environment .getDispatcher (Environment .WORK_QUEUE ))
195
168
.connect (this .host , this .port )
196
- .codec (codec )
197
- .options (new NettyClientSocketOptions (). eventLoopGroup ( this .eventLoopGroup ) );
169
+ .codec (this . codec )
170
+ .options (this .socketOptions );
198
171
}
199
172
}
200
173
0 commit comments