Skip to content

Commit 03f3cf9

Browse files
committed
Refactored pooling of FTP clients
1 parent ee1c45d commit 03f3cf9

File tree

20 files changed

+1013
-793
lines changed

20 files changed

+1013
-793
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,18 @@ The `ftp-fs` library provides subclasses for [FileSystemException](https://docs.
6161

6262
## Thread safety
6363

64-
The FTP protocol is fundamentally not thread safe. To overcome this limitation, FTP file systems maintain multiple connections to FTP servers. The number of connections determines the number of concurrent operations that can be executed. If all connections are busy, a new operation will block until a connection becomes available. Class [FTPEnvironment](https://robtimus.github.io/ftp-fs/apidocs/com/github/robtimus/filesystems/ftp/FTPEnvironment.html) has method [withClientConnectionCount](https://robtimus.github.io/ftp-fs/apidocs/com/github/robtimus/filesystems/ftp/FTPEnvironment.html#withClientConnectionCount-int-) that allows you to specify the number of connections to use. If no connection count is explicitly set, the default will be `5`. It also has method [withClientConnectionWaitTimeout](https://robtimus.github.io/ftp-fs/apidocs/com/github/robtimus/filesystems/ftp/FTPEnvironment.html#withClientConnectionWaitTimeout-long-) that can be used to control how long to wait before a connection is available. The default is `0` which means wait indefinitely.
64+
The FTP protocol is fundamentally not thread safe. To overcome this limitation, FTP file systems maintain multiple connections to FTP servers. The number of connections determines the number of concurrent operations that can be executed. If all connections are busy, a new operation will block until a connection becomes available. Class [FTPEnvironment](https://robtimus.github.io/ftp-fs/apidocs/com/github/robtimus/filesystems/ftp/FTPEnvironment.html) has method [withPoolConfig](https://robtimus.github.io/ftp-fs/apidocs/com/github/robtimus/filesystems/ftp/FTPEnvironment.html#withPoolConfig-com.github.robtimus.filesystems.ftp.FTPPoolConfig-) that allows you to configure the connection pool:
65+
66+
* The initial pool size - the number of connections that are created when an FTP file system is created. The default is `1`.
67+
* The maximum pool size - the maximum number of concurrent operations. The default is `5`.
68+
* The maximum wait time - this determines how long to wait until a connection is available. The default is to wait indefinitely.
69+
* The maximum time that connections can be idle. The default is indefinitely.
6570

6671
When a stream or channel is opened for reading or writing, the connection will block because it will wait for the download or upload to finish. This will not occur until the stream or channel is closed. It is therefore advised to close streams and channels as soon as possible.
6772

6873
## Connection management
6974

70-
Because FTP file systems use multiple connections to an FTP server, it's possible that one or more of these connections become stale. Class [FTPFileSystemProvider](https://robtimus.github.io/ftp-fs/apidocs/com/github/robtimus/filesystems/ftp/FTPFileSystemProvider.html) has static method [keepAlive](https://robtimus.github.io/ftp-fs/apidocs/com/github/robtimus/filesystems/ftp/FTPFileSystemProvider.html#keepAlive-java.nio.file.FileSystem-) that, if given an instance of an FTP file system, will send a keep-alive signal (NOOP) over each of its idle connections. You should ensure that this method is called on a regular interval.
75+
Because FTP file systems use multiple connections to an FTP server, it's possible that one or more of these connections become stale. Class [FTPFileSystemProvider](https://robtimus.github.io/ftp-fs/apidocs/com/github/robtimus/filesystems/ftp/FTPFileSystemProvider.html) has static method [keepAlive](https://robtimus.github.io/ftp-fs/apidocs/com/github/robtimus/filesystems/ftp/FTPFileSystemProvider.html#keepAlive-java.nio.file.FileSystem-) that, if given an instance of an FTP file system, will send a keep-alive signal (NOOP) over each of its idle connections. You should ensure that this method is called on a regular interval. An alternative is to set a maximum idle time (see [Thread safety](#thread-safety)).
7176

7277
## Limitations
7378

pom.xml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
<parent>
2323
<groupId>com.github.robtimus</groupId>
2424
<artifactId>robtimus-parent</artifactId>
25-
<version>1.4.3</version>
25+
<version>1.5</version>
2626
<relativePath />
2727
</parent>
2828

2929
<artifactId>ftp-fs</artifactId>
30-
<version>2.3-SNAPSHOT</version>
30+
<version>3.0-SNAPSHOT</version>
3131
<packaging>jar</packaging>
3232

3333
<name>ftp-fs</name>
@@ -76,7 +76,9 @@
7676
<properties>
7777
<version.commons-net>3.8.0</version.commons-net>
7878
<version.fs-core>2.0.2</version.fs-core>
79-
<version.MockFtpServer>2.8.0</version.MockFtpServer>
79+
<version.junit-support>2.0</version.junit-support>
80+
<version.MockFtpServer>3.0.0</version.MockFtpServer>
81+
<version.simple-pool>1.0</version.simple-pool>
8082
</properties>
8183

8284
<dependencies>
@@ -93,9 +95,9 @@
9395
</dependency>
9496

9597
<dependency>
96-
<groupId>org.slf4j</groupId>
97-
<artifactId>slf4j-api</artifactId>
98-
<optional>true</optional>
98+
<groupId>com.github.robtimus</groupId>
99+
<artifactId>simple-pool</artifactId>
100+
<version>${version.simple-pool}</version>
99101
</dependency>
100102

101103
<dependency>
@@ -112,7 +114,14 @@
112114

113115
<dependency>
114116
<groupId>org.mockito</groupId>
115-
<artifactId>mockito-core</artifactId>
117+
<artifactId>mockito-inline</artifactId>
118+
<scope>test</scope>
119+
</dependency>
120+
121+
<dependency>
122+
<groupId>com.github.robtimus</groupId>
123+
<artifactId>junit-support</artifactId>
124+
<version>${version.junit-support}</version>
116125
<scope>test</scope>
117126
</dependency>
118127

@@ -126,7 +135,6 @@
126135
<dependency>
127136
<groupId>org.slf4j</groupId>
128137
<artifactId>slf4j-reload4j</artifactId>
129-
<version>${version.slf4j}</version>
130138
<scope>test</scope>
131139
</dependency>
132140
</dependencies>

0 commit comments

Comments
 (0)