return result;
}
private MessageImpl doReceive(long consumerId, final Condition wait)
throws JMSException {
ConsumerEndpoint consumer = getConsumer(consumerId);
Condition cancel;
if (wait != null) {
cancel = new Condition() {
public boolean get() {
return _stop.get() || !wait.get();
}
};
} 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);