Condition routingKey = conditionFactory.createCondition(routingKeyText);
lock.readLock().acquire();
// Need to reference the message
MessageReference ref = null;
try
{
if (message.isReliable())
{
// It will already have been persisted on the sender's side
message.setPersisted(true);
}
ref = ms.reference(message);
// We route on the condition
DefaultClusteredBindings cb = (DefaultClusteredBindings)conditionMap.get(routingKey);
if (cb != null)
{
Collection bindings = cb.getAllBindings();
Iterator iter = bindings.iterator();
while (iter.hasNext())
{
Binding binding = (Binding)iter.next();
if (binding.getNodeID() == this.currentNodeId)
{
boolean handle = true;
if (queueNameNodeIdMap != null)
{
Integer in = (Integer)queueNameNodeIdMap.get(binding.getQueue().getName());
//When there are more than one queues with the same name across the cluster we only
//want to chose one of them
if (in != null)
{
handle = in.intValue() == currentNodeId;
}
}
if (handle)
{
//It's a local binding so we pass the message on to the subscription
LocalClusteredQueue queue = (LocalClusteredQueue)binding.getQueue();
Delivery del = queue.handleFromCluster(ref);
if (trace)
{
log.trace(this.currentNodeId + " queue " + queue.getName() + " handled reference from cluster " + del);
}
}
}
}
}
}
finally
{
if (ref != null)
{
ref.releaseMemoryReference();
}
lock.readLock().release();
}
}