Skip to content

Commit ed8c61a

Browse files
committed
Upgrade to RSocket 1.0 RC7 snapshots
1 parent 376434e commit ed8c61a

File tree

12 files changed

+336
-131
lines changed

12 files changed

+336
-131
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ configure(allprojects) { project ->
2929
mavenBom "com.fasterxml.jackson:jackson-bom:2.10.3"
3030
mavenBom "io.netty:netty-bom:4.1.48.Final"
3131
mavenBom "io.projectreactor:reactor-bom:Dysprosium-BUILD-SNAPSHOT"
32-
mavenBom "io.rsocket:rsocket-bom:1.0.0-RC6"
32+
mavenBom "io.rsocket:rsocket-bom:1.0.0-RC7-SNAPSHOT"
3333
mavenBom "org.eclipse.jetty:jetty-bom:9.4.28.v20200408"
3434
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.3.72"
3535
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.3.5"
@@ -280,6 +280,7 @@ configure(allprojects) { project ->
280280
mavenCentral()
281281
maven { url "https://repo.spring.io/libs-spring-framework-build" }
282282
maven { url "https://repo.spring.io/snapshot" }
283+
maven { url "https://oss.jfrog.org/artifactory/oss-snapshot-local" } // RSocket
283284
}
284285
}
285286
configurations.all {

spring-messaging/src/main/java/org/springframework/messaging/rsocket/ClientRSocketFactoryConfigurer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -15,22 +15,24 @@
1515
*/
1616
package org.springframework.messaging.rsocket;
1717

18-
import io.rsocket.RSocketFactory;
19-
2018
/**
2119
* Strategy to apply configuration to a client side {@code RSocketFactory}.
2220
* that's being prepared by {@link RSocketRequester.Builder} to connect
2321
* to a server.
2422
*
2523
* @author Rossen Stoyanchev
2624
* @since 5.2
25+
* @deprecated as of 5.2.6 following the deprecation of
26+
* {@link io.rsocket.RSocketFactory.ClientRSocketFactory RSocketFactory.ClientRSocketFactory}
27+
* in RSocket 1.0 RC7. Please, use {@link RSocketConnectorConfigurer}.
2728
*/
2829
@FunctionalInterface
30+
@Deprecated
2931
public interface ClientRSocketFactoryConfigurer {
3032

3133
/**
3234
* Apply configuration to the given {@code ClientRSocketFactory}.
3335
*/
34-
void configure(RSocketFactory.ClientRSocketFactory rsocketFactory);
36+
void configure(io.rsocket.RSocketFactory.ClientRSocketFactory rsocketFactory);
3537

3638
}

spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java

Lines changed: 103 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -25,12 +25,12 @@
2525
import java.util.function.Consumer;
2626

2727
import io.rsocket.Payload;
28-
import io.rsocket.RSocketFactory;
2928
import io.rsocket.frame.decoder.PayloadDecoder;
3029
import io.rsocket.metadata.WellKnownMimeType;
3130
import io.rsocket.transport.ClientTransport;
3231
import io.rsocket.transport.netty.client.TcpClientTransport;
3332
import io.rsocket.transport.netty.client.WebsocketClientTransport;
33+
import io.rsocket.util.DefaultPayload;
3434
import reactor.core.publisher.Mono;
3535

3636
import org.springframework.core.ReactiveAdapter;
@@ -43,6 +43,7 @@
4343
import org.springframework.core.io.buffer.NettyDataBufferFactory;
4444
import org.springframework.lang.Nullable;
4545
import org.springframework.util.Assert;
46+
import org.springframework.util.ClassUtils;
4647
import org.springframework.util.CollectionUtils;
4748
import org.springframework.util.MimeType;
4849
import org.springframework.util.MimeTypeUtils;
@@ -56,10 +57,17 @@
5657
*/
5758
final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
5859

60+
private final static boolean rsocketConnectorPresent =
61+
ClassUtils.isPresent("io.rsocket.core.RSocketConnector",
62+
DefaultRSocketRequesterBuilder.class.getClassLoader());
63+
64+
5965
private static final Map<String, Object> HINTS = Collections.emptyMap();
6066

6167
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
6268

69+
private static final Payload EMPTY_SETUP_PAYLOAD = DefaultPayload.create(EMPTY_BYTE_ARRAY);
70+
6371

6472
@Nullable
6573
private MimeType dataMimeType;
@@ -84,7 +92,10 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
8492

8593
private List<Consumer<RSocketStrategies.Builder>> strategiesConfigurers = new ArrayList<>();
8694

87-
private List<ClientRSocketFactoryConfigurer> rsocketConfigurers = new ArrayList<>();
95+
private List<RSocketConnectorConfigurer> rsocketConnectorConfigurers = new ArrayList<>();
96+
97+
@SuppressWarnings("deprecation")
98+
private List<ClientRSocketFactoryConfigurer> rsocketFactoryConfigurers = new ArrayList<>();
8899

89100

90101
@Override
@@ -133,8 +144,15 @@ public RSocketRequester.Builder rsocketStrategies(Consumer<RSocketStrategies.Bui
133144
}
134145

135146
@Override
147+
public RSocketRequester.Builder rsocketConnector(RSocketConnectorConfigurer configurer) {
148+
this.rsocketConnectorConfigurers.add(configurer);
149+
return this;
150+
}
151+
152+
@Override
153+
@Deprecated
136154
public RSocketRequester.Builder rsocketFactory(ClientRSocketFactoryConfigurer configurer) {
137-
this.rsocketConfigurers.add(configurer);
155+
this.rsocketFactoryConfigurers.add(configurer);
138156
return this;
139157
}
140158

@@ -164,28 +182,25 @@ private Mono<RSocketRequester> doConnect(ClientTransport transport) {
164182
Assert.isTrue(!rsocketStrategies.encoders().isEmpty(), "No encoders");
165183
Assert.isTrue(!rsocketStrategies.decoders().isEmpty(), "No decoders");
166184

167-
RSocketFactory.ClientRSocketFactory factory = RSocketFactory.connect();
168-
this.rsocketConfigurers.forEach(configurer -> configurer.configure(factory));
169-
170-
if (rsocketStrategies.dataBufferFactory() instanceof NettyDataBufferFactory) {
171-
factory.frameDecoder(PayloadDecoder.ZERO_COPY);
172-
}
173-
174185
MimeType metaMimeType = this.metadataMimeType != null ? this.metadataMimeType :
175186
MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
176187

177188
MimeType dataMimeType = getDataMimeType(rsocketStrategies);
178-
factory.dataMimeType(dataMimeType.toString());
179-
factory.metadataMimeType(metaMimeType.toString());
180-
181-
return getSetupPayload(dataMimeType, metaMimeType, rsocketStrategies)
182-
.doOnNext(factory::setupPayload)
183-
.then(Mono.defer(() ->
184-
factory.transport(transport)
185-
.start()
186-
.map(rsocket -> new DefaultRSocketRequester(
187-
rsocket, dataMimeType, metaMimeType, rsocketStrategies))
188-
));
189+
190+
if (rsocketConnectorPresent) {
191+
return getSetupPayload(dataMimeType, metaMimeType, rsocketStrategies)
192+
.flatMap(payload ->
193+
new RSocketConnectorHelper().connect(
194+
this.rsocketConnectorConfigurers, this.rsocketFactoryConfigurers,
195+
metaMimeType, dataMimeType, payload, rsocketStrategies, transport));
196+
}
197+
else {
198+
return getSetupPayload(dataMimeType, metaMimeType, rsocketStrategies)
199+
.flatMap(payload ->
200+
new RSocketFactoryHelper().connect(
201+
this.rsocketFactoryConfigurers, metaMimeType, dataMimeType, payload,
202+
rsocketStrategies, transport));
203+
}
189204
}
190205

191206
private RSocketStrategies getRSocketStrategies() {
@@ -234,7 +249,7 @@ private Mono<Payload> getSetupPayload(
234249
Object data = this.setupData;
235250
boolean hasMetadata = (this.setupRoute != null || !CollectionUtils.isEmpty(this.setupMetadata));
236251
if (!hasMetadata && data == null) {
237-
return Mono.empty();
252+
return Mono.just(EMPTY_SETUP_PAYLOAD);
238253
}
239254

240255
Mono<DataBuffer> dataMono = Mono.empty();
@@ -269,4 +284,69 @@ private Mono<Payload> getSetupPayload(
269284
.doOnDiscard(Payload.class, Payload::release);
270285
}
271286

287+
288+
private static class RSocketConnectorHelper {
289+
290+
@SuppressWarnings("deprecation")
291+
Mono<RSocketRequester> connect(
292+
List<RSocketConnectorConfigurer> connectorConfigurers,
293+
List<ClientRSocketFactoryConfigurer> factoryConfigurers,
294+
MimeType metaMimeType, MimeType dataMimeType, Payload setupPayload,
295+
RSocketStrategies rsocketStrategies, ClientTransport transport) {
296+
297+
io.rsocket.core.RSocketConnector connector = io.rsocket.core.RSocketConnector.create();
298+
connectorConfigurers.forEach(c -> c.configure(connector));
299+
300+
if (!factoryConfigurers.isEmpty()) {
301+
io.rsocket.RSocketFactory.ClientRSocketFactory factory =
302+
new io.rsocket.RSocketFactory.ClientRSocketFactory(connector);
303+
factoryConfigurers.forEach(c -> c.configure(factory));
304+
}
305+
306+
if (rsocketStrategies.dataBufferFactory() instanceof NettyDataBufferFactory) {
307+
connector.payloadDecoder(PayloadDecoder.ZERO_COPY);
308+
}
309+
310+
if (setupPayload != EMPTY_SETUP_PAYLOAD) {
311+
connector.setupPayload(setupPayload);
312+
}
313+
314+
return connector
315+
.metadataMimeType(metaMimeType.toString())
316+
.dataMimeType(dataMimeType.toString())
317+
.connect(transport)
318+
.map(rsocket -> new DefaultRSocketRequester(
319+
rsocket, dataMimeType, metaMimeType, rsocketStrategies));
320+
}
321+
}
322+
323+
324+
@SuppressWarnings("deprecation")
325+
private static class RSocketFactoryHelper {
326+
327+
Mono<RSocketRequester> connect(
328+
List<ClientRSocketFactoryConfigurer> configurers,
329+
MimeType metaMimeType, MimeType dataMimeType, Payload setupPayload,
330+
RSocketStrategies rsocketStrategies, ClientTransport transport) {
331+
332+
io.rsocket.RSocketFactory.ClientRSocketFactory factory = io.rsocket.RSocketFactory.connect();
333+
configurers.forEach(c -> c.configure(factory));
334+
335+
if (rsocketStrategies.dataBufferFactory() instanceof NettyDataBufferFactory) {
336+
factory.frameDecoder(PayloadDecoder.ZERO_COPY);
337+
}
338+
339+
if (setupPayload != EMPTY_SETUP_PAYLOAD) {
340+
factory.setupPayload(setupPayload);
341+
}
342+
343+
return factory.metadataMimeType(metaMimeType.toString())
344+
.dataMimeType(dataMimeType.toString())
345+
.transport(transport)
346+
.start()
347+
.map(rsocket -> new DefaultRSocketRequester(
348+
rsocket, dataMimeType, metaMimeType, rsocketStrategies));
349+
}
350+
}
351+
272352
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2002-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.messaging.rsocket;
17+
18+
import io.rsocket.core.RSocketConnector;
19+
20+
/**
21+
* Strategy to apply configuration to an {@code RSocketConnector}. For use with
22+
* {@link RSocketRequester.Builder#rsocketConnector RSocketRequester.Builder}.
23+
*
24+
* @author Rossen Stoyanchev
25+
* @since 5.2.6
26+
*/
27+
@FunctionalInterface
28+
public interface RSocketConnectorConfigurer {
29+
30+
/**
31+
* Apply configuration to the given {@code RSocketConnector}.
32+
*/
33+
void configure(RSocketConnector connector);
34+
35+
}

spring-messaging/src/main/java/org/springframework/messaging/rsocket/RSocketRequester.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -185,6 +185,26 @@ interface Builder {
185185
*/
186186
RSocketRequester.Builder rsocketStrategies(Consumer<RSocketStrategies.Builder> configurer);
187187

188+
/**
189+
* Callback to configure the {@code RSocketConnector} directly.
190+
* <ul>
191+
* <li>The data and metadata mime types cannot be set directly
192+
* on the {@code RSocketConnector} and will be overridden. Use the
193+
* shortcuts {@link #dataMimeType(MimeType)} and
194+
* {@link #metadataMimeType(MimeType)} on this builder instead.
195+
* <li>The frame decoder also cannot be set directly and instead is set
196+
* to match the configured {@code DataBufferFactory}.
197+
* <li>For the
198+
* {@link io.rsocket.core.RSocketConnector#setupPayload(Payload)
199+
* setupPayload}, consider using methods on this builder to specify the
200+
* route, other metadata, and data as Object values to be encoded.
201+
* <li>To configure client side responding, see
202+
* {@link RSocketMessageHandler#responder(RSocketStrategies, Object...)}.
203+
* </ul>
204+
* @since 5.2.6
205+
*/
206+
RSocketRequester.Builder rsocketConnector(RSocketConnectorConfigurer configurer);
207+
188208
/**
189209
* Callback to configure the {@code ClientRSocketFactory} directly.
190210
* <ul>
@@ -201,7 +221,11 @@ interface Builder {
201221
* <li>To configure client side responding, see
202222
* {@link RSocketMessageHandler#clientResponder(RSocketStrategies, Object...)}.
203223
* </ul>
224+
* @deprecated as of 5.2.6 following the deprecation of
225+
* {@link io.rsocket.RSocketFactory.ClientRSocketFactory RSocketFactory.ClientRSocketFactory}
226+
* in RSocket 1.0 RC7. Please, use {@link #rsocketConnector(RSocketConnectorConfigurer)}.
204227
*/
228+
@Deprecated
205229
RSocketRequester.Builder rsocketFactory(ClientRSocketFactoryConfigurer configurer);
206230

207231
/**

spring-messaging/src/main/java/org/springframework/messaging/rsocket/RSocketStrategies.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -20,8 +20,6 @@
2020
import java.util.function.Consumer;
2121

2222
import io.rsocket.Payload;
23-
import io.rsocket.RSocketFactory.ClientRSocketFactory;
24-
import io.rsocket.RSocketFactory.ServerRSocketFactory;
2523

2624
import org.springframework.core.ReactiveAdapterRegistry;
2725
import org.springframework.core.ResolvableType;
@@ -200,9 +198,10 @@ interface Builder {
200198
* <a href="https://github.com/rsocket/rsocket-java#zero-copy">configured</a>
201199
* for zero copy. For client setup, {@link RSocketRequester.Builder}
202200
* adapts automatically to the {@code DataBufferFactory} configured
203-
* here, and sets the frame decoder in {@link ClientRSocketFactory
204-
* ClientRSocketFactory} accordingly. For server setup, the
205-
* {@link ServerRSocketFactory ServerRSocketFactory} must be configured
201+
* here, and sets the frame decoder in
202+
* {@link io.rsocket.core.RSocketConnector RSocketConnector}
203+
* accordingly. For server setup, the
204+
* {@link io.rsocket.core.RSocketServer RSocketServer} must be configured
206205
* accordingly for zero copy too.
207206
* <p>If using {@link DefaultDataBufferFactory} instead, there is no
208207
* need for related config changes in RSocket.

0 commit comments

Comments
 (0)