From commits-return-17047-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Fri Sep 16 22:53:07 2011 Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9FF627D57 for ; Fri, 16 Sep 2011 22:53:07 +0000 (UTC) Received: (qmail 49817 invoked by uid 500); 16 Sep 2011 22:53:07 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 49773 invoked by uid 500); 16 Sep 2011 22:53:07 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 49764 invoked by uid 99); 16 Sep 2011 22:53:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Sep 2011 22:53:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Sep 2011 22:53:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3B8E02388847 for ; Fri, 16 Sep 2011 22:52:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1171843 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp: MessageConsumer.cs Util/SimplePriorityMessageDispatchChannel.cs Date: Fri, 16 Sep 2011 22:52:46 -0000 To: commits@activemq.apache.org From: jgomes@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20110916225246.3B8E02388847@eris.apache.org> Author: jgomes Date: Fri Sep 16 22:52:45 2011 New Revision: 1171843 URL: http://svn.apache.org/viewvc?rev=1171843&view=rev Log: Refactor to minimize the amount of time that a lock is kept. This will also stop the potential of a deadlock from occurring while dispatching a message. Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/MessageConsumer.cs activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Util/SimplePriorityMessageDispatchChannel.cs Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/MessageConsumer.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/MessageConsumer.cs?rev=1171843&r1=1171842&r2=1171843&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/MessageConsumer.cs (original) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/MessageConsumer.cs Fri Sep 16 22:52:45 2011 @@ -596,6 +596,7 @@ namespace Apache.NMS.ActiveMQ public virtual void Dispatch(MessageDispatch dispatch) { MessageListener listener = this.listener; + bool dispatchMessage = false; try { @@ -623,47 +624,52 @@ namespace Apache.NMS.ActiveMQ { if(listener != null && this.unconsumedMessages.Running) { - ActiveMQMessage message = CreateActiveMQMessage(dispatch); - - this.BeforeMessageIsConsumed(dispatch); + dispatchMessage = true; + } + else + { + this.unconsumedMessages.Enqueue(dispatch); + } + } + } - try - { - bool expired = (!IgnoreExpiration && message.IsExpired()); + if(dispatchMessage) + { + ActiveMQMessage message = CreateActiveMQMessage(dispatch); - if(!expired) - { - listener(message); - } + this.BeforeMessageIsConsumed(dispatch); - this.AfterMessageIsConsumed(dispatch, expired); - } - catch(Exception e) - { - if(IsAutoAcknowledgeBatch || IsAutoAcknowledgeEach || IsIndividualAcknowledge) - { - // Redeliver the message - } - else - { - // Transacted or Client ack: Deliver the next message. - this.AfterMessageIsConsumed(dispatch, false); - } + try + { + bool expired = (!IgnoreExpiration && message.IsExpired()); - Tracer.Error(this.info.ConsumerId + " Exception while processing message: " + e); + if(!expired) + { + listener(message); + } - // If aborted we stop the abort here and let normal processing resume. - // This allows the session to shutdown normally and ack all messages - // that have outstanding acks in this consumer. - if( (Thread.CurrentThread.ThreadState & ThreadState.AbortRequested) == ThreadState.AbortRequested) - { - Thread.ResetAbort(); - } - } + this.AfterMessageIsConsumed(dispatch, expired); + } + catch(Exception e) + { + if(IsAutoAcknowledgeBatch || IsAutoAcknowledgeEach || IsIndividualAcknowledge) + { + // Redeliver the message } else { - this.unconsumedMessages.Enqueue(dispatch); + // Transacted or Client ack: Deliver the next message. + this.AfterMessageIsConsumed(dispatch, false); + } + + Tracer.Error(this.info.ConsumerId + " Exception while processing message: " + e); + + // If aborted we stop the abort here and let normal processing resume. + // This allows the session to shutdown normally and ack all messages + // that have outstanding acks in this consumer. + if((Thread.CurrentThread.ThreadState & ThreadState.AbortRequested) == ThreadState.AbortRequested) + { + Thread.ResetAbort(); } } } Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Util/SimplePriorityMessageDispatchChannel.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Util/SimplePriorityMessageDispatchChannel.cs?rev=1171843&r1=1171842&r2=1171843&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Util/SimplePriorityMessageDispatchChannel.cs (original) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Util/SimplePriorityMessageDispatchChannel.cs Fri Sep 16 22:52:45 2011 @@ -51,10 +51,7 @@ namespace Apache.NMS.ActiveMQ.Util { get { - lock(this.mutex) - { - return this.closed; - } + return this.closed; } set @@ -70,10 +67,7 @@ namespace Apache.NMS.ActiveMQ.Util { get { - lock(this.mutex) - { - return this.running; - } + return this.running; } set @@ -89,10 +83,7 @@ namespace Apache.NMS.ActiveMQ.Util { get { - lock(mutex) - { - return this.size == 0; - } + return this.size == 0; } } @@ -100,10 +91,7 @@ namespace Apache.NMS.ActiveMQ.Util { get { - lock(mutex) - { - return this.size; - } + return this.size; } }