use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class ManagementNode method enqueue.
@Override
public void enqueue(final ServerMessage message, final Action<? super MessageInstance> action, final MessageEnqueueRecord record) {
@SuppressWarnings("unchecked") MessageConverter<ServerMessage, InternalMessage> converter = (MessageConverter<ServerMessage, InternalMessage>) MessageConverterRegistry.getConverter((message.getClass()), InternalMessage.class);
final InternalMessage msg = converter.convert(message, _addressSpace);
try {
if (action != null) {
action.performAction(new ConsumedMessageInstance(msg));
}
processRequest(msg);
} finally {
converter.dispose(msg);
}
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class AMQChannel method deadLetter.
private void deadLetter(long deliveryTag) {
final UnacknowledgedMessageMap unackedMap = getUnacknowledgedMessageMap();
final MessageConsumerAssociation association = unackedMap.remove(deliveryTag, true);
if (association == null) {
LOGGER.warn("No message found, unable to DLQ delivery tag: " + deliveryTag);
} else {
final MessageInstance messageInstance = association.getMessageInstance();
final ServerMessage msg = messageInstance.getMessage();
int requeues = 0;
if (messageInstance.makeAcquisitionUnstealable(association.getConsumer())) {
requeues = messageInstance.routeToAlternate(new Action<MessageInstance>() {
@Override
public void performAction(final MessageInstance requeueEntry) {
messageWithSubject(ChannelMessages.DEADLETTERMSG(msg.getMessageNumber(), requeueEntry.getOwningResource().getName()));
}
}, null);
}
if (requeues == 0) {
final TransactionLogResource owningResource = messageInstance.getOwningResource();
if (owningResource instanceof Queue) {
final Queue<?> queue = (Queue<?>) owningResource;
final MessageDestination alternateBindingDestination = queue.getAlternateBindingDestination();
if (alternateBindingDestination == null) {
messageWithSubject(ChannelMessages.DISCARDMSG_NOALTEXCH(msg.getMessageNumber(), queue.getName(), msg.getInitialRoutingAddress()));
} else {
messageWithSubject(ChannelMessages.DISCARDMSG_NOROUTE(msg.getMessageNumber(), alternateBindingDestination.getName()));
}
}
}
}
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class ReportRunnerTest method createMockMessageForQueue.
protected ServerMessage createMockMessageForQueue() {
final ServerMessage message = mock(ServerMessage.class);
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(message.getMessageHeader()).thenReturn(header);
when(message.getContent()).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
return message;
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class AbstractQueue method checkMessageStatus.
@Override
public void checkMessageStatus() {
QueueEntryIterator queueListIterator = getEntries().iterator();
final Set<NotificationCheck> perMessageChecks = new HashSet<>();
final Set<NotificationCheck> queueLevelChecks = new HashSet<>();
for (NotificationCheck check : getNotificationChecks()) {
if (check.isMessageSpecific()) {
perMessageChecks.add(check);
} else {
queueLevelChecks.add(check);
}
}
QueueNotificationListener listener = _notificationListener;
final long currentTime = System.currentTimeMillis();
final long thresholdTime = currentTime - getAlertRepeatGap();
while (!_stopped.get() && queueListIterator.advance()) {
final QueueEntry node = queueListIterator.getNode();
// Only process nodes that are not currently deleted and not dequeued
if (!node.isDeleted()) {
// If the node has expired then acquire it
if (node.expired()) {
deleteEntry(node, () -> _queueStatistics.addToExpired(node.getSizeWithHeader()));
} else {
node.checkHeld(currentTime);
// There is a chance that the node could be deleted by
// the time the check actually occurs. So verify we
// can actually get the message to perform the check.
ServerMessage msg = node.getMessage();
if (msg != null) {
try (MessageReference messageReference = msg.newReference()) {
for (NotificationCheck check : perMessageChecks) {
checkForNotification(msg, listener, currentTime, thresholdTime, check);
}
} catch (MessageDeletedException e) {
// Ignore
}
}
}
}
}
for (NotificationCheck check : queueLevelChecks) {
checkForNotification(null, listener, currentTime, thresholdTime, check);
}
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class AbstractQueue method reallocateMessages.
@Override
public void reallocateMessages() {
QueueEntryIterator queueListIterator = getEntries().iterator();
while (!_stopped.get() && queueListIterator.advance()) {
final QueueEntry node = queueListIterator.getNode();
if (!node.isDeleted() && !node.expired()) {
try {
final ServerMessage message = node.getMessage();
final MessageReference messageReference = message.newReference();
try {
message.getStoredMessage().reallocate();
} finally {
messageReference.release();
}
} catch (MessageDeletedException mde) {
// Ignore
}
}
}
}
Aggregations