Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 5562 invoked from network); 23 Nov 2010 00:28:35 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 23 Nov 2010 00:28:35 -0000 Received: (qmail 14221 invoked by uid 500); 23 Nov 2010 00:29:07 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 14135 invoked by uid 500); 23 Nov 2010 00:29:07 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 14127 invoked by uid 99); 23 Nov 2010 00:29:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Nov 2010 00:29:07 +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; Tue, 23 Nov 2010 00:29:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7FED0238897F; Tue, 23 Nov 2010 00:27:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1037953 - in /commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider: AbstractFileSystem.java ftp/FtpFileSystem.java Date: Tue, 23 Nov 2010 00:27:35 -0000 To: commits@commons.apache.org From: rgoers@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101123002735.7FED0238897F@eris.apache.org> Author: rgoers Date: Tue Nov 23 00:27:35 2010 New Revision: 1037953 URL: http://svn.apache.org/viewvc?rev=1037953&view=rev Log: Fix VFS-293 by converting the idle client to an AtomicReference. Make atomic objects final Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystem.java Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java?rev=1037953&r1=1037952&r2=1037953&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java Tue Nov 23 00:27:35 2010 @@ -95,7 +95,7 @@ public abstract class AbstractFileSystem /** * How many fileObjects are handed out */ - private AtomicLong useCount = new AtomicLong(0); + private final AtomicLong useCount = new AtomicLong(0); private FileSystemKey cacheKey; @@ -103,7 +103,7 @@ public abstract class AbstractFileSystem /** * open streams counter for this filesystem */ - private AtomicInteger openStreams = new AtomicInteger(0); + private final AtomicInteger openStreams = new AtomicInteger(0); protected AbstractFileSystem(final FileName rootName, final FileObject parentLayer, Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystem.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystem.java?rev=1037953&r1=1037952&r2=1037953&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystem.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystem.java Tue Nov 23 00:27:35 2010 @@ -29,6 +29,7 @@ import org.apache.commons.vfs2.provider. import java.io.IOException; import java.util.Collection; +import java.util.concurrent.atomic.AtomicReference; /** * An FTP file system. @@ -46,7 +47,7 @@ public class FtpFileSystem extends Abstr // private final String password; // An idle client - private FtpClient idleClient; + private final AtomicReference idleClient = new AtomicReference(); /** * @param rootName The root of the file system. @@ -61,17 +62,17 @@ public class FtpFileSystem extends Abstr // hostname = rootName.getHostName(); // port = rootName.getPort(); - idleClient = ftpClient; + idleClient.set(ftpClient); } @Override protected void doCloseCommunicationLink() { + FtpClient idle = idleClient.getAndSet(null); // Clean up the connection - if (idleClient != null) + if (idle != null) { - closeConnection(idleClient); - idleClient = null; + closeConnection(idle); } } @@ -112,21 +113,14 @@ public class FtpFileSystem extends Abstr */ public FtpClient getClient() throws FileSystemException { - synchronized (this) - { - if (idleClient == null || !idleClient.isConnected()) - { - idleClient = null; - - return new FTPClientWrapper((GenericFileName) getRoot().getName(), getFileSystemOptions()); - } - else - { - final FtpClient client = idleClient; - idleClient = null; - return client; - } - } + FtpClient client = idleClient.getAndSet(null); + + if (client == null || !client.isConnected()) + { + client = new FTPClientWrapper((GenericFileName) getRoot().getName(), getFileSystemOptions()); + } + + return client; } /** @@ -135,21 +129,15 @@ public class FtpFileSystem extends Abstr */ public void putClient(final FtpClient client) { - synchronized (this) - { - if (idleClient == null) - { - // Hang on to client for later - idleClient = client; - } - else - { - // Close the client - closeConnection(client); - } - } + // Save client for reuse if none is idle. + if (!idleClient.compareAndSet(null, client)) + { + // An idle client is already present so close the connection. + closeConnection(client); + } } + /** * Creates a file object. */