Upgrade to reactor 1.0.1.RELEASE
This commit is contained in:
parent
92eb99a5ab
commit
918e21fd8f
|
@ -390,8 +390,8 @@ project("spring-messaging") {
|
||||||
compile(project(":spring-beans"))
|
compile(project(":spring-beans"))
|
||||||
compile(project(":spring-core"))
|
compile(project(":spring-core"))
|
||||||
compile(project(":spring-context"))
|
compile(project(":spring-context"))
|
||||||
optional("org.projectreactor:reactor-core:1.0.0.RELEASE")
|
optional("org.projectreactor:reactor-core:1.0.1.RELEASE")
|
||||||
optional("org.projectreactor:reactor-tcp:1.0.0.RELEASE")
|
optional("org.projectreactor:reactor-tcp:1.0.1.RELEASE")
|
||||||
optional("org.eclipse.jetty.websocket:websocket-server:${jettyVersion}") {
|
optional("org.eclipse.jetty.websocket:websocket-server:${jettyVersion}") {
|
||||||
exclude group: "javax.servlet", module: "javax.servlet-api"
|
exclude group: "javax.servlet", module: "javax.servlet-api"
|
||||||
}
|
}
|
||||||
|
@ -607,8 +607,8 @@ project("spring-websocket") {
|
||||||
testCompile("org.apache.tomcat.embed:tomcat-embed-core:8.0.3")
|
testCompile("org.apache.tomcat.embed:tomcat-embed-core:8.0.3")
|
||||||
testCompile("org.apache.tomcat.embed:tomcat-embed-websocket:8.0.3")
|
testCompile("org.apache.tomcat.embed:tomcat-embed-websocket:8.0.3")
|
||||||
testCompile("org.apache.tomcat.embed:tomcat-embed-logging-juli:8.0.3")
|
testCompile("org.apache.tomcat.embed:tomcat-embed-logging-juli:8.0.3")
|
||||||
testCompile("org.projectreactor:reactor-core:1.0.0.RELEASE")
|
testCompile("org.projectreactor:reactor-core:1.0.1.RELEASE")
|
||||||
testCompile("org.projectreactor:reactor-tcp:1.0.0.RELEASE")
|
testCompile("org.projectreactor:reactor-tcp:1.0.1.RELEASE")
|
||||||
testCompile("log4j:log4j:1.2.17")
|
testCompile("log4j:log4j:1.2.17")
|
||||||
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
|
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.messaging.tcp.reactor;
|
package org.springframework.messaging.tcp.reactor;
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -48,7 +49,7 @@ import reactor.tuple.Tuple2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of {@link org.springframework.messaging.tcp.TcpOperations}
|
* An implementation of {@link org.springframework.messaging.tcp.TcpOperations}
|
||||||
* based on the Reactor project.
|
* based on the TCP client support of the Reactor project.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
|
@ -60,7 +61,9 @@ public class ReactorTcpClient<P> implements TcpOperations<P> {
|
||||||
|
|
||||||
private final static Log logger = LogFactory.getLog(ReactorTcpClient.class);
|
private final static Log logger = LogFactory.getLog(ReactorTcpClient.class);
|
||||||
|
|
||||||
private TcpClient<Message<P>, Message<P>> tcpClient;
|
private final TcpClient<Message<P>, Message<P>> tcpClient;
|
||||||
|
|
||||||
|
private final Environment environment;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,12 +79,18 @@ public class ReactorTcpClient<P> implements TcpOperations<P> {
|
||||||
* @param codec the codec to use for encoding and decoding the TCP stream
|
* @param codec the codec to use for encoding and decoding the TCP stream
|
||||||
*/
|
*/
|
||||||
public ReactorTcpClient(String host, int port, Codec<Buffer, Message<P>, Message<P>> codec) {
|
public ReactorTcpClient(String host, int port, Codec<Buffer, Message<P>, Message<P>> codec) {
|
||||||
|
|
||||||
|
// Revisit in 1.1: is Environment still required w/ sync dispatcher?
|
||||||
|
this.environment = new Environment();
|
||||||
|
|
||||||
this.tcpClient = new TcpClientSpec<Message<P>, Message<P>>(REACTOR_TCP_CLIENT_TYPE)
|
this.tcpClient = new TcpClientSpec<Message<P>, Message<P>>(REACTOR_TCP_CLIENT_TYPE)
|
||||||
.env(new Environment())
|
.env(this.environment)
|
||||||
.codec(codec)
|
.codec(codec)
|
||||||
.connect(host, port)
|
.connect(host, port)
|
||||||
.synchronousDispatcher()
|
.synchronousDispatcher()
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
|
checkReactorVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,6 +105,20 @@ public class ReactorTcpClient<P> implements TcpOperations<P> {
|
||||||
public ReactorTcpClient(TcpClient<Message<P>, Message<P>> tcpClient) {
|
public ReactorTcpClient(TcpClient<Message<P>, Message<P>> tcpClient) {
|
||||||
Assert.notNull(tcpClient, "'tcpClient' must not be null");
|
Assert.notNull(tcpClient, "'tcpClient' must not be null");
|
||||||
this.tcpClient = tcpClient;
|
this.tcpClient = tcpClient;
|
||||||
|
this.environment = null;
|
||||||
|
checkReactorVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkReactorVersion() {
|
||||||
|
Class<?> type = null;
|
||||||
|
try {
|
||||||
|
type = ReactorTcpClient.class.getClassLoader().loadClass("reactor.event.dispatch.BaseDispatcher");
|
||||||
|
Assert.isTrue(Modifier.isPublic(type.getModifiers()),
|
||||||
|
"Detected older version of reactor-tcp. Switch to 1.0.1.RELEASE or higher.");
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e) {
|
||||||
|
// Ignore, must be 1.1+
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -190,13 +213,19 @@ public class ReactorTcpClient<P> implements TcpOperations<P> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Void> shutdown() {
|
public ListenableFuture<Void> shutdown() {
|
||||||
Promise<Void> promise = this.tcpClient.close();
|
try {
|
||||||
return new AbstractPromiseToListenableFutureAdapter<Void, Void>(promise) {
|
Promise<Void> promise = this.tcpClient.close();
|
||||||
@Override
|
return new AbstractPromiseToListenableFutureAdapter<Void, Void>(promise) {
|
||||||
protected Void adapt(Void result) {
|
@Override
|
||||||
return result;
|
protected Void adapt(Void result) {
|
||||||
}
|
return result;
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
this.environment.shutdown();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue