diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java index 3267e5cb1c..64c0c7a7ed 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java @@ -56,6 +56,7 @@ import org.springframework.util.StringUtils; * @author David Turanski * @author Gary Russell * @author Artem Bilan + * @author Alen Turkovic * * @since 3.0 * @@ -443,9 +444,7 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ return callback.doInSession(session); } catch (Exception e) { - if (session instanceof CachingSessionFactory.CachedSession) { - ((CachingSessionFactory.CachedSession) session).dirty(); - } + session.dirty(); if (e instanceof MessagingException) { throw (MessagingException) e; } 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 fe4597bf3c..019c950f75 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 @@ -36,6 +36,7 @@ import org.springframework.util.Assert; * @author Oleg Zhurakousky * @author Mark Fisher * @author Gary Russell + * @author Alen Turkovic * @since 2.0 */ public class CachingSessionFactory implements SessionFactory, DisposableBean { @@ -273,6 +274,7 @@ public class CachingSessionFactory implements SessionFactory, DisposableBe return this.targetSession.finalizeRaw(); } + @Override public void dirty() { this.dirty = true; } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/Session.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/Session.java index 76c0789299..305a4f6d0b 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/Session.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/Session.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import java.io.OutputStream; * @author Mark Fisher * @author Oleg Zhurakousky * @author Gary Russell + * @author Alen Turkovic * @since 2.0 */ public interface Session extends Closeable { @@ -107,4 +108,14 @@ public interface Session extends Closeable { */ Object getClientInstance(); + /** + * Mark this session as dirty, indicating that it should not be reused and any + * delegated sessions should be taken care of before closing. + * @see CachingSessionFactory.CachedSession#close() + * @since 5.1.2 + */ + default void dirty() { + // NOOP + } + }