org.springframework.integration.ftp
Class QueuedFtpClientPool

java.lang.Object
  extended by org.springframework.integration.ftp.QueuedFtpClientPool
All Implemented Interfaces:
FtpClientFactory, FtpClientPool

public class QueuedFtpClientPool
extends java.lang.Object
implements FtpClientPool

FtpClientPool implementation based on a Queue. This implementation has a default pool size of 5, but this is configurable with a constructor argument.

This implementation pools released clients, but gives no guarantee to the number of clients open at the same time.


Constructor Summary
QueuedFtpClientPool(FtpClientFactory<?> factory)
           
QueuedFtpClientPool(int maxPoolSize, FtpClientFactory<?> factory)
           
 
Method Summary
 org.apache.commons.net.ftp.FTPClient getClient()
          Returns an active FTPClient connected to the configured server.
protected  org.apache.commons.net.ftp.FTPClient prepareClient(org.apache.commons.net.ftp.FTPClient client)
          Prepares the client before it is returned through getClient().
 void releaseClient(org.apache.commons.net.ftp.FTPClient client)
          Releases the client back to the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueuedFtpClientPool

public QueuedFtpClientPool(FtpClientFactory<?> factory)

QueuedFtpClientPool

public QueuedFtpClientPool(int maxPoolSize,
                           FtpClientFactory<?> factory)
Parameters:
maxPoolSize - the maximum size of the pool
Method Detail

getClient

public org.apache.commons.net.ftp.FTPClient getClient()
                                               throws java.net.SocketException,
                                                      java.io.IOException
Returns an active FTPClient connected to the configured server. When no clients are available in the queue a new client is created with the factory.

It is possible that released clients are disconnected by the remote server (@see FTPClient.sendNoOp(). In this case getClient is called recursively to obtain a client that is still alive. For this reason large pools are not recommended in poor networking conditions.

Specified by:
getClient in interface FtpClientFactory
Returns:
Fully configured and connected FTPClient. Never null.
Throws:
java.io.IOException - thrown when a networking IO subsystem error occurs
java.net.SocketException

prepareClient

protected org.apache.commons.net.ftp.FTPClient prepareClient(org.apache.commons.net.ftp.FTPClient client)
                                                      throws java.net.SocketException,
                                                             java.io.IOException
Prepares the client before it is returned through getClient(). The default implementation will check the connection using a noOp and replace the client with a new one if it encounters a problem.

In more exotic environments subclasses can override this method to implement their own preparation strategy.

Parameters:
client - the unprepared client
Returns:
Throws:
java.net.SocketException
java.io.IOException

releaseClient

public void releaseClient(org.apache.commons.net.ftp.FTPClient client)
Description copied from interface: FtpClientPool
Releases the client back to the pool. When calling this method the caller is no longer responsible for the connection. The pool is free to do with it as it sees fit, which means either recycling or disconnecting it most probably.

The caller should NOT disconnect the client before calling this method.

The caller is NOT expected to use the client after calling this method. Doing so can lead to unexpected behavior.

Specified by:
releaseClient in interface FtpClientPool
Parameters:
client - the FTPClient to release. Implementations of this method are recommended to deal gracefully with a null argument, although the endpoint implementations in org.springframework.integration.ftp will never pass in null.