More defensive checks when queuing read and write checks to the static executor.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1405122 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2012-11-02 19:39:53 +00:00
parent 437ea2f6e5
commit 32e009dd7b
1 changed files with 69 additions and 47 deletions

View File

@ -18,6 +18,7 @@ package org.apache.activemq.transport;
import java.io.IOException;
import java.util.Timer;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
@ -107,6 +108,7 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
private final Runnable writeChecker = new Runnable() {
long lastRunTime;
public void run() {
long now = System.currentTimeMillis();
if (lastRunTime != 0 && LOG.isDebugEnabled()) {
@ -146,10 +148,14 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
return;
}
if (!commandSent.get() && useKeepAlive && monitorStarted.get() && !ASYNC_TASKS.isTerminating()) {
if (!commandSent.get() && useKeepAlive && monitorStarted.get() &&
!ASYNC_TASKS.isTerminating() && !ASYNC_TASKS.isTerminated()) {
if (LOG.isTraceEnabled()) {
LOG.trace(this + " no message sent since last write check, sending a KeepAliveInfo");
}
try {
ASYNC_TASKS.execute(new Runnable() {
public void run() {
if (LOG.isDebugEnabled()) {
@ -179,6 +185,12 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
return "WriteCheck[" + getRemoteAddress() + "]";
};
});
} catch (RejectedExecutionException ex) {
if (!ASYNC_TASKS.isTerminating() && !ASYNC_TASKS.isTerminated()) {
LOG.error("Async write check was rejected from the executor: ", ex);
throw ex;
}
}
} else {
if (LOG.isTraceEnabled()) {
LOG.trace(this + " message sent since last write check, resetting flag");
@ -197,10 +209,14 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
}
return;
}
if (!commandReceived.get() && monitorStarted.get() && !ASYNC_TASKS.isTerminating()) {
if (!commandReceived.get() && monitorStarted.get() &&
!ASYNC_TASKS.isTerminating() && !ASYNC_TASKS.isTerminated()) {
if (LOG.isDebugEnabled()) {
LOG.debug("No message received since last read check for " + toString() + ". Throwing InactivityIOException.");
}
try {
ASYNC_TASKS.execute(new Runnable() {
public void run() {
if (LOG.isDebugEnabled()) {
@ -214,6 +230,12 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
return "ReadCheck[" + getRemoteAddress() + "]";
};
});
} catch (RejectedExecutionException ex) {
if (!ASYNC_TASKS.isTerminating() && !ASYNC_TASKS.isTerminated()) {
LOG.error("Async read check was rejected from the executor: ", ex);
throw ex;
}
}
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("Message received since last read check, resetting flag: ");