};
} else {
cancel = _stop;
}
MessageImpl message = null;
try {
_database.begin();
MessageHandle handle = consumer.receive(cancel);
if (handle != null) {
// retrieve the message and copy it
message = handle.getMessage();
if (message != null) {
message = copy(message, handle);
}
}
if (message == null) {
// no message available. Mark the consumer as (possibly) waiting
// for a message.
consumer.setWaitingForMessage(wait);
} else {
// clear any wait condition
consumer.setWaitingForMessage(null);
// if we have a non-null message then add it to the sent message
// cache. Additionally, if we are part of a global transaction
// then we must also send it to the ResourceManager for recovery.
_sent.preSend(handle);
}
_database.commit();
} catch (Exception exception) {
rethrow(exception.getMessage(), exception);
}
if (_log.isDebugEnabled()) {
if (message != null) {
_log.debug("doReceive(consumerId=" + consumerId +
") -> JMSMesssageID=" + message.getMessageId());
}
}
return message;
}