Author: imario Date: Mon Jul 4 12:28:21 2005 New Revision: 209116 URL: http://svn.apache.org/viewcvs?rev=209116&view=rev Log: fixed race condition and wrong use of mini-pool. Now if one gets a "connection refused" exception it might be e.g. xinetd.conf which allows to limit the connections-per-second (cps)
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java?rev=209116&r1=209115&r2=209116&view=diff ============================================================================== --- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java (original) +++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpFileSystem.java Mon Jul 4 12:28:21 2005 @@ -46,6 +46,7 @@ // An idle client private FtpClient idleClient; + private Object idleClientSync = new Object(); protected FtpFileSystem(final GenericFileName rootName, final FtpClient ftpClient, final FileSystemOptions fileSystemOptions) { @@ -99,26 +100,29 @@ */ public FtpClient getClient() throws FileSystemException { - if (idleClient == null || !idleClient.isConnected()) + synchronized(idleClientSync) { - idleClient = new FTPClientWrapper((GenericFileName) getRoot().getName(), getFileSystemOptions()); - return idleClient; - /* - final GenericFileName rootName = (GenericFileName) getRoot().getName(); - - return FtpClientFactory.createConnection(rootName.getHostName(), - rootName.getPort(), - rootName.getUserName(), - rootName.getPassword(), - rootName.getPath(), - getFileSystemOptions()); - */ - } - else - { - final FtpClient client = idleClient; - idleClient = null; - return client; + if (idleClient == null || !idleClient.isConnected()) + { + FtpClient ftpClient = new FTPClientWrapper((GenericFileName) getRoot().getName(), getFileSystemOptions()); + return ftpClient; + /* + final GenericFileName rootName = (GenericFileName) getRoot().getName(); + + return FtpClientFactory.createConnection(rootName.getHostName(), + rootName.getPort(), + rootName.getUserName(), + rootName.getPassword(), + rootName.getPath(), + getFileSystemOptions()); + */ + } + else + { + final FtpClient client = idleClient; + idleClient = null; + return client; + } } } @@ -127,15 +131,18 @@ */ public void putClient(final FtpClient client) { - if (idleClient == null) + synchronized(idleClientSync) { - // Hang on to client for later - idleClient = client; - } - else - { - // Close the client - closeConnection(client); + if (idleClient == null) + { + // Hang on to client for later + idleClient = client; + } + else + { + // Close the client + closeConnection(client); + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]