diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java index 3d060c1eb3..1948dc7bcf 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java @@ -39,7 +39,7 @@ import org.springframework.beans.factory.DisposableBean; */ public class CachingSessionFactory implements SessionFactory, DisposableBean { - private static Log logger = LogFactory.getLog(CachingSessionFactory.class); + private static final Log logger = LogFactory.getLog(CachingSessionFactory.class); public static final int DEFAULT_POOL_SIZE = 10; @@ -50,6 +50,7 @@ public class CachingSessionFactory implements SessionFactory, DisposableBean { private final int maxPoolSize; + public CachingSessionFactory(SessionFactory sessionFactory) { this(sessionFactory, DEFAULT_POOL_SIZE); } @@ -60,20 +61,21 @@ public class CachingSessionFactory implements SessionFactory, DisposableBean { this.queue = new ArrayBlockingQueue(this.maxPoolSize, true); } + public Session getSession() { Session session = this.queue.poll(); - - if (session == null || (session != null && !session.isOpen())) { - if (session != null && !session.isOpen()){ + if (session == null || !session.isOpen()) { + if (session != null && logger.isTraceEnabled()) { logger.trace("Located session in the pool but it is stale, will create new one."); } - session = sessionFactory.getSession(); - logger.trace("Created new session"); + session = this.sessionFactory.getSession(); + if (logger.isTraceEnabled()) { + logger.trace("Created new session"); + } } - else { + else if (logger.isTraceEnabled()) { logger.trace("Using session from the pool"); } - return new CachedSession(session); } @@ -92,8 +94,10 @@ public class CachingSessionFactory implements SessionFactory, DisposableBean { } } catch (Throwable e) { - // log and ignore - logger.warn("Exception was thrown while destroying Session. ", e); + if (logger.isWarnEnabled()) { + // log and ignore + logger.warn("Exception was thrown while destroying Session. ", e); + } } } @@ -108,11 +112,15 @@ public class CachingSessionFactory implements SessionFactory, DisposableBean { public void close() { if (queue.size() < maxPoolSize) { - logger.trace("Releasing target session back to the pool"); + if (logger.isTraceEnabled()) { + logger.trace("Releasing target session back to the pool"); + } queue.add(targetSession); } else { - logger.trace("Disconnecting target session"); + if (logger.isTraceEnabled()) { + logger.trace("Disconnecting target session"); + } targetSession.close(); } } diff --git a/spring-integration-sftp/.gitignore b/spring-integration-sftp/.gitignore index 314bcda8e2..cb9bdcd169 100644 --- a/spring-integration-sftp/.gitignore +++ b/spring-integration-sftp/.gitignore @@ -1,2 +1,3 @@ local-test-dir/*.test -remote-target-dir/*test-foo +remote-target-dir/*foo* +remote-target-dir/*test*