use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueImpl method sendMessagesToDeadLetterAddress.
@Override
public synchronized int sendMessagesToDeadLetterAddress(Filter filter) throws Exception {
int count = 0;
try (LinkedListIterator<MessageReference> iter = iterator()) {
while (iter.hasNext()) {
MessageReference ref = iter.next();
if (filter == null || filter.match(ref.getMessage())) {
incDelivering(ref);
sendToDeadLetterAddress(null, ref);
iter.remove();
refRemoved(ref);
count++;
}
}
return count;
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueImpl method iterQueue.
/**
* This is a generic method for any method interacting on the Queue to move or delete messages
* Instead of duplicate the feature we created an abstract class where you pass the logic for
* each message.
*
* @param filter1
* @param messageAction
* @return
* @throws Exception
*/
private synchronized int iterQueue(final int flushLimit, final Filter filter1, QueueIterateAction messageAction) throws Exception {
int count = 0;
int txCount = 0;
Transaction tx = new TransactionImpl(storageManager);
try (LinkedListIterator<MessageReference> iter = iterator()) {
while (iter.hasNext()) {
MessageReference ref = iter.next();
if (ref.isPaged() && queueDestroyed) {
// page cleanup
continue;
}
if (filter1 == null || filter1.match(ref.getMessage())) {
messageAction.actMessage(tx, ref);
iter.remove();
txCount++;
count++;
}
}
if (txCount > 0) {
tx.commit();
tx = new TransactionImpl(storageManager);
txCount = 0;
}
List<MessageReference> cancelled = scheduledDeliveryHandler.cancel(filter1);
for (MessageReference messageReference : cancelled) {
messageAction.actMessage(tx, messageReference);
count++;
txCount++;
}
if (txCount > 0) {
tx.commit();
tx = new TransactionImpl(storageManager);
txCount = 0;
}
if (pageIterator != null && !queueDestroyed) {
while (pageIterator.hasNext()) {
PagedReference reference = pageIterator.next();
pageIterator.remove();
if (filter1 == null || filter1.match(reference.getMessage())) {
count++;
txCount++;
messageAction.actMessage(tx, reference, false);
} else {
addTail(reference, false);
}
if (txCount > 0 && txCount % flushLimit == 0) {
tx.commit();
tx = new TransactionImpl(storageManager);
txCount = 0;
}
}
}
if (txCount > 0) {
tx.commit();
tx = null;
}
if (filter != null && !queueDestroyed && pageSubscription != null) {
scheduleDepage(false);
}
return count;
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueImpl method addHead.
/* Called when a message is cancelled back into the queue */
@Override
public void addHead(final List<MessageReference> refs, boolean scheduling) {
enterCritical(CRITICAL_PATH_ADD_HEAD);
synchronized (this) {
try {
for (MessageReference ref : refs) {
addHead(ref, scheduling);
}
resetAllIterators();
deliverAsync();
} finally {
leaveCritical(CRITICAL_PATH_ADD_HEAD);
}
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueImpl method expireReferences.
@Override
public synchronized int expireReferences(final Filter filter) throws Exception {
if (isExpirationRedundant()) {
return 0;
}
Transaction tx = new TransactionImpl(storageManager);
int count = 0;
try (LinkedListIterator<MessageReference> iter = iterator()) {
while (iter.hasNext()) {
MessageReference ref = iter.next();
if (filter == null || filter.match(ref.getMessage())) {
incDelivering(ref);
expire(tx, ref);
iter.remove();
refRemoved(ref);
count++;
}
}
tx.commit();
return count;
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueImpl method moveReference.
@Override
public synchronized boolean moveReference(final long messageID, final SimpleString toAddress, final Binding binding, final boolean rejectDuplicate) throws Exception {
try (LinkedListIterator<MessageReference> iter = iterator()) {
while (iter.hasNext()) {
MessageReference ref = iter.next();
if (ref.getMessage().getMessageID() == messageID) {
iter.remove();
refRemoved(ref);
incDelivering(ref);
try {
move(null, toAddress, binding, ref, rejectDuplicate, AckReason.NORMAL);
} catch (Exception e) {
decDelivering(ref);
throw e;
}
return true;
}
}
return false;
}
}
Aggregations