int localConsumersCount = consumersSnapshot.size();
int currentOffset = consumerOffset++; // Copy current offset (value is volatile and should not change during the following loop)
for (int n = 0 ; n < localConsumersCount ; n++)
{
int offset = ((n+currentOffset) % localConsumersCount);
LocalMessageConsumer consumer = (LocalMessageConsumer)consumersSnapshot.get(offset);
// Check that the consumer connection is started
if (!consumer.getSession().getConnection().isStarted())
continue;
// Check message selector
if (message != null)
{
MessageSelector consumerSelector = consumer.getReceiveSelector();
if (consumerSelector != null)
{
message.ensureDeserializationLevel(MessageSerializationLevel.ALL_HEADERS);
try
{
if (!consumerSelector.matches(message))
continue;
}
catch (JMSException e)
{
ErrorTools.log(e, log);
consumer.getSession().getConnection().exceptionOccured(e);
break;
}
}
}
try
{
if (consumer.mayBlock())
engine.getDeliveryAsyncTaskManager().execute(consumer);
else
consumer.messageAvailable();
break;
}
catch (JMSException e)
{
ErrorTools.log(e, log);
consumer.getSession().getConnection().exceptionOccured(e);
}
}
}