use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueImpl method changeReferencePriority.
@Override
public synchronized boolean changeReferencePriority(final long messageID, final byte newPriority) throws Exception {
try (LinkedListIterator<MessageReference> iter = iterator()) {
while (iter.hasNext()) {
MessageReference ref = iter.next();
if (ref.getMessage().getMessageID() == messageID) {
iter.remove();
refRemoved(ref);
ref.getMessage().setPriority(newPriority);
addTail(ref, false);
return true;
}
}
return false;
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueImpl method deliverScheduledMessages.
@Override
public void deliverScheduledMessages() throws ActiveMQException {
List<MessageReference> scheduledMessages = scheduledDeliveryHandler.cancel(null);
if (scheduledMessages != null && scheduledMessages.size() > 0) {
for (MessageReference ref : scheduledMessages) {
ref.getMessage().setScheduledDeliveryTime(ref.getScheduledDeliveryTime());
ref.setScheduledDeliveryTime(0);
}
this.addHead(scheduledMessages, true);
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class ScaleDownHandler method scaleDownRegularMessages.
public long scaleDownRegularMessages(final SimpleString address, final Set<Queue> queues, final ClientSession clientSession, final ClientProducer producer) throws Exception {
logger.debug("Scaling down messages on address " + address);
long messageCount = 0;
final HashMap<Queue, QueuesXRefInnerManager> controls = new HashMap<>();
PagingStore pageStore = pagingManager.getPageStore(address);
Transaction tx = new TransactionImpl(storageManager);
pageStore.disableCleanup();
try {
for (Queue queue : queues) {
controls.put(queue, new QueuesXRefInnerManager(clientSession, queue, pageStore));
}
// compile a list of all the relevant queues and queue iterators for this address
for (Queue loopQueue : queues) {
logger.debug("Scaling down messages on address " + address + " / performing loop on queue " + loopQueue);
try (LinkedListIterator<MessageReference> messagesIterator = loopQueue.browserIterator()) {
while (messagesIterator.hasNext()) {
MessageReference messageReference = messagesIterator.next();
Message message = messageReference.getMessage().copy();
logger.debug("Reading message " + message + " from queue " + loopQueue);
Set<QueuesXRefInnerManager> queuesFound = new HashSet<>();
for (Map.Entry<Queue, QueuesXRefInnerManager> controlEntry : controls.entrySet()) {
if (controlEntry.getKey() == loopQueue) {
// no need to lookup on itself, we just add it
queuesFound.add(controlEntry.getValue());
} else if (controlEntry.getValue().lookup(messageReference)) {
logger.debug("Message existed on queue " + controlEntry.getKey().getID() + " removeID=" + controlEntry.getValue().getQueueID());
queuesFound.add(controlEntry.getValue());
}
}
// get the ID for every queue that contains the message
ByteBuffer buffer = ByteBuffer.allocate(queuesFound.size() * 8);
for (QueuesXRefInnerManager control : queuesFound) {
long queueID = control.getQueueID();
buffer.putLong(queueID);
}
message.putBytesProperty(Message.HDR_ROUTE_TO_IDS.toString(), buffer.array());
if (logger.isDebugEnabled()) {
if (messageReference.isPaged()) {
logger.debug("*********************<<<<< Scaling down pdgmessage " + message);
} else {
logger.debug("*********************<<<<< Scaling down message " + message);
}
}
producer.send(address, message);
messageCount++;
messagesIterator.remove();
// We need to perform the ack / removal after sending, otherwise the message could been removed before the send is finished
for (QueuesXRefInnerManager queueFound : queuesFound) {
ackMessageOnQueue(tx, queueFound.getQueue(), messageReference);
}
}
} catch (NoSuchElementException ignored) {
// this could happen through paging browsing
}
}
tx.commit();
for (QueuesXRefInnerManager controlRemoved : controls.values()) {
controlRemoved.close();
}
return messageCount;
} finally {
pageStore.enableCleanup();
pageStore.getCursorProvider().scheduleCleanup();
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class ScheduledDeliveryHandlerImpl method cancel.
@Override
public List<MessageReference> cancel(final Filter filter) throws ActiveMQException {
List<MessageReference> refs = new ArrayList<>();
synchronized (scheduledReferences) {
Iterator<RefScheduled> iter = scheduledReferences.iterator();
while (iter.hasNext()) {
MessageReference ref = iter.next().getRef();
if (filter == null || filter.match(ref.getMessage())) {
iter.remove();
refs.add(ref);
metrics.decrementMetrics(ref);
}
}
}
return refs;
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class ServerSessionImpl method doRollback.
private void doRollback(final boolean clientFailed, final boolean lastMessageAsDelived, final Transaction theTx) throws Exception {
boolean wasStarted = started;
List<MessageReference> toCancel = new ArrayList<>();
for (ServerConsumer consumer : consumers.values()) {
if (wasStarted) {
consumer.setStarted(false);
}
toCancel.addAll(consumer.cancelRefs(clientFailed, lastMessageAsDelived, theTx));
}
// we add them to a new tx and roll them back as the calling client will assume that this has happened.
if (theTx.getState() == State.ROLLEDBACK) {
Transaction newTX = newTransaction();
cancelAndRollback(clientFailed, newTX, wasStarted, toCancel);
} else {
cancelAndRollback(clientFailed, theTx, wasStarted, toCancel);
}
}
Aggregations