From 1656e1dd5282d929aff5d4a440d2998fdb8e9f01 Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Wed, 19 Mar 2008 15:48:41 +0000 Subject: [PATCH] Avoid generating additional exception after the first one reported. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@638886 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/transport/InactivityMonitor.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java b/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java index 003dc3ddf8..cc31a265be 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/InactivityMonitor.java @@ -50,7 +50,7 @@ public class InactivityMonitor extends TransportFilter { private final AtomicBoolean commandSent = new AtomicBoolean(false); private final AtomicBoolean inSend = new AtomicBoolean(false); - private final AtomicBoolean inactive = new AtomicBoolean(false); + private final AtomicBoolean failed = new AtomicBoolean(false); private final AtomicBoolean commandReceived = new AtomicBoolean(true); private final AtomicBoolean inReceive = new AtomicBoolean(false); @@ -151,13 +151,13 @@ public class InactivityMonitor extends TransportFilter { return; } if (!commandReceived.get()) { - if( !inactive.getAndSet(true) ) { + if( !failed.getAndSet(true) ) { if (LOG.isDebugEnabled()) { LOG.debug("No message received since last read check for " + toString() + "! Throwing InactivityIOException."); } ASYNC_TASKS.execute(new Runnable() { public void run() { - onException(new InactivityIOException("Channel was inactive for too long: "+next.getRemoteAddress())); + handleException(new InactivityIOException("Channel was inactive for too long: "+next.getRemoteAddress())); }; }); @@ -224,7 +224,7 @@ public class InactivityMonitor extends TransportFilter { startMonitorThreads(); } } - if( inactive.get() ) { + if( failed.get() ) { throw new InactivityIOException("Channel was inactive for too long: "+next.getRemoteAddress()); } next.oneway(o); @@ -236,12 +236,18 @@ public class InactivityMonitor extends TransportFilter { } public void onException(IOException error) { - if (monitorStarted.get()) { - stopMonitorThreads(); - } - transportListener.onException(error); + if( !failed.getAndSet(true) ) { + handleException(error); + } } + private void handleException(IOException error) { + if (monitorStarted.get()) { + stopMonitorThreads(); + } + transportListener.onException(error); + } + private synchronized void startMonitorThreads() throws IOException { if (monitorStarted.get()) { return;