_totalMessagesReceived.incrementAndGet();
QueueEntry entry;
final Subscription exclusiveSub = _exclusiveSubscriber;
entry = _entries.add(message);
if(action != null || (exclusiveSub == null && _queueRunner.isIdle()))
{
/*
iterate over subscriptions and if any is at the end of the queue and can deliver this message, then deliver the message
*/
SubscriptionList.SubscriptionNode node = _subscriptionList.getMarkedNode();
SubscriptionList.SubscriptionNode nextNode = node.findNext();
if (nextNode == null)
{
nextNode = _subscriptionList.getHead().findNext();
}
while (nextNode != null)
{
if (_subscriptionList.updateMarkedNode(node, nextNode))
{
break;
}
else
{
node = _subscriptionList.getMarkedNode();
nextNode = node.findNext();
if (nextNode == null)
{
nextNode = _subscriptionList.getHead().findNext();
}
}
}
// always do one extra loop after we believe we've finished
// this catches the case where we *just* miss an update
int loops = 2;
while (entry.isAvailable() && loops != 0)
{
if (nextNode == null)
{
loops--;
nextNode = _subscriptionList.getHead();
}
else
{
// if subscription at end, and active, offer
Subscription sub = nextNode.getSubscription();
deliverToSubscription(sub, entry);
}
nextNode = nextNode.findNext();
}