Custom Session dirty logic

Fixes spring-projects/spring-integration#2687

Allows any session to implement its dirty logic.

* License year was not updated

**Cherry-pick to 5.0.x**
This commit is contained in:
Alen Turkovic
2019-01-10 16:52:45 +01:00
committed by Artem Bilan
parent 2766707547
commit 6ddcfb3a8d
3 changed files with 16 additions and 4 deletions

View File

@@ -56,6 +56,7 @@ import org.springframework.util.StringUtils;
* @author David Turanski
* @author Gary Russell
* @author Artem Bilan
* @author Alen Turkovic
*
* @since 3.0
*
@@ -442,9 +443,7 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, 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;
}

View File

@@ -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<F> implements SessionFactory<F>, DisposableBean {
@@ -284,6 +285,7 @@ public class CachingSessionFactory<F> implements SessionFactory<F>, DisposableBe
return this.targetSession.finalizeRaw();
}
@Override
public void dirty() {
this.dirty = true;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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<F> extends Closeable {
@@ -117,4 +118,14 @@ public interface Session<F> extends Closeable {
return this.isOpen();
}
/**
* 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
}
}