INT-3098 TCP Suppress Error Log on Normal Close

Net connections suppress error logs, NIO connections did not.

Conflicts:

	spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractTcpConnection.java
	spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java

Resolved
This commit is contained in:
Gary Russell
2013-09-16 22:55:15 -04:00
parent ae282dd1d5
commit 1287c58684
3 changed files with 29 additions and 8 deletions

View File

@@ -72,6 +72,8 @@ public abstract class AbstractTcpConnection implements TcpConnection {
private volatile String hostAddress = "unknown";
private volatile boolean noReadErrorOnClose;
public AbstractTcpConnection(Socket socket, boolean server, boolean lookupHost) {
this.server = server;
InetAddress inetAddress = socket.getInetAddress();
@@ -262,4 +264,12 @@ public abstract class AbstractTcpConnection implements TcpConnection {
return this.connectionId;
}
protected boolean isNoReadErrorOnClose() {
return noReadErrorOnClose;
}
protected void setNoReadErrorOnClose(boolean noReadErrorOnClose) {
this.noReadErrorOnClose = noReadErrorOnClose;
}
}

View File

@@ -36,8 +36,6 @@ public class TcpNetConnection extends AbstractTcpConnection {
private final Socket socket;
private boolean noReadErrorOnClose;
private volatile long lastRead = System.currentTimeMillis();
private volatile long lastSend;
@@ -58,10 +56,11 @@ public class TcpNetConnection extends AbstractTcpConnection {
*/
@Override
public void close() {
this.noReadErrorOnClose = true;
this.setNoReadErrorOnClose(true);
try {
this.socket.close();
} catch (Exception e) {}
}
catch (Exception e) {}
super.close();
}
@@ -176,7 +175,7 @@ public class TcpNetConnection extends AbstractTcpConnection {
}
}
if (doClose) {
boolean noReadErrorOnClose = this.noReadErrorOnClose;
boolean noReadErrorOnClose = this.isNoReadErrorOnClose();
this.closeConnection();
if (!(e instanceof SoftEndOfStreamException)) {
if (e instanceof SocketTimeoutException && this.isSingleUse()) {

View File

@@ -96,16 +96,19 @@ public class TcpNioConnection extends AbstractTcpConnection {
@Override
public void close() {
this.setNoReadErrorOnClose(true);
doClose();
}
private void doClose() {
try {
channelInputStream.close();
} catch (IOException e) {}
}
catch (IOException e) {}
try {
this.socketChannel.close();
} catch (Exception e) {}
}
catch (Exception e) {}
super.close();
}
@@ -182,12 +185,21 @@ public class TcpNioConnection extends AbstractTcpConnection {
if (logger.isTraceEnabled()) {
logger.error("Read exception " +
this.getConnectionId(), e);
} else {
}
else if (!this.isNoReadErrorOnClose()) {
logger.error("Read exception " +
this.getConnectionId() + " " +
e.getClass().getSimpleName() +
":" + e.getCause() + ":" + e.getMessage());
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Read exception " +
this.getConnectionId() + " " +
e.getClass().getSimpleName() +
":" + e.getCause() + ":" + e.getMessage());
}
}
this.closeConnection();
return;
}