From commits-return-10995-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Mon Jun 08 21:49:24 2009 Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 35867 invoked from network); 8 Jun 2009 21:49:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Jun 2009 21:49:24 -0000 Received: (qmail 74093 invoked by uid 500); 8 Jun 2009 21:49:35 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 74041 invoked by uid 500); 8 Jun 2009 21:49:35 -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 74032 invoked by uid 99); 8 Jun 2009 21:49:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jun 2009 21:49:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Mon, 08 Jun 2009 21:49:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B7A202388896; Mon, 8 Jun 2009 21:49:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r782803 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp: State/SynchronizedObjects.cs Transport/Failover/FailoverTransport.cs Date: Mon, 08 Jun 2009 21:49:09 -0000 To: commits@activemq.apache.org From: jgomes@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090608214909.B7A202388896@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jgomes Date: Mon Jun 8 21:49:09 2009 New Revision: 782803 URL: http://svn.apache.org/viewvc?rev=782803&view=rev Log: Reimplemented the copy constructor for AtomicCollection to work around bug in Mono. Improved locking algorithms to use SyncRoot. Fixed broken Reconnect() call in FailoverTransport.cs when previous code changes were rolled back. The background thread task was longer being started and the reconnect actions would never be performed. Fixes [AMQNET-152]. (See https://issues.apache.org/activemq/browse/AMQNET-152) Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/State/SynchronizedObjects.cs activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/State/SynchronizedObjects.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/State/SynchronizedObjects.cs?rev=782803&r1=782802&r2=782803&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/State/SynchronizedObjects.cs (original) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/State/SynchronizedObjects.cs Mon Jun 8 21:49:09 2009 @@ -24,24 +24,28 @@ public class AtomicCollection where TValue : class { - private Object myLock = new Object(); - private ArrayList _collection; + private ArrayList _collection = new ArrayList(); public AtomicCollection() { - _collection = new ArrayList(); } public AtomicCollection(ICollection c) { - _collection = new ArrayList(c); + lock(c.SyncRoot) + { + foreach(object obj in c) + { + _collection.Add(obj); + } + } } public int Count { get { - lock(myLock) + lock(_collection.SyncRoot) { return _collection.Count; } @@ -58,7 +62,7 @@ public int Add(TValue v) { - lock(myLock) + lock(_collection.SyncRoot) { return _collection.Add(v); } @@ -66,7 +70,7 @@ public void Clear() { - lock(myLock) + lock(_collection.SyncRoot) { _collection.Clear(); } @@ -74,7 +78,7 @@ public bool Contains(TValue v) { - lock(myLock) + lock(_collection.SyncRoot) { return _collection.Contains(v); } @@ -82,7 +86,7 @@ public void CopyTo(TValue[] a, int index) { - lock(myLock) + lock(_collection.SyncRoot) { _collection.CopyTo(a, index); } @@ -90,7 +94,7 @@ public void Remove(TValue v) { - lock(myLock) + lock(_collection.SyncRoot) { _collection.Remove(v); } @@ -98,7 +102,7 @@ public void RemoveAt(int index) { - lock(myLock) + lock(_collection.SyncRoot) { _collection.RemoveAt(index); } @@ -109,7 +113,7 @@ get { TValue ret; - lock(myLock) + lock(_collection.SyncRoot) { ret = (TValue) _collection[index]; } @@ -117,7 +121,7 @@ } set { - lock(myLock) + lock(_collection.SyncRoot) { _collection[index] = value; } @@ -126,7 +130,7 @@ public IEnumerator GetEnumerator() { - lock(myLock) + lock(_collection.SyncRoot) { return _collection.GetEnumerator(); } @@ -135,7 +139,7 @@ #if !NETCF public IEnumerator GetEnumerator(int index, int count) { - lock(myLock) + lock(_collection.SyncRoot) { return _collection.GetEnumerator(index, count); } @@ -147,7 +151,6 @@ where TKey : class where TValue : class { - private Object myLock = new Object(); private Dictionary _dictionary = new Dictionary(); public void Clear() @@ -160,7 +163,7 @@ get { TValue ret; - lock(myLock) + lock(((ICollection) _dictionary).SyncRoot) { ret = _dictionary[key]; } @@ -168,7 +171,7 @@ } set { - lock(myLock) + lock(((ICollection) _dictionary).SyncRoot) { _dictionary[key] = value; } @@ -179,7 +182,7 @@ { get { - lock(myLock) + lock(((ICollection) _dictionary).SyncRoot) { return new AtomicCollection(_dictionary.Keys); } @@ -190,7 +193,7 @@ { get { - lock(myLock) + lock(((ICollection) _dictionary).SyncRoot) { return new AtomicCollection(_dictionary.Values); } @@ -199,7 +202,7 @@ public void Add(TKey k, TValue v) { - lock(myLock) + lock(((ICollection) _dictionary).SyncRoot) { _dictionary.Add(k, v); } @@ -207,7 +210,7 @@ public bool Remove(TKey v) { - lock(myLock) + lock(((ICollection) _dictionary).SyncRoot) { return _dictionary.Remove(v); } Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs?rev=782803&r1=782802&r2=782803&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs (original) +++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs Mon Jun 8 21:49:09 2009 @@ -16,6 +16,7 @@ */ using System; +using System.Collections; using System.Collections.Generic; using System.Threading; using Apache.NMS.ActiveMQ.Commands; @@ -151,7 +152,7 @@ if(command.IsResponse) { Object oo = null; - lock(requestMap) + lock(((ICollection) requestMap).SyncRoot) { int v = ((Response) command).CorrelationId; try @@ -481,8 +482,7 @@ if(transport == null) { - // Previous loop may have exited due to use being - // disposed. + // Previous loop may have exited due to use being disposed. if(disposed) { error = new IOException("Transport disposed."); @@ -499,11 +499,10 @@ } // If it was a request and it was not being tracked by - // the state tracker, - // then hold it in the requestMap so that we can replay - // it later. + // the state tracker, then hold it in the requestMap so + // that we can replay it later. Tracked tracked = stateTracker.track(command); - lock(requestMap) + lock(((ICollection) requestMap).SyncRoot) { if(tracked != null && tracked.WaitingForResponse) { @@ -530,12 +529,14 @@ { // since we will retry in this method.. take it - // out of the request - // map so that it is not sent 2 times on - // recovery + // out of the request map so that it is not + // sent 2 times on recovery if(command.ResponseRequired) { - requestMap.Remove(command.CommandId); + lock(((ICollection) requestMap).SyncRoot) + { + requestMap.Remove(command.CommandId); + } } // Rethrow the exception so it will handled by @@ -699,14 +700,17 @@ protected void restoreTransport(ITransport t) { + Tracer.Info("Restoring previous transport connection."); t.Start(); //send information to the broker - informing it we are an ft client ConnectionControl cc = new ConnectionControl(); cc.FaultTolerant = true; t.Oneway(cc); stateTracker.DoRestore(t); + + Tracer.Info("Sending queued commands..."); Dictionary tmpMap = null; - lock(requestMap) + lock(((ICollection) requestMap).SyncRoot) { tmpMap = new Dictionary(requestMap); } @@ -792,7 +796,7 @@ ConnectedTransportURI = uri; ConnectedTransport = t; connectFailures = 0; - connected = true; + connected = true; Tracer.InfoFormat("Successfully reconnected to backup {0}", uri.ToString()); return false; } @@ -833,6 +837,7 @@ ConnectedTransportURI = uri; ConnectedTransport = t; connectFailures = 0; + connected = true; if(firstConnection) { @@ -844,7 +849,6 @@ Tracer.InfoFormat("Successfully reconnected to: {0}", uri.ToString()); } - connected = true; return false; } catch(Exception e)