/**
* @see org.apache.activemq.thread.Task#iterate()
*/
public boolean iterate() {
final TransportListener tl;
try {
// Disable changing the state variables while we are running...
enqueueValve.increment();
tl = transportListener;
if (!started || disposed || tl == null || stopping.get()) {
if( stopping.get() ) {
// drain the queue it since folks could be blocked putting on to
// it and that would not allow the stop() method for finishing up.
getMessageQueue().clear();
}
return false;
}
} catch (InterruptedException e) {
return false;
} finally {
enqueueValve.decrement();
}
LinkedBlockingQueue<Object> mq = getMessageQueue();
Object command = mq.poll();
if (command != null) {
if( command == DISCONNECT ) {
tl.onException(new TransportDisposedIOException("Peer (" + peer.toString() + ") disposed."));
} else {
tl.onCommand(command);
}
return !mq.isEmpty();
} else {
return false;
}