Skip to content

Commit 6ddcfb3

Browse files
alturkovicartembilan
authored andcommitted
Custom Session dirty logic
Fixes #2687 Allows any session to implement its dirty logic. * License year was not updated **Cherry-pick to 5.0.x**
1 parent 2766707 commit 6ddcfb3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* @author David Turanski
5757
* @author Gary Russell
5858
* @author Artem Bilan
59+
* @author Alen Turkovic
5960
*
6061
* @since 3.0
6162
*
@@ -442,9 +443,7 @@ public <T> T execute(SessionCallback<F, T> callback) {
442443
return callback.doInSession(session);
443444
}
444445
catch (Exception e) {
445-
if (session instanceof CachingSessionFactory<?>.CachedSession) {
446-
((CachingSessionFactory.CachedSession) session).dirty();
447-
}
446+
session.dirty();
448447
if (e instanceof MessagingException) {
449448
throw (MessagingException) e;
450449
}

spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* @author Oleg Zhurakousky
3737
* @author Mark Fisher
3838
* @author Gary Russell
39+
* @author Alen Turkovic
3940
* @since 2.0
4041
*/
4142
public class CachingSessionFactory<F> implements SessionFactory<F>, DisposableBean {
@@ -284,6 +285,7 @@ public boolean finalizeRaw() throws IOException {
284285
return this.targetSession.finalizeRaw();
285286
}
286287

288+
@Override
287289
public void dirty() {
288290
this.dirty = true;
289291
}

spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/Session.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
2929
* @author Mark Fisher
3030
* @author Oleg Zhurakousky
3131
* @author Gary Russell
32+
* @author Alen Turkovic
3233
* @since 2.0
3334
*/
3435
public interface Session<F> extends Closeable {
@@ -117,4 +118,14 @@ default boolean test() {
117118
return this.isOpen();
118119
}
119120

121+
/**
122+
* Mark this session as dirty, indicating that it should not be reused and any
123+
* delegated sessions should be taken care of before closing.
124+
* @see CachingSessionFactory.CachedSession#close()
125+
* @since 5.1.2
126+
*/
127+
default void dirty() {
128+
// NOOP
129+
}
130+
120131
}

0 commit comments

Comments
 (0)