int count = -1;
try {
// first see if the cache is loaded in memory
JmsDestination dest = _destinations.getDestination(queue);
DestinationCache cache = null;
if (dest != null) {
_database.begin();
cache = _destinations.getDestinationCache(dest);
// retrieve the number of handles for the cache, which
// reflects the number of messages
count = cache.getMessageCount();
_database.commit();
}
} catch (Exception exception) {
_log.error("Failed to get message count for queue=" + queue,
exception);