public Message getMessage() throws IOException { if (!dropped && !loaded) { loaded = true; messageReference.incrementReferenceCount(); message = messageReference.getMessage(); if (message == null) { messageReference.decrementReferenceCount(); dropped = true; loaded = false; } } return message; }
public DispatchedNode(final MessageReference node) { super(); this.size = node.getSize(); this.messageId = node.getMessageId(); this.destination = node.getRegionDestination() instanceof Destination ? ((Destination)node.getRegionDestination()) : null; }
public void add(MessageReference node) { int delta = node.getMessageHardRef().getSize(); synchronized (lock) { list.add(node); size += delta; while (size > maximumSize) { MessageReference evicted = list.removeFirst(); size -= evicted.getMessageHardRef().getSize(); } } }
protected int getPriority(MessageReference message) { int priority = javax.jms.Message.DEFAULT_PRIORITY; if (message.getMessageId() != null) { priority = Math.max(message.getMessage().getPriority(), 0); priority = Math.min(priority, 9); } return priority; }
if (!node.isExpired()) { try { regionDestination = (Destination) node.getMessage().getRegionDestination(); if (isDiskListEmpty()) { if (hasSpace()) { memoryList.addMessageFirst(node); node.incrementReferenceCount(); setCacheEnabled(true); return; if (hasSpace()) { memoryList.addMessageFirst(node); node.incrementReferenceCount(); return; } else { node.decrementReferenceCount(); ByteSequence bs = getByteSequence(node.getMessage()); Object locator = getDiskList().addFirst(node.getMessageId().toString(), bs); node.getMessageId().setPlistLocator(locator);
@Override public boolean sendToDeadLetterQueue(ConnectionContext context, MessageReference messageReference, Subscription subscription, Throwable poisonCause) { if (messageReference.isExpired() || (poisonCause != null && poisonCause.getMessage() != null && poisonCause.getMessage().contains(DUPLICATE_FROM_STORE_MSG_PREFIX))) { Destination regionDestination = (Destination) messageReference.getRegionDestination(); final RedeliveryPolicy redeliveryPolicy = redeliveryPolicyMap.getEntryFor(regionDestination.getActiveMQDestination()); if (redeliveryPolicy != null) { final int maximumRedeliveries = redeliveryPolicy.getMaximumRedeliveries(); int redeliveryCount = messageReference.getRedeliveryCounter(); if (RedeliveryPolicy.NO_MAXIMUM_REDELIVERIES == maximumRedeliveries || redeliveryCount < maximumRedeliveries) { return super.sendToDeadLetterQueue(context, messageReference, subscription, poisonCause); } else { LOG.debug("Discarding message that exceeds max redelivery count({}), {}", maximumRedeliveries, messageReference.getMessageId()); LOG.debug("Ignoring dlq request for: {}, RedeliveryPolicy not found (and no fallback) for: {}", messageReference.getMessageId(), regionDestination.getActiveMQDestination()); } catch (Exception exception) { RuntimeException toThrow = new RuntimeException("Failed to schedule redelivery for: " + messageReference.getMessageId(), exception); LOG.error(toThrow.toString(), exception); throw toThrow;
@Override public boolean sendToDeadLetterQueue(ConnectionContext context, MessageReference messageReference, Subscription subscription, Throwable poisonCause) { boolean wasDLQd = super.sendToDeadLetterQueue(context, messageReference, subscription, poisonCause); if (wasDLQd) { try { if (!messageReference.isAdvisory()) { BaseDestination baseDestination = (BaseDestination) messageReference.getMessage().getRegionDestination(); ActiveMQTopic topic = AdvisorySupport.getMessageDLQdAdvisoryTopic(baseDestination.getActiveMQDestination()); Message payload = messageReference.getMessage().copy(); if (!baseDestination.isIncludeBodyForAdvisory()) { payload.clearBody(); } fireAdvisory(context, topic, payload); } } catch (Exception e) { handleFireFailure("add to DLQ", e); } } return wasDLQd; }
private void dispatch(final MessageReference node) throws IOException { Message message = node != null ? node.getMessage() : null; if (node != null) { node.incrementReferenceCount(); md.setConsumerId(info.getConsumerId()); if (node != null) { md.setDestination(((Destination)node.getRegionDestination()).getActiveMQDestination()); synchronized(dispatchLock) { getSubscriptionStatistics().getDispatched().increment(); if (isUseTopicSubscriptionInflightStats()) { dispatched.add(new DispatchedNode(node)); getSubscriptionStatistics().getInflightMessageSize().addSize(node.getSize()); destination = (Destination)node.getRegionDestination(); } else { if (destination != node.getRegionDestination()) { singleDestination = false; context.getConnection().dispatchSync(md); if (node != null) { Destination regionDestination = (Destination) node.getRegionDestination(); regionDestination.getDestinationStatistics().getDispatched().increment(); regionDestination.getDestinationStatistics().getInflight().increment(); node.decrementReferenceCount();
public Message getMessage() throws IOException { return messageReference != null ? messageReference.getMessage():null; }
/** * @param node * @param message * @return MessageDispatch */ protected MessageDispatch createMessageDispatch(MessageReference node, Message message) { MessageDispatch md = new MessageDispatch(); md.setConsumerId(info.getConsumerId()); if (node == QueueMessageReference.NULL_MESSAGE) { md.setMessage(null); md.setDestination(null); } else { Destination regionDestination = (Destination) node.getRegionDestination(); md.setDestination(regionDestination.getActiveMQDestination()); md.setMessage(message); md.setRedeliveryCounter(node.getRedeliveryCounter()); } return md; }
private void discardExpiredMessage(MessageReference reference) { LOG.debug("Discarding expired message {}", reference); if (reference.isExpired() && broker.isExpired(reference)) { ConnectionContext context = new ConnectionContext(); context.setBroker(broker); ((Destination)reference.getRegionDestination()).messageExpired(context, null, new IndirectMessageReference(reference.getMessage())); } }
@Override protected void acknowledge(ConnectionContext context, MessageAck ack, MessageReference node) throws IOException { this.setTimeOfLastMessageAck(System.currentTimeMillis()); Destination regionDestination = (Destination) node.getRegionDestination(); regionDestination.acknowledge(context, this, ack, node); redeliveredMessages.remove(node.getMessageId()); node.decrementReferenceCount(); ((Destination)node.getRegionDestination()).getDestinationStatistics().getDequeues().increment(); if (info.isNetworkSubscription()) { ((Destination)node.getRegionDestination()).getDestinationStatistics().getForwards().add(ack.getMessageCount()); } }
@Override public synchronized List<MessageReference> remove(ConnectionContext context, Destination destination) throws Exception { List<MessageReference> rc = new ArrayList<MessageReference>(); for (Iterator<MessageReference> iterator = list.iterator(); iterator.hasNext();) { MessageReference r = iterator.next(); if (r.getRegionDestination() == destination) { r.decrementReferenceCount(); rc.add(r); iterator.remove(); } } return rc; }
/** * @return the next pending message */ @Override public synchronized MessageReference next() { last = iter.next(); if (last != null) { last.incrementReferenceCount(); } return last; }
/** * A strategy hook to allow per-message caches to be cleared */ protected void clearMessageCache() { if (loaded) { messageReference.decrementReferenceCount(); } message = null; dropped = false; loaded = false; }
/** * @return the next pending message */ @Override public synchronized MessageReference next() { MessageReference reference = iter.next(); last = reference; if (!isDiskListEmpty()) { // got from disk reference.getMessage().setRegionDestination(regionDestination); reference.getMessage().setMemoryUsage(this.getSystemUsage().getMemoryUsage()); } reference.incrementReferenceCount(); return reference; }
LOG.trace("assigned {} to consumer {}", node.getMessageId(), s.getConsumerInfo().getConsumerId()); iterator.remove(); target = s; if (target == null && node.isDropped()) { iterator.remove();
/** * @return true if there are no pending messages */ @Override public synchronized boolean isEmpty() { if (list.isEmpty()) { return true; } else { for (Iterator<MessageReference> iterator = list.iterator(); iterator.hasNext();) { MessageReference node = iterator.next(); if (node == QueueMessageReference.NULL_MESSAGE) { continue; } if (!node.isDropped()) { return false; } // We can remove dropped references. iterator.remove(); } return true; } }
@Override public boolean contains(MessageReference message) { if (message != null) { return this.map.containsKey(message.getMessageId()); } return false; }
@Override protected MessageDispatch createMessageDispatch(MessageReference node, Message message) { MessageDispatch md = super.createMessageDispatch(node, message); if (node != QueueMessageReference.NULL_MESSAGE) { node.incrementReferenceCount(); Integer count = redeliveredMessages.get(node.getMessageId()); if (count != null) { md.setRedeliveryCounter(count.intValue()); } } return md; }