From 4ae5e7d0ffc67c605c9eef8fbfbcffc1e2d7095a Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 14 Aug 2008 19:53:36 +0000 Subject: [PATCH] Removed FTPClientPool for now since the QueuedFTPClientPool was expecting an interface. --- .../adapter/ftp/FTPClientPool.java | 98 ------------------- .../adapter/ftp/QueuedFTPClientPool.java | 33 ++++--- 2 files changed, 19 insertions(+), 112 deletions(-) delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FTPClientPool.java diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FTPClientPool.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FTPClientPool.java deleted file mode 100644 index ca93f7f4bd..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FTPClientPool.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.springframework.integration.adapter.ftp; - -import java.io.IOException; -import java.net.SocketException; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Queue; -import java.util.Set; -import java.util.Stack; -import java.util.concurrent.ArrayBlockingQueue; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.commons.net.ftp.FTP; -import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPClientConfig; - -public class FTPClientPool { - - private static final int DEFAULT_POOL_SIZE = 5; - - private final Queue pool; - - private FTPClientConfig config; - - private String host; - - private int port = FTP.DEFAULT_PORT; - - private String user; - - private String pass; - - private FTPClientFactory factory = new DefaultFactory(); - - private final Log log = LogFactory.getLog(this.getClass()); - - public FTPClientPool() { - this(DEFAULT_POOL_SIZE); - } - - public FTPClientPool(int maxPoolSize) { - pool = new ArrayBlockingQueue(maxPoolSize); - } - - public synchronized FTPClient getClient() throws SocketException, IOException { - return pool.isEmpty() ? factory.getClient() : pool.element(); - } - - public synchronized void releaseClient(FTPClient client) { - if (client != null) { - if (!pool.offer(client)) { - try { - client.disconnect(); - } - catch (IOException e) { - log.warn("Error disconnecting ftpclient", e); - } - } - } - } - - private class DefaultFactory implements FTPClientFactory { - - public FTPClient getClient() throws SocketException, IOException { - FTPClient client = new FTPClient(); - client.configure(config); - client.connect(host, port); - client.login(user, pass); - return client; - } - } - - public void setConfig(FTPClientConfig config) { - this.config = config; - } - - public void setHost(String host) { - this.host = host; - } - - public void setPort(int port) { - this.port = port; - } - - public void setUser(String user) { - this.user = user; - } - - public void setPass(String pass) { - this.pass = pass; - } - - public void setFactory(FTPClientFactory factory) { - this.factory = factory; - } -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPool.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPool.java index 5453257cf9..e57e556fb6 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPool.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPool.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.adapter.ftp; import java.io.IOException; @@ -25,6 +26,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClientConfig; + import org.springframework.util.Assert; /** @@ -32,9 +34,8 @@ import org.springframework.util.Assert; * default pool size of 5, but this is configurable with a constructor argument. * * @author Iwein Fuld - * */ -public class QueuedFTPClientPool implements FTPClientPool { +public class QueuedFTPClientPool { private static final int DEFAULT_POOL_SIZE = 5; @@ -54,10 +55,12 @@ public class QueuedFTPClientPool implements FTPClientPool { private final Log log = LogFactory.getLog(this.getClass()); + public QueuedFTPClientPool() { this(DEFAULT_POOL_SIZE); } + /** * @param maxPoolSize the maximum size of the pool */ @@ -82,17 +85,6 @@ public class QueuedFTPClientPool implements FTPClientPool { } } - private class DefaultFactory implements FTPClientFactory { - - public FTPClient getClient() throws SocketException, IOException { - FTPClient client = new FTPClient(); - client.configure(config); - client.connect(host, port); - client.login(user, pass); - return client; - } - } - public void setConfig(FTPClientConfig config) { Assert.notNull(config); this.config = config; @@ -104,7 +96,7 @@ public class QueuedFTPClientPool implements FTPClientPool { } public void setPort(int port) { - Assert.isTrue(port != 0, "Port number should be > 0"); + Assert.isTrue(port > 0, "Port number should be > 0"); this.port = port; } @@ -122,4 +114,17 @@ public class QueuedFTPClientPool implements FTPClientPool { Assert.notNull(factory); this.factory = factory; } + + + private class DefaultFactory implements FTPClientFactory { + + public FTPClient getClient() throws SocketException, IOException { + FTPClient client = new FTPClient(); + client.configure(config); + client.connect(host, port); + client.login(user, pass); + return client; + } + } + }