|
6 | 6 | import io.netty.channel.nio.NioEventLoopGroup; |
7 | 7 | import io.netty.util.concurrent.DefaultThreadFactory; |
8 | 8 | import io.netty.util.concurrent.Future; |
9 | | -import io.rsocket.transport.netty.client.TcpClientTransport; |
10 | | -import io.rsocket.transport.netty.server.TcpServerTransport; |
11 | 9 | import io.scalecube.services.transport.api.ClientTransport; |
12 | 10 | import io.scalecube.services.transport.api.DataCodec; |
13 | 11 | import io.scalecube.services.transport.api.HeadersCodec; |
14 | 12 | import io.scalecube.services.transport.api.ServerTransport; |
15 | 13 | import io.scalecube.services.transport.api.ServiceMessageCodec; |
16 | 14 | import io.scalecube.services.transport.api.ServiceTransport; |
17 | | -import java.net.InetSocketAddress; |
18 | 15 | import java.util.Collection; |
19 | 16 | import java.util.concurrent.ThreadFactory; |
20 | 17 | import java.util.function.Function; |
21 | | -import org.slf4j.Logger; |
22 | | -import org.slf4j.LoggerFactory; |
23 | 18 | import reactor.core.publisher.Flux; |
24 | 19 | import reactor.core.publisher.Mono; |
25 | 20 | import reactor.netty.FutureMono; |
26 | 21 | import reactor.netty.resources.LoopResources; |
27 | | -import reactor.netty.tcp.TcpClient; |
28 | | -import reactor.netty.tcp.TcpServer; |
29 | 22 |
|
30 | 23 | public class RSocketServiceTransport implements ServiceTransport { |
31 | 24 |
|
32 | | - private static final Logger LOGGER = LoggerFactory.getLogger(RSocketServiceTransport.class); |
33 | | - |
34 | 25 | private int numOfWorkers = Runtime.getRuntime().availableProcessors(); |
35 | 26 | private HeadersCodec headersCodec; |
36 | 27 | private Collection<DataCodec> dataCodecs; |
37 | 28 | private Function<LoopResources, RSocketServerTransportFactory> serverTransportFactory = |
38 | | - defaultServerTransportFactory(); |
| 29 | + RSocketServerTransportFactory.tcp(); |
39 | 30 | private Function<LoopResources, RSocketClientTransportFactory> clientTransportFactory = |
40 | | - defaultClientTransportFactory(); |
| 31 | + RSocketClientTransportFactory.tcp(); |
41 | 32 |
|
42 | 33 | // resources |
43 | 34 | private EventLoopGroup eventLoopGroup; |
@@ -182,36 +173,6 @@ private Mono<Void> shutdownEventLoopGroup() { |
182 | 173 | return Mono.defer(() -> FutureMono.from((Future) eventLoopGroup.shutdownGracefully())); |
183 | 174 | } |
184 | 175 |
|
185 | | - private Function<LoopResources, RSocketServerTransportFactory> defaultServerTransportFactory() { |
186 | | - return (LoopResources serverLoopResources) -> |
187 | | - () -> |
188 | | - TcpServerTransport.create( |
189 | | - TcpServer.create() |
190 | | - .runOn(serverLoopResources) |
191 | | - .bindAddress(() -> new InetSocketAddress(0)) |
192 | | - .doOnConnection( |
193 | | - connection -> { |
194 | | - LOGGER.debug( |
195 | | - "[rsocket][server] Accepted connection on {}", connection.channel()); |
196 | | - connection.onDispose( |
197 | | - () -> |
198 | | - LOGGER.debug( |
199 | | - "[rsocket][server] Connection closed on {}", |
200 | | - connection.channel())); |
201 | | - })); |
202 | | - } |
203 | | - |
204 | | - private Function<LoopResources, RSocketClientTransportFactory> defaultClientTransportFactory() { |
205 | | - return (LoopResources loopResources) -> |
206 | | - (RSocketClientTransportFactory) |
207 | | - address -> |
208 | | - TcpClientTransport.create( |
209 | | - TcpClient.newConnection() |
210 | | - .host(address.host()) |
211 | | - .port(address.port()) |
212 | | - .runOn(loopResources)); |
213 | | - } |
214 | | - |
215 | 176 | @Override |
216 | 177 | public String toString() { |
217 | 178 | return "RSocketServiceTransport{" |
|
0 commit comments