public void processRoute(final ServerMessage message, final RoutingContext context, final boolean direct) throws Exception
{
final List<MessageReference> refs = new ArrayList<MessageReference>();
Transaction tx = context.getTransaction();
for (Map.Entry<SimpleString, RouteContextList> entry : context.getContexListing().entrySet())
{
PagingStore store = pagingManager.getPageStore(entry.getKey());
if (storageManager.addToPage(store, message, context.getTransaction(), entry.getValue()))
{
if (message.isLargeMessage())
{
confirmLargeMessageSend(tx, message);
}
// We need to kick delivery so the Queues may check for the cursors case they are empty
schedulePageDelivery(tx, entry);
continue;
}
for (Queue queue : entry.getValue().getNonDurableQueues())
{
MessageReference reference = message.createReference(queue);
refs.add(reference);
if (message.containsProperty(Message.HDR_SCHEDULED_DELIVERY_TIME))
{
Long scheduledDeliveryTime = message.getLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME);
reference.setScheduledDeliveryTime(scheduledDeliveryTime);
}
message.incrementRefCount();
}
Iterator<Queue> iter = entry.getValue().getDurableQueues().iterator();
while (iter.hasNext())
{
Queue queue = iter.next();
MessageReference reference = message.createReference(queue);
refs.add(reference);
if (message.containsProperty(Message.HDR_SCHEDULED_DELIVERY_TIME))
{
Long scheduledDeliveryTime = message.getLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME);
reference.setScheduledDeliveryTime(scheduledDeliveryTime);
}
if (message.isDurable())
{
int durableRefCount = message.incrementDurableRefCount();
if (durableRefCount == 1)
{
if (tx != null)
{
storageManager.storeMessageTransactional(tx.getID(), message);
}
else
{
storageManager.storeMessage(message);
}
if (message.isLargeMessage())
{
confirmLargeMessageSend(tx, message);
}
}
if (tx != null)
{
storageManager.storeReferenceTransactional(tx.getID(), queue.getID(), message.getMessageID());
tx.setContainsPersistent();
}
else
{
storageManager.storeReference(queue.getID(), message.getMessageID(), !iter.hasNext());
}
if (message.containsProperty(Message.HDR_SCHEDULED_DELIVERY_TIME))
{
if (tx != null)
{
storageManager.updateScheduledDeliveryTimeTransactional(tx.getID(), reference);
}
else
{
storageManager.updateScheduledDeliveryTime(reference);
}
}
}
message.incrementRefCount();
}
}
if (tx != null)
{
tx.addOperation(new AddOperation(refs));
}
else
{
// This will use the same thread if there are no pending operations
// avoiding a context switch on this case