Skip to content

Commit 60b19c7

Browse files
committed
Update TCP/Reactor
Issue: SPR-12599
1 parent 74c0250 commit 60b19c7

File tree

7 files changed

+185
-181
lines changed

7 files changed

+185
-181
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ configure(allprojects) { project ->
117117
}
118118

119119
repositories {
120-
mavenLocal()
121120
maven { url "https://repo.spring.io/libs-release" }
122121
maven { url "https://repo.spring.io/milestone" }
122+
maven { url "https://repo.spring.io/snapshot" } // for reactor 2.0.1 snapshot
123123
}
124124

125125
dependencies {
@@ -487,6 +487,7 @@ project("spring-messaging") {
487487
compile(project(":spring-beans"))
488488
compile(project(":spring-core"))
489489
compile(project(":spring-context"))
490+
optional("io.projectreactor:reactor-core:${reactorVersion}")
490491
optional("io.projectreactor:reactor-net:${reactorVersion}") {
491492
exclude group: "io.netty", module: "netty-all"
492493
}
@@ -497,7 +498,6 @@ project("spring-messaging") {
497498
optional("org.eclipse.jetty.websocket:websocket-client:${jettyVersion}")
498499
optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}")
499500
testCompile(project(":spring-test"))
500-
testCompile('org.slf4j:slf4j-log4j12:1.7.10')
501501
testCompile("javax.inject:javax.inject-tck:1")
502502
testCompile("javax.servlet:javax.servlet-api:3.1.0")
503503
testCompile("javax.validation:validation-api:1.0.0.GA")

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/Reactor2StompCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/Reactor2TcpStompClient.java

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818
import org.springframework.messaging.Message;
1919
import org.springframework.messaging.tcp.TcpOperations;
2020
import org.springframework.messaging.tcp.reactor.Reactor2TcpClient;
21+
import org.springframework.messaging.tcp.reactor.Reactor2TcpClient.TcpClientSpecFactory;
2122
import org.springframework.util.concurrent.ListenableFuture;
2223
import reactor.Environment;
2324
import reactor.core.config.ConfigurationReader;
2425
import reactor.core.config.DispatcherConfiguration;
2526
import reactor.core.config.DispatcherType;
2627
import reactor.core.config.ReactorConfiguration;
27-
import reactor.fn.Function;
28-
import reactor.io.net.Spec;
28+
import reactor.io.net.Spec.TcpClientSpec;
2929

3030
import java.util.Arrays;
31+
import java.util.List;
3132
import java.util.Properties;
3233

3334
/**
@@ -52,40 +53,18 @@ public Reactor2TcpStompClient() {
5253

5354
/**
5455
* Create an instance with the given host and port.
55-
*
5656
* @param host the host
5757
* @param port the port
5858
*/
5959
public Reactor2TcpStompClient(final String host, final int port) {
60-
this.tcpClient = new Reactor2TcpClient<byte[]>(createNettyTcpClientFactory(host, port));
61-
}
62-
63-
private Function<Spec.TcpClientSpec<Message<byte[]>, Message<byte[]>>,
64-
Spec.TcpClientSpec<Message<byte[]>, Message<byte[]>>> createNettyTcpClientFactory(
65-
final String host, final int port
66-
) {
67-
68-
final Environment environment = new Environment(new StompClientDispatcherConfigReader()).assignErrorJournal();
69-
70-
return new Function<Spec.TcpClientSpec<Message<byte[]>, Message<byte[]>>,
71-
Spec.TcpClientSpec<Message<byte[]>, Message<byte[]>>>() {
72-
73-
@Override
74-
public Spec.TcpClientSpec<Message<byte[]>, Message<byte[]>> apply(Spec.TcpClientSpec<Message<byte[]>,
75-
Message<byte[]>> spec) {
76-
77-
return spec
78-
.codec(new Reactor2StompCodec(new StompEncoder(), new StompDecoder()))
79-
.env(environment)
80-
.dispatcher(environment.getCachedDispatchers("StompClient").get())
81-
.connect(host, port);
82-
}
83-
};
60+
ConfigurationReader reader = new StompClientDispatcherConfigReader();
61+
Environment environment = new Environment(reader).assignErrorJournal();
62+
StompTcpClientSpecFactory factory = new StompTcpClientSpecFactory(environment, host, port);
63+
this.tcpClient = new Reactor2TcpClient<byte[]>(factory);
8464
}
8565

8666
/**
8767
* Create an instance with a pre-configured TCP client.
88-
*
8968
* @param tcpClient the client to use
9069
*/
9170
public Reactor2TcpStompClient(TcpOperations<byte[]> tcpClient) {
@@ -136,8 +115,35 @@ public ReactorConfiguration read() {
136115
String dispatcherName = "StompClient";
137116
DispatcherType dispatcherType = DispatcherType.DISPATCHER_GROUP;
138117
DispatcherConfiguration config = new DispatcherConfiguration(dispatcherName, dispatcherType, 128, 0);
139-
return new ReactorConfiguration(Arrays.<DispatcherConfiguration>asList(config), dispatcherName, new Properties
140-
());
118+
List<DispatcherConfiguration> configList = Arrays.<DispatcherConfiguration>asList(config);
119+
return new ReactorConfiguration(configList, dispatcherName, new Properties());
120+
}
121+
}
122+
123+
private static class StompTcpClientSpecFactory
124+
implements TcpClientSpecFactory<Message<byte[]>, Message<byte[]>> {
125+
126+
private final Environment environment;
127+
128+
private final String host;
129+
130+
private final int port;
131+
132+
public StompTcpClientSpecFactory(Environment environment, String host, int port) {
133+
this.environment = environment;
134+
this.host = host;
135+
this.port = port;
136+
}
137+
138+
@Override
139+
public TcpClientSpec<Message<byte[]>, Message<byte[]>> apply(
140+
TcpClientSpec<Message<byte[]>, Message<byte[]>> tcpClientSpec) {
141+
142+
return tcpClientSpec
143+
.codec(new Reactor2StompCodec(new StompEncoder(), new StompDecoder()))
144+
.env(this.environment)
145+
.dispatcher(this.environment.getCachedDispatchers("StompClient").get())
146+
.connect(this.host, this.port);
141147
}
142148
}
143149

spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/AbstractPromiseToListenableFutureAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ protected AbstractPromiseToListenableFutureAdapter(Promise<S> promise) {
5454
public void accept(S result) {
5555
try {
5656
registry.success(adapt(result));
57-
} catch (Throwable t) {
57+
}
58+
catch (Throwable t) {
5859
registry.failure(t);
5960
}
6061
}

spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/PassThroughPromiseToListenableFutureAdapter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,11 @@
1616

1717
package org.springframework.messaging.tcp.reactor;
1818

19-
2019
import reactor.rx.Promise;
2120

2221
/**
23-
* A Promise-to-ListenableFutureAdapter where the source and the target from the Promise and
24-
* the ListenableFuture respectively are of the same type.
22+
* A Promise-to-ListenableFutureAdapter where the source and the target from
23+
* the Promise and the ListenableFuture respectively are of the same type.
2524
*
2625
* @author Rossen Stoyanchev
2726
* @since 4.0

0 commit comments

Comments
 (0)