From 71362299aee1068d62f730b6f391602849f0774b Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 15 Apr 2019 21:41:19 +0200 Subject: [PATCH] Polish RSocket server bootstrap See gh-16021 --- .../rsocket/RSocketServerAutoConfiguration.java | 13 +++++++------ .../RSocketServerAutoConfigurationTests.java | 10 +++++----- .../RSocketServerBootstrap.java} | 8 +++----- 3 files changed, 15 insertions(+), 16 deletions(-) rename spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/{netty/NettyRSocketBootstrap.java => server/RSocketServerBootstrap.java} (86%) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java index d4c59eb668..2ef84770fa 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java @@ -18,9 +18,10 @@ package org.springframework.boot.autoconfigure.rsocket; import java.util.stream.Collectors; -import io.netty.buffer.PooledByteBufAllocator; import io.rsocket.RSocketFactory; import io.rsocket.SocketAcceptor; +import io.rsocket.transport.netty.server.TcpServerTransport; +import reactor.netty.http.server.HttpServer; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -33,7 +34,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.PropertyMapper; -import org.springframework.boot.rsocket.netty.NettyRSocketBootstrap; +import org.springframework.boot.rsocket.server.RSocketServerBootstrap; import org.springframework.boot.rsocket.netty.NettyRSocketServerFactory; import org.springframework.boot.rsocket.server.RSocketServerFactory; import org.springframework.boot.rsocket.server.ServerRSocketFactoryCustomizer; @@ -57,8 +58,8 @@ import org.springframework.messaging.rsocket.RSocketStrategies; * @since 2.2.0 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnClass({ RSocketFactory.class, RSocketStrategies.class, - PooledByteBufAllocator.class }) +@ConditionalOnClass({ RSocketFactory.class, RSocketStrategies.class, HttpServer.class, + TcpServerTransport.class }) @ConditionalOnBean(MessageHandlerAcceptor.class) @AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class) @EnableConfigurationProperties(RSocketProperties.class) @@ -105,10 +106,10 @@ public class RSocketServerAutoConfiguration { } @Bean - public NettyRSocketBootstrap nettyRSocketBootstrap( + public RSocketServerBootstrap nettyRSocketBootstrap( RSocketServerFactory rSocketServerFactory, SocketAcceptor socketAcceptor) { - return new NettyRSocketBootstrap(rSocketServerFactory, socketAcceptor); + return new RSocketServerBootstrap(rSocketServerFactory, socketAcceptor); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java index d44fd549a9..ec4ff60dcd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java @@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.rsocket; import org.junit.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.rsocket.netty.NettyRSocketBootstrap; +import org.springframework.boot.rsocket.server.RSocketServerBootstrap; import org.springframework.boot.rsocket.server.RSocketServerFactory; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; @@ -46,7 +46,7 @@ public class RSocketServerAutoConfigurationTests { contextRunner.run((context) -> assertThat(context) .doesNotHaveBean(WebServerFactoryCustomizer.class) .doesNotHaveBean(RSocketServerFactory.class) - .doesNotHaveBean(NettyRSocketBootstrap.class)); + .doesNotHaveBean(RSocketServerBootstrap.class)); } @Test @@ -55,7 +55,7 @@ public class RSocketServerAutoConfigurationTests { contextRunner.run((context) -> assertThat(context) .doesNotHaveBean(WebServerFactoryCustomizer.class) .doesNotHaveBean(RSocketServerFactory.class) - .doesNotHaveBean(NettyRSocketBootstrap.class)); + .doesNotHaveBean(RSocketServerBootstrap.class)); } @Test @@ -67,7 +67,7 @@ public class RSocketServerAutoConfigurationTests { .run((context) -> assertThat(context) .doesNotHaveBean(WebServerFactoryCustomizer.class) .doesNotHaveBean(RSocketServerFactory.class) - .doesNotHaveBean(NettyRSocketBootstrap.class)); + .doesNotHaveBean(RSocketServerBootstrap.class)); } @Test @@ -87,7 +87,7 @@ public class RSocketServerAutoConfigurationTests { contextRunner.withPropertyValues("spring.rsocket.server.port=0") .run((context) -> assertThat(context) .hasSingleBean(RSocketServerFactory.class) - .hasSingleBean(NettyRSocketBootstrap.class)); + .hasSingleBean(RSocketServerBootstrap.class)); } private ApplicationContextRunner createContextRunner() { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/netty/NettyRSocketBootstrap.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/server/RSocketServerBootstrap.java similarity index 86% rename from spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/netty/NettyRSocketBootstrap.java rename to spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/server/RSocketServerBootstrap.java index 85e76011de..a9cb747a80 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/netty/NettyRSocketBootstrap.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/server/RSocketServerBootstrap.java @@ -14,13 +14,11 @@ * limitations under the License. */ -package org.springframework.boot.rsocket.netty; +package org.springframework.boot.rsocket.server; import io.rsocket.SocketAcceptor; import org.springframework.boot.rsocket.context.RSocketServerInitializedEvent; -import org.springframework.boot.rsocket.server.RSocketServer; -import org.springframework.boot.rsocket.server.RSocketServerFactory; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.SmartLifecycle; @@ -31,14 +29,14 @@ import org.springframework.context.SmartLifecycle; * @author Brian Clozel * @since 2.2.0 */ -public class NettyRSocketBootstrap +public class RSocketServerBootstrap implements ApplicationEventPublisherAware, SmartLifecycle { private final RSocketServer rSocketServer; private ApplicationEventPublisher applicationEventPublisher; - public NettyRSocketBootstrap(RSocketServerFactory serverFactoryProvider, + public RSocketServerBootstrap(RSocketServerFactory serverFactoryProvider, SocketAcceptor socketAcceptor) { this.rSocketServer = serverFactoryProvider.create(socketAcceptor); }