Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 57621 invoked from network); 2 Mar 2006 15:56:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 Mar 2006 15:56:55 -0000 Received: (qmail 26863 invoked by uid 500); 2 Mar 2006 15:57:41 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 26840 invoked by uid 500); 2 Mar 2006 15:57:41 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 26828 invoked by uid 99); 2 Mar 2006 15:57:41 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Mar 2006 07:57:41 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 02 Mar 2006 07:57:40 -0800 Received: (qmail 57388 invoked by uid 65534); 2 Mar 2006 15:56:33 -0000 Message-ID: <20060302155632.57372.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r382421 - /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicSubscription.java Date: Thu, 02 Mar 2006 15:56:31 -0000 To: activemq-commits@geronimo.apache.org From: jstrachan@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jstrachan Date: Thu Mar 2 07:56:30 2006 New Revision: 382421 URL: http://svn.apache.org/viewcvs?rev=382421&view=rev Log: added the ability to discard old messages for non-durable topics if a maximum number of pending messages is reached Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicSubscription.java Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicSubscription.java URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicSubscription.java?rev=382421&r1=382420&r2=382421&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicSubscription.java (original) +++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicSubscription.java Thu Mar 2 07:56:30 2006 @@ -42,6 +42,7 @@ final protected UsageManager usageManager; protected int dispatched=0; protected int delivered=0; + private int maximumPendingMessages = 0; public TopicSubscription(Broker broker,ConnectionContext context, ConsumerInfo info, UsageManager usageManager) throws InvalidSelectorException { super(broker,context, info); @@ -50,11 +51,20 @@ public void add(MessageReference node) throws InterruptedException, IOException { node.incrementReferenceCount(); - if( !isFull() && !isSlaveBroker() ) { + if( !isFull() && !isSlaveBroker()) { + // TODO - if we have already dispatched too many messages to this slow consumer + // should we avoid dispatching and just discard old messages as shown below dispatch(node); } else { - synchronized(matched){ - matched.addLast(node); + synchronized (matched) { + matched.addLast(node); + if (maximumPendingMessages > 0) { + // lets discard old messages as we are a slow consumer + while (matched.size() > maximumPendingMessages) { + MessageReference oldMessage = (MessageReference) matched.removeFirst(); + oldMessage.decrementReferenceCount(); + } + } } } } @@ -122,6 +132,18 @@ return delivered; } + public int getMaximumPendingMessages() { + return maximumPendingMessages; + } + + /** + * Sets the maximum number of pending messages that can be matched against this consumer + * before old messages are discarded. + */ + public void setMaximumPendingMessages(int maximumPendingMessages) { + this.maximumPendingMessages = maximumPendingMessages; + } + private boolean isFull() { return dispatched-delivered >= info.getPrefetchSize(); }