public synchronized int moveReferences(final Filter filter,
final SimpleString toAddress,
final boolean rejectDuplicates) throws Exception
{
Transaction tx = new TransactionImpl(storageManager);
int count = 0;
try
{
LinkedListIterator<MessageReference> iter = iterator();
try
{
DuplicateIDCache targetDuplicateCache = postOffice.getDuplicateIDCache(toAddress);
while (iter.hasNext())
{
MessageReference ref = iter.next();
if (filter == null || filter.match(ref.getMessage()))
{
boolean ignored = false;
deliveringCount.incrementAndGet();
count++;
if (rejectDuplicates)
{
byte[] duplicateBytes = ref.getMessage().getDuplicateIDBytes();
if (duplicateBytes != null)
{
if (targetDuplicateCache.contains(duplicateBytes))
{
log.info("Message with duplicate ID " + ref.getMessage().getDuplicateProperty() +
" was already set at " +
toAddress +
". Move from " +
this.address +
" being ignored and message removed from " +
this.address);
acknowledge(tx, ref);
ignored = true;
}
}
}
if (!ignored)
{
move(toAddress, tx, ref, false, rejectDuplicates);
}
iter.remove();
}
}
List<MessageReference> cancelled = scheduledDeliveryHandler.cancel(filter);
for (MessageReference ref : cancelled)
{
byte[] duplicateBytes = ref.getMessage().getDuplicateIDBytes();
if (duplicateBytes != null)
{
if (targetDuplicateCache.contains(duplicateBytes))
{
log.info("Message with duplicate ID " + ref.getMessage().getDuplicateProperty() +
" was already set at " +
toAddress +
". Move from " +
this.address +
" being ignored");
continue;
}
}
deliveringCount.incrementAndGet();
count++;
move(toAddress, tx, ref, false, rejectDuplicates);
acknowledge(tx, ref);
}
tx.commit();
return count;
}
finally
{