Skip to content

Commit f63abc1

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** # Conflicts: # spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/Session.java
1 parent 23fb52c commit f63abc1

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
*
@@ -443,9 +444,7 @@ public <T> T execute(SessionCallback<F, T> callback) {
443444
return callback.doInSession(session);
444445
}
445446
catch (Exception e) {
446-
if (session instanceof CachingSessionFactory<?>.CachedSession) {
447-
((CachingSessionFactory.CachedSession) session).dirty();
448-
}
447+
session.dirty();
449448
if (e instanceof MessagingException) {
450449
throw (MessagingException) e;
451450
}

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 {
@@ -273,6 +274,7 @@ public boolean finalizeRaw() throws IOException {
273274
return this.targetSession.finalizeRaw();
274275
}
275276

277+
@Override
276278
public void dirty() {
277279
this.dirty = true;
278280
}

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-2016 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 {
@@ -107,4 +108,14 @@ public interface Session<F> extends Closeable {
107108
*/
108109
Object getClientInstance();
109110

111+
/**
112+
* Mark this session as dirty, indicating that it should not be reused and any
113+
* delegated sessions should be taken care of before closing.
114+
* @see CachingSessionFactory.CachedSession#close()
115+
* @since 5.1.2
116+
*/
117+
default void dirty() {
118+
// NOOP
119+
}
120+
110121
}

0 commit comments

Comments
 (0)