Skip to content

Commit c4bd5ab

Browse files
committed
Nullability refinements and related polishing
1 parent 55418b2 commit c4bd5ab

File tree

6 files changed

+22
-36
lines changed

6 files changed

+22
-36
lines changed

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/reactive/MessageMappingMessageHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ protected Mono<Void> handleMatch(CompositeMessageCondition mapping, HandlerMetho
323323
if (!CollectionUtils.isEmpty(patterns)) {
324324
String pattern = patterns.iterator().next();
325325
String destination = getDestination(message);
326+
Assert.state(destination != null, "Missing destination header");
326327
Map<String, String> vars = getPathMatcher().extractUriTemplateVariables(pattern, destination);
327328
if (!CollectionUtils.isEmpty(vars)) {
328329
MessageHeaderAccessor mha = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
@@ -332,4 +333,5 @@ protected Mono<Void> handleMatch(CompositeMessageCondition mapping, HandlerMetho
332333
}
333334
return super.handleMatch(mapping, handlerMethod, message);
334335
}
336+
335337
}

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,18 @@ public RequestSpec route(String route) {
7979

8080

8181
private static boolean isVoid(ResolvableType elementType) {
82-
return Void.class.equals(elementType.resolve()) || void.class.equals(elementType.resolve());
82+
return (Void.class.equals(elementType.resolve()) || void.class.equals(elementType.resolve()));
8383
}
8484

8585

8686
private class DefaultRequestSpec implements RequestSpec {
8787

8888
private final String route;
8989

90-
9190
DefaultRequestSpec(String route) {
9291
this.route = route;
9392
}
9493

95-
9694
@Override
9795
public ResponseSpec data(Object data) {
9896
Assert.notNull(data, "'data' must not be null");
@@ -195,7 +193,6 @@ private class DefaultResponseSpec implements ResponseSpec {
195193
@Nullable
196194
private final Flux<Payload> payloadFlux;
197195

198-
199196
DefaultResponseSpec(Mono<Payload> payloadMono) {
200197
this.payloadMono = payloadMono;
201198
this.payloadFlux = null;
@@ -206,10 +203,9 @@ private class DefaultResponseSpec implements ResponseSpec {
206203
this.payloadFlux = payloadFlux;
207204
}
208205

209-
210206
@Override
211207
public Mono<Void> send() {
212-
Assert.notNull(this.payloadMono, "No RSocket interaction model for one-way send with Flux.");
208+
Assert.state(this.payloadMono != null, "No RSocket interaction model for one-way send with Flux");
213209
return this.payloadMono.flatMap(rsocket::fireAndForget);
214210
}
215211

@@ -235,9 +231,7 @@ public <T> Flux<T> retrieveFlux(ParameterizedTypeReference<T> dataTypeRef) {
235231

236232
@SuppressWarnings("unchecked")
237233
private <T> Mono<T> retrieveMono(ResolvableType elementType) {
238-
Assert.notNull(this.payloadMono,
239-
"No RSocket interaction model for Flux request to Mono response.");
240-
234+
Assert.notNull(this.payloadMono, "No RSocket interaction model for Flux request to Mono response.");
241235
Mono<Payload> payloadMono = this.payloadMono.flatMap(rsocket::requestResponse);
242236

243237
if (isVoid(elementType)) {
@@ -251,7 +245,6 @@ private <T> Mono<T> retrieveMono(ResolvableType elementType) {
251245

252246
@SuppressWarnings("unchecked")
253247
private <T> Flux<T> retrieveFlux(ResolvableType elementType) {
254-
255248
Flux<Payload> payloadFlux = this.payloadMono != null ?
256249
this.payloadMono.flatMapMany(rsocket::requestStream) :
257250
rsocket.requestChannel(this.payloadFlux);
@@ -261,7 +254,6 @@ private <T> Flux<T> retrieveFlux(ResolvableType elementType) {
261254
}
262255

263256
Decoder<?> decoder = strategies.decoder(elementType, dataMimeType);
264-
265257
return payloadFlux.map(this::retainDataAndReleasePayload).map(dataBuffer ->
266258
(T) decoder.decode(dataBuffer, elementType, dataMimeType, EMPTY_HINTS));
267259
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import io.rsocket.transport.netty.client.WebsocketClientTransport;
2828
import reactor.core.publisher.Mono;
2929

30-
import org.springframework.lang.Nullable;
3130
import org.springframework.util.MimeType;
3231

3332
/**
@@ -38,12 +37,11 @@
3837
*/
3938
final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
4039

41-
@Nullable
4240
private List<Consumer<RSocketFactory.ClientRSocketFactory>> factoryConfigurers = new ArrayList<>();
4341

44-
@Nullable
4542
private List<Consumer<RSocketStrategies.Builder>> strategiesConfigurers = new ArrayList<>();
4643

44+
4745
@Override
4846
public RSocketRequester.Builder rsocketFactory(Consumer<RSocketFactory.ClientRSocketFactory> configurer) {
4947
this.factoryConfigurers.add(configurer);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ final class DefaultRSocketStrategies implements RSocketStrategies {
4747
private final DataBufferFactory bufferFactory;
4848

4949

50-
private DefaultRSocketStrategies(
51-
List<Encoder<?>> encoders, List<Decoder<?>> decoders,
50+
private DefaultRSocketStrategies(List<Encoder<?>> encoders, List<Decoder<?>> decoders,
5251
ReactiveAdapterRegistry adapterRegistry, DataBufferFactory bufferFactory) {
5352

5453
this.encoders = Collections.unmodifiableList(encoders);
@@ -93,7 +92,6 @@ static class DefaultRSocketStrategiesBuilder implements RSocketStrategies.Builde
9392
@Nullable
9493
private DataBufferFactory dataBufferFactory;
9594

96-
9795
public DefaultRSocketStrategiesBuilder() {
9896
}
9997

@@ -104,7 +102,6 @@ public DefaultRSocketStrategiesBuilder(RSocketStrategies other) {
104102
this.dataBufferFactory = other.dataBufferFactory();
105103
}
106104

107-
108105
@Override
109106
public Builder encoder(Encoder<?>... encoders) {
110107
this.encoders.addAll(Arrays.asList(encoders));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void setDefaultDataMimeType(@Nullable MimeType defaultDataMimeType) {
5959
@Override
6060
public Mono<RSocket> accept(ConnectionSetupPayload setupPayload, RSocket sendingRSocket) {
6161
MessagingRSocket rsocket = createRSocket(sendingRSocket);
62+
6263
// Allow handling of the ConnectionSetupPayload via @MessageMapping methods.
6364
// However, if the handling is to make requests to the client, it's expected
6465
// it will do so decoupled from the handling, e.g. via .subscribe().
@@ -71,8 +72,7 @@ public RSocket apply(RSocket sendingRSocket) {
7172
}
7273

7374
private MessagingRSocket createRSocket(RSocket rsocket) {
74-
return new MessagingRSocket(
75-
this::handleMessage, rsocket, this.defaultDataMimeType, getRSocketStrategies());
75+
return new MessagingRSocket(this::handleMessage, rsocket, this.defaultDataMimeType, getRSocketStrategies());
7676
}
7777

7878
}

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,24 @@
4242
*/
4343
public interface RSocketRequester {
4444

45-
4645
/**
4746
* Return the underlying RSocket used to make requests.
4847
*/
4948
RSocket rsocket();
5049

50+
// For now we treat metadata as a simple string that is the route.
51+
// This will change after the resolution of:
52+
// https://github.com/rsocket/rsocket-java/issues/568
53+
54+
/**
55+
* Entry point to prepare a new request to the given route.
56+
* <p>For requestChannel interactions, i.e. Flux-to-Flux the metadata is
57+
* attached to the first request payload.
58+
* @param route the routing destination
59+
* @return a spec for further defining and executing the reuqest
60+
*/
61+
RequestSpec route(String route);
62+
5163

5264
/**
5365
* Create a new {@code RSocketRequester} from the given {@link RSocket} and
@@ -68,20 +80,6 @@ static RSocketRequester.Builder builder() {
6880
return new DefaultRSocketRequesterBuilder();
6981
}
7082

71-
// For now we treat metadata as a simple string that is the route.
72-
// This will change after the resolution of:
73-
// https://github.com/rsocket/rsocket-java/issues/568
74-
75-
/**
76-
* Entry point to prepare a new request to the given route.
77-
*
78-
* <p>For requestChannel interactions, i.e. Flux-to-Flux the metadata is
79-
* attached to the first request payload.
80-
*
81-
* @param route the routing destination
82-
* @return a spec for further defining and executing the reuqest
83-
*/
84-
RequestSpec route(String route);
8583

8684
/**
8785
* A mutable builder for creating a client {@link RSocketRequester}.
@@ -129,7 +127,6 @@ RSocketRequester.Builder rsocketFactory(
129127
* @return a mono containing the connected {@code RSocketRequester}
130128
*/
131129
Mono<RSocketRequester> connectWebSocket(URI uri, MimeType dataMimeType);
132-
133130
}
134131

135132

0 commit comments

Comments
 (0)