INT-3047 SFTP Multiplex Over Single Connection

Enable the use of multiple JSch channels over a
single connection.

JIRA: https://jira.springsource.org/browse/INT-3047

INT-3047: Polishing locks logic

INT-3047 SFTP Reset Cache; Quiesce Shared Sessions

Support resetCache() on the CachingSessionFactory
- reset a shared JSch session so it is reestablished on next use
- immediately close idle sessions
- close in-use sessions as they are returned
- close the channel when an SftpSession is closed and a shared JSch is being used
- physically close a shared JSch session only when the last channel is closed

Polishing

Forgot to save the ftp.xml.

Change CachedSession.epoch to created.

INT-3047 Polishing - PR Comments

- Also add missing docs for `preserve-timestamp`

INT-3047 Polish - PR Comments

Also change epoch to nanoseconds and use a simple != comparison with the
epoch in which a session was created.
This commit is contained in:
Gary Russell
2013-11-07 21:09:33 +02:00
committed by Artem Bilan
parent e128c80c19
commit 7bc4fe2d0b
12 changed files with 649 additions and 19 deletions

View File

@@ -154,6 +154,7 @@ protected void postProcessClientBeforeConnect(T client) throws IOException {
filename-pattern="*.txt"
remote-directory="some/remote/path"
remote-file-separator="/"
preserve-timestamp="true"
local-filename-generator-expression="#this.toUpperCase() + '.a'"
local-filter="myFilter"
local-directory=".">
@@ -172,7 +173,11 @@ protected void postProcessClientBeforeConnect(T client) throws IOException {
that's what it ultimately generates with the transferred file as its payload. So, the root object of the SpEL Evaluation Context
is the original name of the remote file (String).
</para>
<para>
Starting with <emphasis>Spring Integration 3.0</emphasis>, you can specify the <code>preserve-timestamp</code>
attribute (default <code>false</code>); when <code>true</code>, the local file's modified timestamp will be set to the value
retrieved from the server; otherwise it will be set to the current time.
</para>
<para>
Sometimes file filtering based on the simple pattern specified via <code>filename-pattern</code> attribute might not be
sufficient. If this is the case, you can use the <code>filename-regex</code> attribute to specify a Regular Expression
@@ -500,8 +505,8 @@ protected void postProcessClientBeforeConnect(T client) throws IOException {
<section id="ftp-session-caching">
<title>FTP Session Caching</title>
<important>
Starting with version 3.0, sessions are no longer cached by default; the <code>cache-sessions</code> attribute
is no longer supported on endpoints. You must now use a <classname>CachingSessionFactory</classname> (see below) if you
Starting with <emphasis>Spring Integration version 3.0</emphasis>, sessions are no longer cached by default; the <code>cache-sessions</code> attribute
is no longer supported on endpoints. You must use a <classname>CachingSessionFactory</classname> (see below) if you
wish to cache sessions.
</important>
<para>
@@ -532,5 +537,10 @@ protected void postProcessClientBeforeConnect(T client) throws IOException {
<code>sessionCacheSize</code> set to 10 and the <code>sessionWaitTimeout</code> set to 1 second (its value is in millliseconds).
</para>
<para>
Starting with <emphasis>Spring Integration version 3.0</emphasis>, the <classname>CachingConnectionFactory</classname>
provides a <code>resetCache()</code> method. When invoked, all idle sessions are immediately closed and in-use
sessions are closed when they are returned to the cache. New requests for sessions will establish new sessions as necessary.
</para>
</section>
</chapter>

View File

@@ -59,6 +59,27 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/sftp
However, Spring Integration also supports the caching of SFTP
sessions, please see <xref linkend="sftp-session-caching"/> for more information.
</para>
<important>
<para>
JSch supports multiple channels (operations) over a connection to the server. By default,
the Spring Integration session factory uses a separate physical connection for each channel.
Since <emphasis>Spring Integration 3.0</emphasis>, you can configure the session factory
(using a boolean constructor arg - default <code>false</code>) to use a single connection
to the server and create multiple <code>JSch</code> channels on that single connection.
</para>
<para>
When using this feature, you must wrap the session factory in a caching session
factory, as described below, so that the connection is not physically closed when
an operation completes.
</para>
<para>
If the cache is reset, the session is disconnected only when the last channel is closed.
</para>
<para>
The connection will be refreshed if it is found to be disconnected when a new operation
obtains a session.
</para>
</important>
<note>
If you experience connectivity problems and would like to trace Session
creation as well as see which Sessions are polled you may enable it by
@@ -79,6 +100,11 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/sftp
Below you will find all properties that are exposed by the
<classname><ulink url="http://static.springsource.org/spring-integration/api/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.html">DefaultSftpSessionFactory</ulink></classname>.
</para>
<para><emphasis role="bold">isSharedSession (constructor argument)</emphasis></para>
<para>
When true, a single connection will be used and <code>JSch Channels</code> will be multiplexed.
Defaults to false.
</para>
<para><emphasis role="bold">clientVersion</emphasis></para>
<para>
Allows you to set the client version property. It's default
@@ -183,8 +209,8 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/sftp
<section id="sftp-session-caching">
<title>SFTP Session Caching</title>
<important>
Starting with version 3.0, sessions are no longer cached by default; the <code>cache-sessions</code> attribute
is no longer supported on endpoints. You must now use a <classname>CachingSessionFactory</classname> (see below) if you
Starting with <emphasis>Spring Integration version 3.0</emphasis>, sessions are no longer cached by default; the <code>cache-sessions</code> attribute
is no longer supported on endpoints. You must use a <classname>CachingSessionFactory</classname> (see below) if you
wish to cache sessions.
</important>
<para>
@@ -217,6 +243,13 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/sftp
<code>sessionCacheSize</code> set to 10 and the <code>sessionWaitTimeout</code> set to 1 second (its value is in millliseconds).
</para>
<para>
Starting with <emphasis>Spring Integration version 3.0</emphasis>, the <classname>CachingConnectionFactory</classname>
provides a <code>resetCache()</code> method. When invoked, all idle sessions are immediately closed and in-use
sessions are closed when they are returned to the cache. When using <code>isSharedSession=true</code>, the channel is
closed, and the shared session is closed only when the last channel is closed.
New requests for sessions will establish new sessions as necessary.
</para>
</section>
<section id="sftp-inbound">
@@ -230,6 +263,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/sftp
channel="requestChannel"
filename-pattern="*.txt"
remote-directory="/foo/bar"
preserve-timestamp="true"
local-directory="file:target/foo"
auto-create-local-directory="true"
local-filename-generator-expression="#this.toUpperCase() + '.a'"
@@ -252,6 +286,11 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/sftp
that's what it ultimately generates with the transferred file as its payload. So, the root object of the SpEL Evaluation Context
is the original name of the remote file (String).
</para>
<para>
Starting with <emphasis>Spring Integration 3.0</emphasis>, you can specify the <code>preserve-timestamp</code>
attribute (default <code>false</code>); when <code>true</code>, the local file's modified timestamp will be set to the value
retrieved from the server; otherwise it will be set to the current time.
</para>
<para>
Sometimes file filtering based on the simple pattern specified via <code>filename-pattern</code> attribute might not be
sufficient. If this is the case, you can use the <code>filename-regex</code> attribute to specify a Regular Expression

View File

@@ -243,6 +243,16 @@
For more information, see
<xref linkend="ftp-session-caching"/> and <xref linkend="sftp-session-caching"/>.
</para>
<para>
The <classname>CachingConnectionFactory</classname> now provides a new method
<code>resetCache()</code>. This immediately closes idle sessions and causes in-use
sessions to be closed as and when they are returned to the cache.
</para>
<para>
The <classname>DefaultSftpSessionFactory</classname> (in conjunction with a
<classname>CachingSessionFactory</classname>) now supports multiplexing channels over
a single SSH connection (SFTP Only).
</para>
</section>
<section id="3.0-xFTP-ib">
<title>FTP, SFTP and FTPS Inbound Adapters</title>