Skip to content

Commit d2cc97a

Browse files
committed
Polishing
1 parent f219680 commit d2cc97a

File tree

16 files changed

+82
-79
lines changed

16 files changed

+82
-79
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -38,8 +38,7 @@
3838
public abstract class AbstractSubscriptionRegistry implements SubscriptionRegistry {
3939

4040
private static MultiValueMap<String, String> EMPTY_MAP =
41-
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<String, String>(0));
42-
41+
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(0));
4342

4443
protected final Log logger = LogFactory.getLog(getClass());
4544

@@ -55,19 +54,25 @@ public final void registerSubscription(Message<?> message) {
5554

5655
String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
5756
if (sessionId == null) {
58-
logger.error("No sessionId in " + message);
57+
if (logger.isErrorEnabled()) {
58+
logger.error("No sessionId in " + message);
59+
}
5960
return;
6061
}
6162

6263
String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers);
6364
if (subscriptionId == null) {
64-
logger.error("No subscriptionId in " + message);
65+
if (logger.isErrorEnabled()) {
66+
logger.error("No subscriptionId in " + message);
67+
}
6568
return;
6669
}
6770

6871
String destination = SimpMessageHeaderAccessor.getDestination(headers);
6972
if (destination == null) {
70-
logger.error("No destination in " + message);
73+
if (logger.isErrorEnabled()) {
74+
logger.error("No destination in " + message);
75+
}
7176
return;
7277
}
7378

@@ -85,13 +90,17 @@ public final void unregisterSubscription(Message<?> message) {
8590

8691
String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
8792
if (sessionId == null) {
88-
logger.error("No sessionId in " + message);
93+
if (logger.isErrorEnabled()) {
94+
logger.error("No sessionId in " + message);
95+
}
8996
return;
9097
}
9198

9299
String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers);
93100
if (subscriptionId == null) {
94-
logger.error("No subscriptionId " + message);
101+
if (logger.isErrorEnabled()) {
102+
logger.error("No subscriptionId " + message);
103+
}
95104
return;
96105
}
97106

@@ -109,22 +118,23 @@ public final MultiValueMap<String, String> findSubscriptions(Message<?> message)
109118

110119
String destination = SimpMessageHeaderAccessor.getDestination(headers);
111120
if (destination == null) {
112-
logger.error("No destination in " + message);
121+
if (logger.isErrorEnabled()) {
122+
logger.error("No destination in " + message);
123+
}
113124
return EMPTY_MAP;
114125
}
115126

116127
return findSubscriptionsInternal(destination, message);
117128
}
118129

119130

120-
protected abstract void addSubscriptionInternal(String sessionId, String subscriptionId,
121-
String destination, Message<?> message);
131+
protected abstract void addSubscriptionInternal(
132+
String sessionId, String subscriptionId, String destination, Message<?> message);
122133

123-
protected abstract void removeSubscriptionInternal(String sessionId, String subscriptionId, Message<?> message);
134+
protected abstract void removeSubscriptionInternal(
135+
String sessionId, String subscriptionId, Message<?> message);
124136

125-
@Override
126-
public abstract void unregisterAllSubscriptions(String sessionId);
127-
128-
protected abstract MultiValueMap<String, String> findSubscriptionsInternal(String destination, Message<?> message);
137+
protected abstract MultiValueMap<String, String> findSubscriptionsInternal(
138+
String destination, Message<?> message);
129139

130140
}

spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public String getSelectorHeaderName() {
136136

137137

138138
@Override
139-
protected void addSubscriptionInternal(String sessionId, String subsId, String destination,
140-
Message<?> message) {
139+
protected void addSubscriptionInternal(
140+
String sessionId, String subsId, String destination, Message<?> message) {
141141

142142
Expression expression = null;
143143
MessageHeaders headers = message.getHeaders();
@@ -478,13 +478,14 @@ public String toString() {
478478
}
479479

480480

481-
private static class Subscription {
481+
private static final class Subscription {
482482

483483
private final String id;
484484

485485
private final Expression selectorExpression;
486486

487487
public Subscription(String id, Expression selector) {
488+
Assert.notNull(id, "Subscription id must not be null");
488489
this.id = id;
489490
this.selectorExpression = selector;
490491
}
@@ -499,19 +500,12 @@ public Expression getSelectorExpression() {
499500

500501
@Override
501502
public boolean equals(Object other) {
502-
if (this == other) {
503-
return true;
504-
}
505-
if (other == null || getClass() != other.getClass()) {
506-
return false;
507-
}
508-
return getId().equals(((Subscription) other).getId());
509-
503+
return (this == other || (other instanceof Subscription && this.id.equals(((Subscription) other).id)));
510504
}
511505

512506
@Override
513507
public int hashCode() {
514-
return getId().hashCode();
508+
return this.id.hashCode();
515509
}
516510

517511
@Override

spring-messaging/src/main/java/org/springframework/messaging/tcp/ReconnectStrategy.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.messaging.tcp;
1818

19-
2019
/**
2120
* A contract to determine the frequency of reconnect attempts after connection failure.
2221
*

spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/AbstractNioBufferReactorNettyCodec.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.messaging.tcp.reactor;
1718

1819
import java.nio.ByteBuffer;
@@ -41,13 +42,14 @@ public Collection<Message<P>> decode(ByteBuf inputBuffer) {
4142
return messages;
4243
}
4344

44-
protected abstract List<Message<P>> decodeInternal(ByteBuffer nioBuffer);
45-
4645
@Override
4746
public void encode(Message<P> message, ByteBuf outputBuffer) {
4847
outputBuffer.writeBytes(encodeInternal(message));
4948
}
5049

50+
51+
protected abstract List<Message<P>> decodeInternal(ByteBuffer nioBuffer);
52+
5153
protected abstract ByteBuffer encodeInternal(Message<P> message);
5254

5355
}

spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/MonoToListenableFutureAdapter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -28,12 +28,10 @@
2828
*/
2929
class MonoToListenableFutureAdapter<T> extends AbstractMonoToListenableFutureAdapter<T, T> {
3030

31-
3231
public MonoToListenableFutureAdapter(Mono<T> mono) {
3332
super(mono);
3433
}
3534

36-
3735
@Override
3836
protected T adapt(T result) {
3937
return result;

spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -115,6 +115,7 @@ public ReactorNettyTcpClient(Consumer<ClientOptions> optionsConsumer, ReactorNet
115115
@Override
116116
public ListenableFuture<Void> connect(final TcpConnectionHandler<P> handler) {
117117
Assert.notNull(handler, "TcpConnectionHandler is required");
118+
118119
if (this.stopping) {
119120
return handleShuttingDownConnectFailure(handler);
120121
}
@@ -131,6 +132,7 @@ public ListenableFuture<Void> connect(final TcpConnectionHandler<P> handler) {
131132
public ListenableFuture<Void> connect(TcpConnectionHandler<P> handler, ReconnectStrategy strategy) {
132133
Assert.notNull(handler, "TcpConnectionHandler is required");
133134
Assert.notNull(strategy, "ReconnectStrategy is required");
135+
134136
if (this.stopping) {
135137
return handleShuttingDownConnectFailure(handler);
136138
}
@@ -189,7 +191,6 @@ public ListenableFuture<Void> shutdown() {
189191
ChannelGroupFuture close = this.channelGroup.close();
190192
Mono<Void> completion = FutureMono.from(close)
191193
.doAfterTerminate((x, e) -> {
192-
193194
// TODO: https://github.com/reactor/reactor-netty/issues/24
194195
shutdownGlobalResources();
195196

@@ -211,14 +212,14 @@ public ListenableFuture<Void> shutdown() {
211212
return new MonoToListenableFutureAdapter<>(completion);
212213
}
213214

214-
private static void shutdownGlobalResources() {
215+
private void shutdownGlobalResources() {
215216
try {
216217
Method method = TcpResources.class.getDeclaredMethod("_dispose");
217218
ReflectionUtils.makeAccessible(method);
218219
ReflectionUtils.invokeMethod(method, TcpResources.get());
219220
}
220221
catch (NoSuchMethodException ex) {
221-
ex.printStackTrace();
222+
// ignore
222223
}
223224
}
224225

@@ -227,15 +228,13 @@ private class ReactorNettyHandler implements BiFunction<NettyInbound, NettyOutbo
227228

228229
private final TcpConnectionHandler<P> connectionHandler;
229230

230-
231231
ReactorNettyHandler(TcpConnectionHandler<P> handler) {
232232
this.connectionHandler = handler;
233233
}
234234

235-
@SuppressWarnings("unchecked")
236235
@Override
236+
@SuppressWarnings("unchecked")
237237
public Publisher<Void> apply(NettyInbound inbound, NettyOutbound outbound) {
238-
239238
DirectProcessor<Void> completion = DirectProcessor.create();
240239
TcpConnection<P> connection = new ReactorNettyTcpConnection<>(inbound, outbound, codec, completion);
241240
scheduler.schedule(() -> connectionHandler.afterConnected(connection));
@@ -254,6 +253,7 @@ public Publisher<Void> apply(NettyInbound inbound, NettyOutbound outbound) {
254253
}
255254
}
256255

256+
257257
private static class StompMessageDecoder<P> extends ByteToMessageDecoder {
258258

259259
private final ReactorNettyCodec<P> codec;

spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpConnection.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -66,7 +66,6 @@ public ListenableFuture<Void> send(Message<P> message) {
6666
@Override
6767
@SuppressWarnings("deprecation")
6868
public void onReadInactivity(Runnable runnable, long inactivityDuration) {
69-
7069
// TODO: workaround for https://github.com/reactor/reactor-netty/issues/22
7170
ChannelPipeline pipeline = this.inbound.context().channel().pipeline();
7271
String name = NettyPipeline.OnChannelReadIdle;

spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -112,7 +112,7 @@ public void setAllowedOrigins(List<String> allowedOrigins) {
112112
}
113113

114114
/**
115-
* Return the configured origins to allow, possibly {@code null}.
115+
* Return the configured origins to allow, or {@code null} if none.
116116
* @see #addAllowedOrigin(String)
117117
* @see #setAllowedOrigins(List)
118118
*/
@@ -155,7 +155,7 @@ public void setAllowedMethods(List<String> allowedMethods) {
155155
}
156156

157157
/**
158-
* Return the allowed HTTP methods, possibly {@code null} in which case
158+
* Return the allowed HTTP methods, or {@code null} in which case
159159
* only {@code "GET"} and {@code "HEAD"} allowed.
160160
* @see #addAllowedMethod(HttpMethod)
161161
* @see #addAllowedMethod(String)
@@ -208,7 +208,7 @@ public void setAllowedHeaders(List<String> allowedHeaders) {
208208
}
209209

210210
/**
211-
* Return the allowed actual request headers, possibly {@code null}.
211+
* Return the allowed actual request headers, or {@code null} if none.
212212
* @see #addAllowedHeader(String)
213213
* @see #setAllowedHeaders(List)
214214
*/
@@ -242,7 +242,7 @@ public void setExposedHeaders(List<String> exposedHeaders) {
242242
}
243243

244244
/**
245-
* Return the configured response headers to expose, possibly {@code null}.
245+
* Return the configured response headers to expose, or {@code null} if none.
246246
* @see #addExposedHeader(String)
247247
* @see #setExposedHeaders(List)
248248
*/
@@ -273,7 +273,7 @@ public void setAllowCredentials(Boolean allowCredentials) {
273273
}
274274

275275
/**
276-
* Return the configured {@code allowCredentials} flag, possibly {@code null}.
276+
* Return the configured {@code allowCredentials} flag, or {@code null} if none.
277277
* @see #setAllowCredentials(Boolean)
278278
*/
279279
public Boolean getAllowCredentials() {
@@ -290,7 +290,7 @@ public void setMaxAge(Long maxAge) {
290290
}
291291

292292
/**
293-
* Return the configured {@code maxAge} value, possibly {@code null}.
293+
* Return the configured {@code maxAge} value, or {@code null} if none.
294294
* @see #setMaxAge(Long)
295295
*/
296296
public Long getMaxAge() {
@@ -378,7 +378,7 @@ private List<String> combine(List<String> source, List<String> other) {
378378
/**
379379
* Check the origin of the request against the configured allowed origins.
380380
* @param requestOrigin the origin to check
381-
* @return the origin to use for the response, possibly {@code null} which
381+
* @return the origin to use for the response, or {@code null} which
382382
* means the request origin is not allowed
383383
*/
384384
public String checkOrigin(String requestOrigin) {

spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
/**
2727
* A function that can extract data from a {@link ReactiveHttpInputMessage} body.
2828
*
29-
* @param <T> the type of data to extract
30-
* @param <M> the type of {@link ReactiveHttpInputMessage} this extractor can be applied to
31-
*
3229
* @author Arjen Poutsma
3330
* @since 5.0
31+
* @param <T> the type of data to extract
32+
* @param <M> the type of {@link ReactiveHttpInputMessage} this extractor can be applied to
3433
* @see BodyExtractors
3534
*/
3635
@FunctionalInterface

spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828
/**
2929
* A combination of functions that can populate a {@link ReactiveHttpOutputMessage} body.
3030
*
31-
* @param <T> the type of data to insert
32-
* @param <M> the type of {@link ReactiveHttpOutputMessage} this inserter can be applied to
33-
*
3431
* @author Arjen Poutsma
3532
* @since 5.0
33+
* @param <T> the type of data to insert
34+
* @param <M> the type of {@link ReactiveHttpOutputMessage} this inserter can be applied to
3635
* @see BodyInserters
3736
*/
3837
@FunctionalInterface

0 commit comments

Comments
 (0)