From 1287c586845df0a350b9d139885901c41f334866 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Mon, 16 Sep 2013 22:55:15 -0400 Subject: [PATCH] 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 --- .../tcp/connection/AbstractTcpConnection.java | 10 ++++++++++ .../ip/tcp/connection/TcpNetConnection.java | 9 ++++----- .../ip/tcp/connection/TcpNioConnection.java | 18 +++++++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractTcpConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractTcpConnection.java index 5db643e5a7..5922451f28 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractTcpConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractTcpConnection.java @@ -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; + } + } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java index bf299ae975..81ff41b9ea 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java @@ -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()) { diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java index 0317bcf247..bb74923af6 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java @@ -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; }