From 772a01be79911d8c5663321f3278f3bac289a16a 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. --- .../ip/tcp/connection/TcpConnectionSupport.java | 10 ++++++++++ .../ip/tcp/connection/TcpNetConnection.java | 9 ++++----- .../ip/tcp/connection/TcpNioConnection.java | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java index 2b702091b6..ab9a91b8db 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java @@ -86,6 +86,8 @@ public abstract class TcpConnectionSupport implements TcpConnection { private final AtomicBoolean exceptionSent = new AtomicBoolean(); + private volatile boolean noReadErrorOnClose; + public TcpConnectionSupport() { this.server = false; this.applicationEventPublisher = null; @@ -308,6 +310,14 @@ public abstract class TcpConnectionSupport implements TcpConnection { return this.connectionId; } + protected boolean isNoReadErrorOnClose() { + return noReadErrorOnClose; + } + + protected void setNoReadErrorOnClose(boolean noReadErrorOnClose) { + this.noReadErrorOnClose = noReadErrorOnClose; + } + protected final void sendExceptionToListener(Exception e) { if (!this.exceptionSent.getAndSet(true) && this.getListener() != null) { Map headers = Collections.singletonMap(IpHeaders.CONNECTION_ID, 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 fc5821d353..204494b300 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 @@ -37,8 +37,6 @@ public class TcpNetConnection extends TcpConnectionSupport { private final Socket socket; - private boolean noReadErrorOnClose; - private volatile long lastRead = System.currentTimeMillis(); private volatile long lastSend; @@ -81,10 +79,11 @@ public class TcpNetConnection extends TcpConnectionSupport { */ @Override public void close() { - this.noReadErrorOnClose = true; + this.setNoReadErrorOnClose(true); try { this.socket.close(); - } catch (Exception e) {} + } + catch (Exception e) {} super.close(); } @@ -217,7 +216,7 @@ public class TcpNetConnection extends TcpConnectionSupport { } } 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 55abdbcfa4..139f6ba061 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 @@ -112,16 +112,19 @@ public class TcpNioConnection extends TcpConnectionSupport { @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(); } @@ -211,12 +214,20 @@ public class TcpNioConnection extends TcpConnectionSupport { 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(); this.sendExceptionToListener(e); return;