git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1438209 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2013-01-24 21:38:33 +00:00
parent 6dce677baa
commit 80d0605682
1 changed files with 37 additions and 21 deletions

View File

@ -74,6 +74,8 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
private final Runnable readChecker = new Runnable() { private final Runnable readChecker = new Runnable() {
long lastRunTime; long lastRunTime;
@Override
public void run() { public void run() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long elapsed = (now - lastRunTime); long elapsed = (now - lastRunTime);
@ -86,8 +88,10 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
// the next read check on time which causes the time elapsed between // the next read check on time which causes the time elapsed between
// read checks to be small.. // read checks to be small..
// If less than 90% of the read check Time elapsed then abort this readcheck. // If less than 90% of the read check Time elapsed then abort this
if( !allowReadCheck(elapsed) ) { // FUNKY qdox bug does not allow me to inline this expression. // readcheck.
if (!allowReadCheck(elapsed)) { // FUNKY qdox bug does not allow me
// to inline this expression.
LOG.debug("Aborting read check.. Not enough time elapsed since last read check."); LOG.debug("Aborting read check.. Not enough time elapsed since last read check.");
return; return;
} }
@ -109,6 +113,7 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
private final Runnable writeChecker = new Runnable() { private final Runnable writeChecker = new Runnable() {
long lastRunTime; long lastRunTime;
@Override
public void run() { public void run() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (lastRunTime != 0 && LOG.isDebugEnabled()) { if (lastRunTime != 0 && LOG.isDebugEnabled()) {
@ -130,11 +135,13 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
this.wireFormat = wireFormat; this.wireFormat = wireFormat;
} }
@Override
public void start() throws Exception { public void start() throws Exception {
next.start(); next.start();
startMonitorThreads(); startMonitorThreads();
} }
@Override
public void stop() throws Exception { public void stop() throws Exception {
stopMonitorThreads(); stopMonitorThreads();
next.stop(); next.stop();
@ -148,8 +155,7 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
return; return;
} }
if (!commandSent.get() && useKeepAlive && monitorStarted.get() && if (!commandSent.get() && useKeepAlive && monitorStarted.get() && !ASYNC_TASKS.isTerminating() && !ASYNC_TASKS.isTerminated()) {
!ASYNC_TASKS.isTerminating() && !ASYNC_TASKS.isTerminated()) {
if (LOG.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOG.trace(this + " no message sent since last write check, sending a KeepAliveInfo"); LOG.trace(this + " no message sent since last write check, sending a KeepAliveInfo");
@ -157,13 +163,15 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
try { try {
ASYNC_TASKS.execute(new Runnable() { ASYNC_TASKS.execute(new Runnable() {
@Override
public void run() { public void run() {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Running {}", this); LOG.debug("Running {}", this);
} }
if (monitorStarted.get()) { if (monitorStarted.get()) {
try { try {
// If we can't get the lock it means another write beat us into the // If we can't get the lock it means another
// write beat us into the
// send and we don't need to heart beat now. // send and we don't need to heart beat now.
if (sendLock.writeLock().tryLock()) { if (sendLock.writeLock().tryLock()) {
KeepAliveInfo info = new KeepAliveInfo(); KeepAliveInfo info = new KeepAliveInfo();
@ -209,8 +217,7 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
} }
return; return;
} }
if (!commandReceived.get() && monitorStarted.get() && if (!commandReceived.get() && monitorStarted.get() && !ASYNC_TASKS.isTerminating() && !ASYNC_TASKS.isTerminated()) {
!ASYNC_TASKS.isTerminating() && !ASYNC_TASKS.isTerminated()) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("No message received since last read check for " + toString() + ". Throwing InactivityIOException."); LOG.debug("No message received since last read check for " + toString() + ". Throwing InactivityIOException.");
@ -218,6 +225,7 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
try { try {
ASYNC_TASKS.execute(new Runnable() { ASYNC_TASKS.execute(new Runnable() {
@Override
public void run() { public void run() {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Running {}", this); LOG.debug("Running {}", this);
@ -245,8 +253,10 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
} }
protected abstract void processInboundWireFormatInfo(WireFormatInfo info) throws IOException; protected abstract void processInboundWireFormatInfo(WireFormatInfo info) throws IOException;
protected abstract void processOutboundWireFormatInfo(WireFormatInfo info) throws IOException; protected abstract void processOutboundWireFormatInfo(WireFormatInfo info) throws IOException;
@Override
public void onCommand(Object command) { public void onCommand(Object command) {
commandReceived.set(true); commandReceived.set(true);
inReceive.set(true); inReceive.set(true);
@ -282,6 +292,7 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
} }
} }
@Override
public void oneway(Object o) throws IOException { public void oneway(Object o) throws IOException {
// To prevent the inactivity monitor from sending a message while we // To prevent the inactivity monitor from sending a message while we
// are performing a send we take a read lock. The inactivity monitor // are performing a send we take a read lock. The inactivity monitor
@ -311,9 +322,13 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
next.oneway(command); next.oneway(command);
} }
@Override
public void onException(IOException error) { public void onException(IOException error) {
if (failed.compareAndSet(false, true)) { if (failed.compareAndSet(false, true)) {
stopMonitorThreads(); stopMonitorThreads();
if (sendLock.writeLock().isHeldByCurrentThread()) {
sendLock.writeLock().unlock();
}
transportListener.onException(error); transportListener.onException(error);
} }
} }
@ -419,7 +434,8 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
} }
} }
private ThreadFactory factory = new ThreadFactory() { private final ThreadFactory factory = new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) { public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable, "ActiveMQ InactivityMonitor Worker"); Thread thread = new Thread(runnable, "ActiveMQ InactivityMonitor Worker");
thread.setDaemon(true); thread.setDaemon(true);