diff --git a/build.gradle b/build.gradle index 31872face7..0fa702ed9b 100644 --- a/build.gradle +++ b/build.gradle @@ -75,6 +75,7 @@ configure(allprojects) { project -> } repositories { + maven { url "http://repo.spring.io/snapshot" } // temporarily until Reactor 1.1.0.M4 maven { url "http://repo.spring.io/libs-release" } maven { url "http://repo.spring.io/milestone" } // for AspectJ 1.8.0.M1 maven { url "https://oss.sonatype.org/content/repositories/releases" } // javax.cache @@ -398,8 +399,8 @@ project("spring-messaging") { compile(project(":spring-beans")) compile(project(":spring-core")) compile(project(":spring-context")) - optional("org.projectreactor:reactor-core:1.0.1.RELEASE") - optional("org.projectreactor:reactor-tcp:1.0.1.RELEASE") + optional("org.projectreactor:reactor-core:1.1.0.BUILD-SNAPSHOT") + optional("org.projectreactor:reactor-net:1.1.0.BUILD-SNAPSHOT") optional("org.eclipse.jetty.websocket:websocket-server:${jettyVersion}") { exclude group: "javax.servlet", module: "javax.servlet-api" } @@ -621,8 +622,8 @@ project("spring-websocket") { 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-logging-juli:8.0.3") - testCompile("org.projectreactor:reactor-core:1.0.1.RELEASE") - testCompile("org.projectreactor:reactor-tcp:1.0.1.RELEASE") + testCompile("org.projectreactor:reactor-core:1.1.0.BUILD-SNAPSHOT") + testCompile("org.projectreactor:reactor-net:1.1.0.BUILD-SNAPSHOT") testCompile("log4j:log4j:1.2.17") testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}") } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompCodec.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompCodec.java index 1425860bdc..ec5569508f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompCodec.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompCodec.java @@ -21,7 +21,7 @@ import org.springframework.messaging.Message; import reactor.function.Consumer; import reactor.function.Function; import reactor.io.Buffer; -import reactor.tcp.encoding.Codec; +import reactor.io.encoding.Codec; import java.util.List; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpOperations.java index 6070ad13d6..8db2e10140 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpOperations.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/TcpOperations.java @@ -50,6 +50,6 @@ public interface TcpOperations
{
* @return a ListenableFuture that can be used to determine when and if the
* connection is successfully closed
*/
- ListenableFuture implements TcpOperations {
/**
- * A constructor that creates a {@link reactor.tcp.netty.NettyTcpClient} with
+ * A constructor that creates a {@link reactor.net.netty.tcp.NettyTcpClient} with
* a {@link reactor.event.dispatch.SynchronousDispatcher} as a result of which
* network I/O is handled in Netty threads.
*
* Also see the constructor accepting a pre-configured Reactor
- * {@link reactor.tcp.TcpClient}.
+ * {@link reactor.net.tcp.TcpClient}.
*
* @param host the host to connect to
* @param port the port to connect to
@@ -94,12 +91,10 @@ public class ReactorTcpClient implements TcpOperations {
.codec(codec)
.connect(host, port)
.get();
-
- checkReactorVersion();
}
/**
- * A constructor with a pre-configured {@link reactor.tcp.TcpClient}.
+ * A constructor with a pre-configured {@link reactor.net.tcp.TcpClient}.
*
* NOTE: if the client is configured with a thread-creating
* dispatcher, you are responsible for shutting down the {@link reactor.core.Environment}
@@ -111,31 +106,18 @@ public class ReactorTcpClient implements TcpOperations {
Assert.notNull(tcpClient, "'tcpClient' must not be null");
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+
- }
}
@Override
public ListenableFuture connectionHandler) {
- Promise >> promise = this.tcpClient.open();
+ Promise >> promise = this.tcpClient.open();
composeConnectionHandling(promise, connectionHandler);
- return new AbstractPromiseToListenableFutureAdapter >, Void>(promise) {
+ return new AbstractPromiseToListenableFutureAdapter >, Void>(promise) {
@Override
- protected Void adapt(TcpConnection > result) {
+ protected Void adapt(NetChannel > result) {
return null;
}
};
@@ -147,82 +129,71 @@ public class ReactorTcpClient implements TcpOperations {
Assert.notNull(reconnectStrategy, "ReconnectStrategy must not be null");
- Stream >> stream =
- this.tcpClient.open(new Reconnect() {
- @Override
- public Tuple2 >> stream = this.tcpClient.open(reconnect);
composeConnectionHandling(stream, connectionHandler);
- return new PassThroughPromiseToListenableFutureAdapter >, Void>() {
+ @Override
+ public Void apply(NetChannel > ch) {
+ return null;
+ }
+ });
+ return new PassThroughPromiseToListenableFutureAdapter >> composable,
+ private void composeConnectionHandling(Composable >> composable,
final TcpConnectionHandler connectionHandler) {
- composable.when(Throwable.class, new Consumer >>() {
- @Override
- public void accept(TcpConnection > connection) {
- connection.on().close(new Runnable() {
+ composable
+ .when(Throwable.class, new Consumer >>() {
+ @Override
+ public void accept(NetChannel > connection) {
+ connection
+ .when(Throwable.class, new Consumer message) {
+ connectionHandler.handleMessage(message);
+ }
+ })
+ .on()
+ .close(new Runnable() {
+ @Override
+ public void run() {
+ connectionHandler.afterConnectionClosed();
+ }
+ });
+ connectionHandler.afterConnected(new ReactorTcpConnection (connection));
}
});
- connection.consume(new Consumer message) {
- connectionHandler.handleMessage(message);
- }
- });
- connection.when(Throwable.class, new Consumer (connection));
- }
- });
- }
-
- private Promise >> stream) {
-
- final Deferred >>() {
- @Override
- public void accept(TcpConnection > conn) {
- deferred.accept((Void) null);
- }
- }));
-
- stream.when(Throwable.class, SingleUseConsumer.once(new Consumer implements TcpOperations {
}
}
-
/**
* A ConfigurationReader that enforces the use of a SynchronousDispatcher.
*
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorTcpConnection.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorTcpConnection.java
index e4c47c9795..78033c865f 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorTcpConnection.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorTcpConnection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,35 +21,46 @@ import org.springframework.messaging.tcp.TcpConnection;
import org.springframework.util.concurrent.ListenableFuture;
import reactor.core.composable.Promise;
+import reactor.net.NetChannel;
+
+/**
+ * An implementation of {@link org.springframework.messaging.tcp.TcpConnection}
+ * based on the TCP client support of the Reactor project.
+ *
+ * @param the payload type of Spring Message's read from
+ * and written to the TCP stream
+ *
+ * @author Rossen Stoyanchev
+ */
public class ReactorTcpConnection implements TcpConnection {
- private final reactor.tcp.TcpConnection > reactorTcpConnection;
+ private final NetChannel > channel;
- public ReactorTcpConnection(reactor.tcp.TcpConnection > connection) {
- this.reactorTcpConnection = connection;
+ public ReactorTcpConnection(NetChannel > connection) {
+ this.channel = connection;
}
@Override
public ListenableFuture message) {
- Promise