Home > other >  Spring Integration CachingSessionFactory: What does setTestSession(true) do?
Spring Integration CachingSessionFactory: What does setTestSession(true) do?

Time:12-09

I'm working with the CachingSessionFactory and I was wondering what the property `setTestSession(boolean testSession) does and when to use it?

The docs are not telling a lot about what it does: https://docs.spring.io/spring-integration/api/org/springframework/integration/file/remote/session/CachingSessionFactory.html#setTestSession(boolean)

CodePudding user response:

See SFTP docs: https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-session-caching

Starting with version 5.1, the CachingSessionFactory has a new property testSession. When true, the session will be tested by performing a REALPATH command for an empty path to ensure it is still active; if not, it will be removed from the cache; a new session is created if no active sessions are in the cache.

The logic there in the cache is like this:

public boolean isStale(Session<F> session) {
            return CachingSessionFactory.this.testSession ? !session.test() : !session.isOpen();
        }

See SftpSession for implementation details.

  • Related