Enable ModifierOrderCheck Checkstyle rule (#2673)

* Enable ModifierOrderCheck Checkstyle rule

* Fix violations for `static` and `abstract` modifier
* Remove redundant code in the `TcpNioConnection`
* Mark `connectionFactoryName` as `@Nullable` in the `TcpConnectionSupport`
ctor and its inheritors
* Fix some smells according IDEA suggestions in the affected classes
* This should fix some Sonar smells as well

* * Fix `HeaderMapperTests`

* * Polishing `TcpConnection` code style and fix Javdocs
This commit is contained in:
Artem Bilan
2018-12-20 19:19:47 -05:00
committed by Gary Russell
parent a01d09f0f1
commit 93d7c58b64
56 changed files with 633 additions and 563 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2018 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.
@@ -38,16 +38,17 @@ import org.springframework.web.socket.messaging.SubProtocolHandler;
*
* @author Andy Wilkinson
* @author Artem Bilan
*
* @since 4.1
*
* @see org.springframework.integration.websocket.inbound.WebSocketInboundChannelAdapter
* @see org.springframework.integration.websocket.outbound.WebSocketOutboundMessageHandler
*/
public final class SubProtocolHandlerRegistry {
private final static Log logger = LogFactory.getLog(SubProtocolHandlerRegistry.class);
private static final Log logger = LogFactory.getLog(SubProtocolHandlerRegistry.class);
private final Map<String, SubProtocolHandler> protocolHandlers =
new TreeMap<String, SubProtocolHandler>(String.CASE_INSENSITIVE_ORDER);
private final Map<String, SubProtocolHandler> protocolHandlers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private final SubProtocolHandler defaultProtocolHandler;
@@ -68,7 +69,9 @@ public final class SubProtocolHandlerRegistry {
for (SubProtocolHandler handler : protocolHandlers) {
List<String> protocols = handler.getSupportedProtocols();
if (CollectionUtils.isEmpty(protocols)) {
logger.warn("No sub-protocols, ignoring handler " + handler);
if (logger.isWarnEnabled()) {
logger.warn("No sub-protocols, ignoring handler " + handler);
}
continue;
}
for (String protocol : protocols) {
@@ -112,7 +115,7 @@ public final class SubProtocolHandlerRegistry {
if (StringUtils.hasText(protocol)) {
handler = this.protocolHandlers.get(protocol);
Assert.state(handler != null,
"No handler for sub-protocol '" + protocol + "', handlers = " + this.protocolHandlers);
() -> "No handler for sub-protocol '" + protocol + "', handlers = " + this.protocolHandlers);
}
else {
handler = this.defaultProtocolHandler;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 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.
@@ -53,11 +53,12 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient;
/**
* @author Artem Bilan
*
* @since 4.1
*/
public class ClientWebSocketContainerTests {
private final static TomcatWebSocketTestServer server = new TomcatWebSocketTestServer(TestServerConfig.class);
private static final TomcatWebSocketTestServer server = new TomcatWebSocketTestServer(TestServerConfig.class);
@BeforeClass
public static void setup() throws Exception {
@@ -71,8 +72,7 @@ public class ClientWebSocketContainerTests {
@Test
public void testClientWebSocketContainer() throws Exception {
final AtomicBoolean failure = new AtomicBoolean();
AtomicBoolean failure = new AtomicBoolean();
StandardWebSocketClient webSocketClient = new StandardWebSocketClient() {
@@ -93,9 +93,8 @@ public class ClientWebSocketContainerTests {
};
Map<String, Object> userProperties = new HashMap<String, Object>();
userProperties.put(Constants.IO_TIMEOUT_MS_PROPERTY,
"" + (Constants.IO_TIMEOUT_MS_DEFAULT * 6));
Map<String, Object> userProperties = new HashMap<>();
userProperties.put(Constants.IO_TIMEOUT_MS_PROPERTY, "" + (Constants.IO_TIMEOUT_MS_DEFAULT * 6));
webSocketClient.setUserProperties(userProperties);
ClientWebSocketContainer container =
@@ -123,7 +122,8 @@ public class ClientWebSocketContainerTests {
}
catch (Exception e) {
assertThat(e, instanceOf(IllegalStateException.class));
assertEquals(e.getMessage(), "'clientSession' has not been established. Consider to 'start' this container.");
assertEquals(e.getMessage(),
"'clientSession' has not been established. Consider to 'start' this container.");
}
assertTrue(messageListener.sessionEndedLatch.await(10, TimeUnit.SECONDS));
@@ -164,18 +164,18 @@ public class ClientWebSocketContainerTests {
public final CountDownLatch sessionEndedLatch = new CountDownLatch(1);
@Override
public void onMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
public void onMessage(WebSocketSession session, WebSocketMessage<?> message) {
this.message = message;
this.messageLatch.countDown();
}
@Override
public void afterSessionStarted(WebSocketSession session) throws Exception {
public void afterSessionStarted(WebSocketSession session) {
this.started = true;
}
@Override
public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus) throws Exception {
public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus) {
sessionEndedLatch.countDown();
}

View File

@@ -93,7 +93,6 @@ import org.springframework.web.socket.server.RequestUpgradeStrategy;
import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
import org.springframework.web.socket.sockjs.client.SockJsClient;
import org.springframework.web.socket.sockjs.client.Transport;
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
/**
@@ -106,7 +105,7 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
@DirtiesContext
public class WebSocketServerTests {
private final static SpelExpressionParser PARSER = new SpelExpressionParser();
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
@Autowired
@Qualifier("webSocketOutputChannel")
@@ -126,7 +125,7 @@ public class WebSocketServerTests {
private Lifecycle requestUpgradeStrategy;
@Test
public void testWebSocketOutboundMessageHandler() throws Exception {
public void testWebSocketOutboundMessageHandler() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
headers.setSubscriptionId("subs1");
headers.setDestination("/queue/foo");
@@ -166,7 +165,7 @@ public class WebSocketServerTests {
}
@Test
public void testBrokerIsNotPresented() throws Exception {
public void testBrokerIsNotPresented() {
WebSocketInboundChannelAdapter webSocketInboundChannelAdapter =
new WebSocketInboundChannelAdapter(Mockito.mock(ServerWebSocketContainer.class));
webSocketInboundChannelAdapter.setOutputChannel(new DirectChannel());
@@ -195,7 +194,7 @@ public class WebSocketServerTests {
@Bean
public WebSocketClient webSocketClient() {
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new StandardWebSocketClient())));
return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient())));
}
@Bean