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:
committed by
Gary Russell
parent
a01d09f0f1
commit
93d7c58b64
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -21,12 +21,16 @@ import java.io.PushbackInputStream;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link TcpNioConnectionSupport} for non-SSL
|
||||
* NIO connections.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
*/
|
||||
@@ -56,8 +60,9 @@ public class DefaultTcpNioConnectionSupport extends AbstractTcpConnectionSupport
|
||||
private volatile InputStream wrapped;
|
||||
|
||||
PushBackTcpNioConnection(SocketChannel socketChannel, boolean server, boolean lookupHost,
|
||||
ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName,
|
||||
ApplicationEventPublisher applicationEventPublisher, @Nullable String connectionFactoryName,
|
||||
int bufferSize) throws Exception {
|
||||
|
||||
super(socketChannel, server, lookupHost, applicationEventPublisher, connectionFactoryName);
|
||||
this.pushbackBufferSize = bufferSize;
|
||||
this.connectionId = "pushback:" + super.getConnectionId();
|
||||
|
||||
@@ -45,6 +45,8 @@ import org.springframework.util.Assert;
|
||||
* (incoming).
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
@@ -114,7 +116,8 @@ public abstract class TcpConnectionSupport implements TcpConnection {
|
||||
*/
|
||||
public TcpConnectionSupport(Socket socket, boolean server, boolean lookupHost,
|
||||
ApplicationEventPublisher applicationEventPublisher,
|
||||
String connectionFactoryName) {
|
||||
@Nullable String connectionFactoryName) {
|
||||
|
||||
this.socketInfo = new SocketInfo(socket);
|
||||
this.server = server;
|
||||
InetAddress inetAddress = socket.getInetAddress();
|
||||
|
||||
@@ -67,9 +67,13 @@ public class TcpNioConnection extends TcpConnectionSupport {
|
||||
|
||||
private final ChannelInputStream channelInputStream = new ChannelInputStream();
|
||||
|
||||
private volatile OutputStream bufferedOutputStream;
|
||||
private final AtomicInteger executionControl = new AtomicInteger();
|
||||
|
||||
private volatile boolean usingDirectBuffers;
|
||||
private boolean usingDirectBuffers;
|
||||
|
||||
private long pipeTimeout = DEFAULT_PIPE_TIMEOUT;
|
||||
|
||||
private volatile OutputStream bufferedOutputStream;
|
||||
|
||||
private volatile CompositeExecutor taskExecutor;
|
||||
|
||||
@@ -81,14 +85,10 @@ public class TcpNioConnection extends TcpConnectionSupport {
|
||||
|
||||
private volatile long lastSend;
|
||||
|
||||
private final AtomicInteger executionControl = new AtomicInteger();
|
||||
|
||||
private volatile boolean writingToPipe;
|
||||
|
||||
private volatile CountDownLatch writingLatch;
|
||||
|
||||
private volatile long pipeTimeout = DEFAULT_PIPE_TIMEOUT;
|
||||
|
||||
private volatile boolean timedOut;
|
||||
|
||||
/**
|
||||
@@ -99,17 +99,13 @@ public class TcpNioConnection extends TcpConnectionSupport {
|
||||
* @param lookupHost true to perform reverse lookups.
|
||||
* @param applicationEventPublisher The event publisher.
|
||||
* @param connectionFactoryName The name of the connection factory creating this connection.
|
||||
* @throws Exception Any Exception.
|
||||
*/
|
||||
public TcpNioConnection(SocketChannel socketChannel, boolean server, boolean lookupHost,
|
||||
ApplicationEventPublisher applicationEventPublisher,
|
||||
String connectionFactoryName) throws Exception {
|
||||
@Nullable String connectionFactoryName) {
|
||||
|
||||
super(socketChannel.socket(), server, lookupHost, applicationEventPublisher, connectionFactoryName);
|
||||
this.socketChannel = socketChannel;
|
||||
int receiveBufferSize = socketChannel.socket().getReceiveBufferSize();
|
||||
if (receiveBufferSize <= 0) {
|
||||
receiveBufferSize = this.maxMessageSize;
|
||||
}
|
||||
this.channelOutputStream = new ChannelOutputStream();
|
||||
}
|
||||
|
||||
@@ -735,9 +731,8 @@ public class TcpNioConnection extends TcpConnectionSupport {
|
||||
|
||||
/**
|
||||
* Blocks if the blocking queue already contains 5 buffers.
|
||||
* @param array
|
||||
* @param bytesToWrite
|
||||
* @throws IOException
|
||||
* @param byteBuffer to write
|
||||
* @throws IOException writing to the buffer exception
|
||||
*/
|
||||
public void write(ByteBuffer byteBuffer) throws IOException {
|
||||
int bytesToWrite = byteBuffer.limit() - byteBuffer.position();
|
||||
@@ -774,7 +769,7 @@ public class TcpNioConnection extends TcpConnectionSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
public int available() {
|
||||
return this.available.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -31,6 +31,7 @@ import javax.net.ssl.SSLHandshakeException;
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -48,7 +49,10 @@ import org.springframework.util.Assert;
|
||||
* Also, it may be deemed necessary to re-perform handshaking.<p>
|
||||
* This class supports the management of handshaking as necessary, both from the
|
||||
* initiating and receiving peers.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
*/
|
||||
@@ -77,8 +81,9 @@ public class TcpNioSSLConnection extends TcpNioConnection {
|
||||
private SSLHandshakeException sslFatal;
|
||||
|
||||
public TcpNioSSLConnection(SocketChannel socketChannel, boolean server, boolean lookupHost,
|
||||
ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName,
|
||||
ApplicationEventPublisher applicationEventPublisher, @Nullable String connectionFactoryName,
|
||||
SSLEngine sslEngine) throws Exception {
|
||||
|
||||
super(socketChannel, server, lookupHost, applicationEventPublisher, connectionFactoryName);
|
||||
this.sslEngine = sslEngine;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ import org.springframework.util.StopWatch;
|
||||
*/
|
||||
public class TcpNioConnectionTests {
|
||||
|
||||
private final static Log logger = LogFactory.getLog(TcpNioConnectionTests.class);
|
||||
private static final Log logger = LogFactory.getLog(TcpNioConnectionTests.class);
|
||||
|
||||
@Rule
|
||||
public Log4j2LevelAdjuster adjuster =
|
||||
@@ -268,7 +268,7 @@ public class TcpNioConnectionTests {
|
||||
connections.put(chan1, conn1);
|
||||
connections.put(chan2, conn2);
|
||||
connections.put(chan3, conn3);
|
||||
final List<Field> fields = new ArrayList<Field>();
|
||||
final List<Field> fields = new ArrayList<>();
|
||||
ReflectionUtils.doWithFields(SocketChannel.class, field -> {
|
||||
field.setAccessible(true);
|
||||
fields.add(field);
|
||||
@@ -279,7 +279,7 @@ public class TcpNioConnectionTests {
|
||||
ReflectionUtils.setField(field, chan2, true);
|
||||
ReflectionUtils.setField(field, chan3, true);
|
||||
Selector selector = mock(Selector.class);
|
||||
HashSet<SelectionKey> keys = new HashSet<SelectionKey>();
|
||||
HashSet<SelectionKey> keys = new HashSet<>();
|
||||
when(selector.selectedKeys()).thenReturn(keys);
|
||||
factory.processNioSelections(1, selector, null, connections);
|
||||
assertEquals(3, connections.size()); // all open
|
||||
|
||||
Reference in New Issue
Block a user