Delegating Session Factory

Version 4.2 introduced the DelegatingSessionFactory, which allows the selection of the actual session factory at runtime. Prior to invoking the FTP endpoint, call setThreadKey() on the factory to associate a key with the current thread. That key is then used to look up the actual session factory to be used. You can clear the key by calling clearThreadKey() after use.

See Context Holder Advice for more information how this factory can be used together with a ContextHolderRequestHandlerAdvice.

When you use session caching (see FTP Session Caching), each of the delegates should be cached. You cannot cache the DelegatingSessionFactory itself.

Starting with version 5.0.7, the DelegatingSessionFactory can be used in conjunction with a RotatingServerAdvice to poll multiple servers; see Inbound Channel Adapters: Polling Multiple Servers and Directories.