return queued;
}
private boolean send(ConsumerEndpoint consumer, Condition cancel) {
boolean sent = false;
MessageHandle handle = null;
try {
_database.begin();
try {
synchronized (_removeLock) {
_consumerId = consumer.getId();
}
handle = consumer.receive(cancel);
if (handle != null) {
MessageImpl message = handle.getMessage();
if (message != null) {
// send the client a copy.
message = copy(message, handle);
// clear any wait condition
// @todo - possible race condition? Could
// syncbronous client timeout and request again,
// and this trash subsequent wait?
consumer.setWaitingForMessage(null);
_sent.preSend(handle);
_database.commit();
// send the message
sent = send(message);
if (sent) {
_database.begin();
_sent.postSend(handle);
_database.commit();
}
}
} else {
_database.commit();
}
} finally {
synchronized (_removeLock) {
_consumerId = -1;
_removeLock.notify();
}
}
} catch (Exception exception) {
cleanup(exception.getMessage(), exception);
}
if (!sent && handle != null) {
try {
_database.begin();
handle.release();
_database.commit();
} catch (Exception exception) {
cleanup("Failed to release unsent message", exception);
}
}