From 0a9b48d2e3f07f2768bdbc4f6f7b7561142f6243 Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Fri, 31 Mar 2023 14:30:09 -0400 Subject: [PATCH] Upgrade WildFly to 28.0.0.Beta1 --- .../CatalinaSessionExpirationListener.java | 5 +-- .../CatalinaSpecificationProvider.java | 2 +- .../tomcat/catalina/DistributableSession.java | 6 +-- .../tomcat/catalina/HttpSessionAdapter.java | 2 +- .../tomcat/hotrod/HotRodManager.java | 17 ++++++-- .../CatalinaSessionExpirationListener.java | 5 +-- .../CatalinaSpecificationProvider.java | 2 +- .../tomcat/catalina/DistributableSession.java | 6 +-- .../tomcat/catalina/HttpSessionAdapter.java | 2 +- .../tomcat/hotrod/HotRodManager.java | 17 ++++++-- .../CatalinaSessionExpirationListener.java | 5 +-- .../CatalinaSpecificationProvider.java | 2 +- .../tomcat/catalina/DistributableSession.java | 6 +-- .../tomcat/catalina/HttpSessionAdapter.java | 2 +- .../tomcat/hotrod/HotRodManager.java | 13 +++++-- .../CatalinaSessionExpirationListener.java | 5 +-- .../CatalinaSpecificationProvider.java | 2 +- .../tomcat/catalina/DistributableSession.java | 6 +-- .../tomcat/catalina/HttpSessionAdapter.java | 2 +- .../tomcat/hotrod/HotRodManager.java | 17 ++++++-- .../tomcat/SessionManagerConfiguration.java | 39 +++++++++++++++++++ pom.xml | 4 +- 22 files changed, 118 insertions(+), 49 deletions(-) create mode 100644 common/src/main/java/org/wildfly/clustering/tomcat/SessionManagerConfiguration.java diff --git a/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java b/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java index 3add7be4..673c2b89 100644 --- a/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java +++ b/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java @@ -29,13 +29,12 @@ import org.wildfly.clustering.context.ContextClassLoaderReference; import org.wildfly.clustering.context.ContextReferenceExecutor; import org.wildfly.clustering.web.session.ImmutableSession; -import org.wildfly.clustering.web.session.SessionExpirationListener; /** * Invokes following timeout of a session. * @author Paul Ferraro */ -public class CatalinaSessionExpirationListener implements SessionExpirationListener { +public class CatalinaSessionExpirationListener implements Consumer { private final Consumer expireAction; private final Executor executor; @@ -46,7 +45,7 @@ public CatalinaSessionExpirationListener(Context context) { } @Override - public void sessionExpired(ImmutableSession session) { + public void accept(ImmutableSession session) { this.executor.execute(() -> this.expireAction.accept(session)); } } diff --git a/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java b/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java index 5b36fdeb..c5369c56 100644 --- a/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java +++ b/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java @@ -70,7 +70,7 @@ public long getLastAccessedTime() { @Override public int getMaxInactiveInterval() { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } @Override diff --git a/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java b/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java index c6ed564c..e6dfee73 100644 --- a/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java +++ b/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java @@ -117,7 +117,7 @@ public Manager getManager() { public int getMaxInactiveInterval() { Session session = this.session.get(); try (BatchContext context = this.resumeBatch()) { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } catch (IllegalStateException e) { this.closeIfInvalid(session); throw e; @@ -232,8 +232,8 @@ public void tellChangedSessionId(String newId, String oldId, boolean notifySessi for (String name: oldSession.getAttributes().getAttributeNames()) { newSession.getAttributes().setAttribute(name, oldSession.getAttributes().getAttribute(name)); } - newSession.getMetaData().setMaxInactiveInterval(oldSession.getMetaData().getMaxInactiveInterval()); - newSession.getMetaData().setLastAccess(oldSession.getMetaData().getLastAccessStartTime(), oldSession.getMetaData().getLastAccessEndTime()); + newSession.getMetaData().setMaxInactiveInterval(oldSession.getMetaData().getTimeout()); + newSession.getMetaData().setLastAccess(oldSession.getMetaData().getLastAccessStartTime(), oldSession.getMetaData().getLastAccessTime()); newSession.getLocalContext().setAuthType(oldSession.getLocalContext().getAuthType()); newSession.getLocalContext().setPrincipal(oldSession.getLocalContext().getPrincipal()); oldSession.invalidate(); diff --git a/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java b/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java index 681a1c7e..c024f9e0 100644 --- a/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java +++ b/10.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java @@ -133,7 +133,7 @@ public long getLastAccessedTime() { public int getMaxInactiveInterval() { Session session = this.session.get(); try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } catch (IllegalStateException e) { this.closeIfInvalid.accept(session); throw e; diff --git a/10.0/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java b/10.0/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java index 35c5d6eb..aeb78744 100644 --- a/10.0/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java +++ b/10.0/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java @@ -31,7 +31,9 @@ import java.util.Optional; import java.util.Properties; import java.util.ServiceLoader; +import java.util.function.Consumer; import java.util.function.Supplier; +import java.util.function.ToIntFunction; import jakarta.servlet.ServletContext; import jakarta.servlet.http.HttpSession; @@ -72,9 +74,9 @@ import org.wildfly.clustering.web.LocalContextFactory; import org.wildfly.clustering.web.hotrod.session.HotRodSessionManagerFactory; import org.wildfly.clustering.web.hotrod.session.HotRodSessionManagerFactoryConfiguration; +import org.wildfly.clustering.web.session.ImmutableSession; import org.wildfly.clustering.web.session.SessionAttributeImmutability; import org.wildfly.clustering.web.session.SessionAttributePersistenceStrategy; -import org.wildfly.clustering.web.session.SessionExpirationListener; import org.wildfly.clustering.web.session.SessionManager; import org.wildfly.clustering.web.session.SessionManagerConfiguration; import org.wildfly.clustering.web.session.SessionManagerFactory; @@ -88,6 +90,8 @@ */ public class HotRodManager extends ManagerBase { + static final ToIntFunction SESSION_TIMEOUT_FUNCTION = ServletContext::getSessionTimeout; + private final Properties properties = new Properties(); private volatile RemoteCacheContainer container; @@ -224,22 +228,27 @@ public SpecificationProvider(sessionManagerFactoryConfig); ServletContext servletContext = context.getServletContext(); - SessionExpirationListener expirationListener = new CatalinaSessionExpirationListener(context); + Consumer expirationListener = new CatalinaSessionExpirationListener(context); Supplier identifierFactory = new CatalinaIdentifierFactory(this.getSessionIdGenerator()); - SessionManagerConfiguration sessionManagerConfiguration = new SessionManagerConfiguration<>() { + SessionManagerConfiguration sessionManagerConfiguration = new org.wildfly.clustering.tomcat.SessionManagerConfiguration<>() { @Override public ServletContext getServletContext() { return servletContext; } + @Override + public ToIntFunction getSessionTimeoutFunction() { + return SESSION_TIMEOUT_FUNCTION; + } + @Override public Supplier getIdentifierFactory() { return identifierFactory; } @Override - public SessionExpirationListener getExpirationListener() { + public Consumer getExpirationListener() { return expirationListener; } }; diff --git a/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java b/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java index 3add7be4..673c2b89 100644 --- a/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java +++ b/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java @@ -29,13 +29,12 @@ import org.wildfly.clustering.context.ContextClassLoaderReference; import org.wildfly.clustering.context.ContextReferenceExecutor; import org.wildfly.clustering.web.session.ImmutableSession; -import org.wildfly.clustering.web.session.SessionExpirationListener; /** * Invokes following timeout of a session. * @author Paul Ferraro */ -public class CatalinaSessionExpirationListener implements SessionExpirationListener { +public class CatalinaSessionExpirationListener implements Consumer { private final Consumer expireAction; private final Executor executor; @@ -46,7 +45,7 @@ public CatalinaSessionExpirationListener(Context context) { } @Override - public void sessionExpired(ImmutableSession session) { + public void accept(ImmutableSession session) { this.executor.execute(() -> this.expireAction.accept(session)); } } diff --git a/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java b/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java index 5b36fdeb..c5369c56 100644 --- a/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java +++ b/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java @@ -70,7 +70,7 @@ public long getLastAccessedTime() { @Override public int getMaxInactiveInterval() { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } @Override diff --git a/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java b/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java index c6ed564c..e6dfee73 100644 --- a/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java +++ b/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java @@ -117,7 +117,7 @@ public Manager getManager() { public int getMaxInactiveInterval() { Session session = this.session.get(); try (BatchContext context = this.resumeBatch()) { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } catch (IllegalStateException e) { this.closeIfInvalid(session); throw e; @@ -232,8 +232,8 @@ public void tellChangedSessionId(String newId, String oldId, boolean notifySessi for (String name: oldSession.getAttributes().getAttributeNames()) { newSession.getAttributes().setAttribute(name, oldSession.getAttributes().getAttribute(name)); } - newSession.getMetaData().setMaxInactiveInterval(oldSession.getMetaData().getMaxInactiveInterval()); - newSession.getMetaData().setLastAccess(oldSession.getMetaData().getLastAccessStartTime(), oldSession.getMetaData().getLastAccessEndTime()); + newSession.getMetaData().setMaxInactiveInterval(oldSession.getMetaData().getTimeout()); + newSession.getMetaData().setLastAccess(oldSession.getMetaData().getLastAccessStartTime(), oldSession.getMetaData().getLastAccessTime()); newSession.getLocalContext().setAuthType(oldSession.getLocalContext().getAuthType()); newSession.getLocalContext().setPrincipal(oldSession.getLocalContext().getPrincipal()); oldSession.invalidate(); diff --git a/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java b/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java index 681a1c7e..c024f9e0 100644 --- a/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java +++ b/10.1/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java @@ -133,7 +133,7 @@ public long getLastAccessedTime() { public int getMaxInactiveInterval() { Session session = this.session.get(); try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } catch (IllegalStateException e) { this.closeIfInvalid.accept(session); throw e; diff --git a/10.1/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java b/10.1/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java index 35c5d6eb..aeb78744 100644 --- a/10.1/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java +++ b/10.1/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java @@ -31,7 +31,9 @@ import java.util.Optional; import java.util.Properties; import java.util.ServiceLoader; +import java.util.function.Consumer; import java.util.function.Supplier; +import java.util.function.ToIntFunction; import jakarta.servlet.ServletContext; import jakarta.servlet.http.HttpSession; @@ -72,9 +74,9 @@ import org.wildfly.clustering.web.LocalContextFactory; import org.wildfly.clustering.web.hotrod.session.HotRodSessionManagerFactory; import org.wildfly.clustering.web.hotrod.session.HotRodSessionManagerFactoryConfiguration; +import org.wildfly.clustering.web.session.ImmutableSession; import org.wildfly.clustering.web.session.SessionAttributeImmutability; import org.wildfly.clustering.web.session.SessionAttributePersistenceStrategy; -import org.wildfly.clustering.web.session.SessionExpirationListener; import org.wildfly.clustering.web.session.SessionManager; import org.wildfly.clustering.web.session.SessionManagerConfiguration; import org.wildfly.clustering.web.session.SessionManagerFactory; @@ -88,6 +90,8 @@ */ public class HotRodManager extends ManagerBase { + static final ToIntFunction SESSION_TIMEOUT_FUNCTION = ServletContext::getSessionTimeout; + private final Properties properties = new Properties(); private volatile RemoteCacheContainer container; @@ -224,22 +228,27 @@ public SpecificationProvider(sessionManagerFactoryConfig); ServletContext servletContext = context.getServletContext(); - SessionExpirationListener expirationListener = new CatalinaSessionExpirationListener(context); + Consumer expirationListener = new CatalinaSessionExpirationListener(context); Supplier identifierFactory = new CatalinaIdentifierFactory(this.getSessionIdGenerator()); - SessionManagerConfiguration sessionManagerConfiguration = new SessionManagerConfiguration<>() { + SessionManagerConfiguration sessionManagerConfiguration = new org.wildfly.clustering.tomcat.SessionManagerConfiguration<>() { @Override public ServletContext getServletContext() { return servletContext; } + @Override + public ToIntFunction getSessionTimeoutFunction() { + return SESSION_TIMEOUT_FUNCTION; + } + @Override public Supplier getIdentifierFactory() { return identifierFactory; } @Override - public SessionExpirationListener getExpirationListener() { + public Consumer getExpirationListener() { return expirationListener; } }; diff --git a/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java b/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java index 3add7be4..673c2b89 100644 --- a/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java +++ b/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java @@ -29,13 +29,12 @@ import org.wildfly.clustering.context.ContextClassLoaderReference; import org.wildfly.clustering.context.ContextReferenceExecutor; import org.wildfly.clustering.web.session.ImmutableSession; -import org.wildfly.clustering.web.session.SessionExpirationListener; /** * Invokes following timeout of a session. * @author Paul Ferraro */ -public class CatalinaSessionExpirationListener implements SessionExpirationListener { +public class CatalinaSessionExpirationListener implements Consumer { private final Consumer expireAction; private final Executor executor; @@ -46,7 +45,7 @@ public CatalinaSessionExpirationListener(Context context) { } @Override - public void sessionExpired(ImmutableSession session) { + public void accept(ImmutableSession session) { this.executor.execute(() -> this.expireAction.accept(session)); } } diff --git a/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java b/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java index f16ab3af..ccc3b95d 100644 --- a/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java +++ b/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java @@ -70,7 +70,7 @@ public long getLastAccessedTime() { @Override public int getMaxInactiveInterval() { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } @Override diff --git a/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java b/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java index c2568c4e..793db641 100644 --- a/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java +++ b/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java @@ -117,7 +117,7 @@ public Manager getManager() { public int getMaxInactiveInterval() { Session session = this.session.get(); try (BatchContext context = this.resumeBatch()) { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } catch (IllegalStateException e) { this.closeIfInvalid(session); throw e; @@ -232,8 +232,8 @@ public void tellChangedSessionId(String newId, String oldId, boolean notifySessi for (String name: oldSession.getAttributes().getAttributeNames()) { newSession.getAttributes().setAttribute(name, oldSession.getAttributes().getAttribute(name)); } - newSession.getMetaData().setMaxInactiveInterval(oldSession.getMetaData().getMaxInactiveInterval()); - newSession.getMetaData().setLastAccess(oldSession.getMetaData().getLastAccessStartTime(), oldSession.getMetaData().getLastAccessEndTime()); + newSession.getMetaData().setMaxInactiveInterval(oldSession.getMetaData().getTimeout()); + newSession.getMetaData().setLastAccess(oldSession.getMetaData().getLastAccessStartTime(), oldSession.getMetaData().getLastAccessTime()); newSession.getLocalContext().setAuthType(oldSession.getLocalContext().getAuthType()); newSession.getLocalContext().setPrincipal(oldSession.getLocalContext().getPrincipal()); oldSession.invalidate(); diff --git a/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java b/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java index 0b9606d9..c298ed48 100644 --- a/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java +++ b/8.5/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java @@ -133,7 +133,7 @@ public long getLastAccessedTime() { public int getMaxInactiveInterval() { Session session = this.session.get(); try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } catch (IllegalStateException e) { this.closeIfInvalid.accept(session); throw e; diff --git a/8.5/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java b/8.5/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java index 75b023f4..5d678c6b 100644 --- a/8.5/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java +++ b/8.5/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.net.URI; +import java.time.Duration; import java.util.EnumSet; import java.util.HashMap; import java.util.LinkedList; @@ -31,6 +32,7 @@ import java.util.Optional; import java.util.Properties; import java.util.ServiceLoader; +import java.util.function.Consumer; import java.util.function.Supplier; import javax.servlet.ServletContext; @@ -72,9 +74,9 @@ import org.wildfly.clustering.web.LocalContextFactory; import org.wildfly.clustering.web.hotrod.session.HotRodSessionManagerFactory; import org.wildfly.clustering.web.hotrod.session.HotRodSessionManagerFactoryConfiguration; +import org.wildfly.clustering.web.session.ImmutableSession; import org.wildfly.clustering.web.session.SessionAttributeImmutability; import org.wildfly.clustering.web.session.SessionAttributePersistenceStrategy; -import org.wildfly.clustering.web.session.SessionExpirationListener; import org.wildfly.clustering.web.session.SessionManager; import org.wildfly.clustering.web.session.SessionManagerConfiguration; import org.wildfly.clustering.web.session.SessionManagerFactory; @@ -224,7 +226,7 @@ public SpecificationProvider(sessionManagerFactoryConfig); ServletContext servletContext = context.getServletContext(); - SessionExpirationListener expirationListener = new CatalinaSessionExpirationListener(context); + Consumer expirationListener = new CatalinaSessionExpirationListener(context); Supplier identifierFactory = new CatalinaIdentifierFactory(this.getSessionIdGenerator()); SessionManagerConfiguration sessionManagerConfiguration = new SessionManagerConfiguration<>() { @@ -233,13 +235,18 @@ public ServletContext getServletContext() { return servletContext; } + @Override + public Duration getTimeout() { + return Duration.ofMinutes(context.getSessionTimeout()); + } + @Override public Supplier getIdentifierFactory() { return identifierFactory; } @Override - public SessionExpirationListener getExpirationListener() { + public Consumer getExpirationListener() { return expirationListener; } }; diff --git a/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java b/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java index 3add7be4..673c2b89 100644 --- a/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java +++ b/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSessionExpirationListener.java @@ -29,13 +29,12 @@ import org.wildfly.clustering.context.ContextClassLoaderReference; import org.wildfly.clustering.context.ContextReferenceExecutor; import org.wildfly.clustering.web.session.ImmutableSession; -import org.wildfly.clustering.web.session.SessionExpirationListener; /** * Invokes following timeout of a session. * @author Paul Ferraro */ -public class CatalinaSessionExpirationListener implements SessionExpirationListener { +public class CatalinaSessionExpirationListener implements Consumer { private final Consumer expireAction; private final Executor executor; @@ -46,7 +45,7 @@ public CatalinaSessionExpirationListener(Context context) { } @Override - public void sessionExpired(ImmutableSession session) { + public void accept(ImmutableSession session) { this.executor.execute(() -> this.expireAction.accept(session)); } } diff --git a/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java b/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java index f16ab3af..ccc3b95d 100644 --- a/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java +++ b/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/CatalinaSpecificationProvider.java @@ -70,7 +70,7 @@ public long getLastAccessedTime() { @Override public int getMaxInactiveInterval() { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } @Override diff --git a/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java b/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java index c2568c4e..793db641 100644 --- a/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java +++ b/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/DistributableSession.java @@ -117,7 +117,7 @@ public Manager getManager() { public int getMaxInactiveInterval() { Session session = this.session.get(); try (BatchContext context = this.resumeBatch()) { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } catch (IllegalStateException e) { this.closeIfInvalid(session); throw e; @@ -232,8 +232,8 @@ public void tellChangedSessionId(String newId, String oldId, boolean notifySessi for (String name: oldSession.getAttributes().getAttributeNames()) { newSession.getAttributes().setAttribute(name, oldSession.getAttributes().getAttribute(name)); } - newSession.getMetaData().setMaxInactiveInterval(oldSession.getMetaData().getMaxInactiveInterval()); - newSession.getMetaData().setLastAccess(oldSession.getMetaData().getLastAccessStartTime(), oldSession.getMetaData().getLastAccessEndTime()); + newSession.getMetaData().setMaxInactiveInterval(oldSession.getMetaData().getTimeout()); + newSession.getMetaData().setLastAccess(oldSession.getMetaData().getLastAccessStartTime(), oldSession.getMetaData().getLastAccessTime()); newSession.getLocalContext().setAuthType(oldSession.getLocalContext().getAuthType()); newSession.getLocalContext().setPrincipal(oldSession.getLocalContext().getPrincipal()); oldSession.invalidate(); diff --git a/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java b/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java index 0b9606d9..c298ed48 100644 --- a/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java +++ b/9.0/catalina/src/main/java/org/wildfly/clustering/tomcat/catalina/HttpSessionAdapter.java @@ -133,7 +133,7 @@ public long getLastAccessedTime() { public int getMaxInactiveInterval() { Session session = this.session.get(); try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) { - return (int) session.getMetaData().getMaxInactiveInterval().getSeconds(); + return (int) session.getMetaData().getTimeout().getSeconds(); } catch (IllegalStateException e) { this.closeIfInvalid.accept(session); throw e; diff --git a/9.0/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java b/9.0/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java index e4e52ddf..857cf26d 100644 --- a/9.0/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java +++ b/9.0/hotrod/src/main/java/org/wildfly/clustering/tomcat/hotrod/HotRodManager.java @@ -31,7 +31,9 @@ import java.util.Optional; import java.util.Properties; import java.util.ServiceLoader; +import java.util.function.Consumer; import java.util.function.Supplier; +import java.util.function.ToIntFunction; import javax.servlet.ServletContext; import javax.servlet.http.HttpSession; @@ -72,9 +74,9 @@ import org.wildfly.clustering.web.LocalContextFactory; import org.wildfly.clustering.web.hotrod.session.HotRodSessionManagerFactory; import org.wildfly.clustering.web.hotrod.session.HotRodSessionManagerFactoryConfiguration; +import org.wildfly.clustering.web.session.ImmutableSession; import org.wildfly.clustering.web.session.SessionAttributeImmutability; import org.wildfly.clustering.web.session.SessionAttributePersistenceStrategy; -import org.wildfly.clustering.web.session.SessionExpirationListener; import org.wildfly.clustering.web.session.SessionManager; import org.wildfly.clustering.web.session.SessionManagerConfiguration; import org.wildfly.clustering.web.session.SessionManagerFactory; @@ -88,6 +90,8 @@ */ public class HotRodManager extends ManagerBase { + static final ToIntFunction SESSION_TIMEOUT_FUNCTION = ServletContext::getSessionTimeout; + private final Properties properties = new Properties(); private volatile RemoteCacheContainer container; @@ -224,22 +228,27 @@ public SpecificationProvider(sessionManagerFactoryConfig); ServletContext servletContext = context.getServletContext(); - SessionExpirationListener expirationListener = new CatalinaSessionExpirationListener(context); + Consumer expirationListener = new CatalinaSessionExpirationListener(context); Supplier identifierFactory = new CatalinaIdentifierFactory(this.getSessionIdGenerator()); - SessionManagerConfiguration sessionManagerConfiguration = new SessionManagerConfiguration<>() { + SessionManagerConfiguration sessionManagerConfiguration = new org.wildfly.clustering.tomcat.SessionManagerConfiguration<>() { @Override public ServletContext getServletContext() { return servletContext; } + @Override + public ToIntFunction getSessionTimeoutFunction() { + return SESSION_TIMEOUT_FUNCTION; + } + @Override public Supplier getIdentifierFactory() { return identifierFactory; } @Override - public SessionExpirationListener getExpirationListener() { + public Consumer getExpirationListener() { return expirationListener; } }; diff --git a/common/src/main/java/org/wildfly/clustering/tomcat/SessionManagerConfiguration.java b/common/src/main/java/org/wildfly/clustering/tomcat/SessionManagerConfiguration.java new file mode 100644 index 00000000..e5d927de --- /dev/null +++ b/common/src/main/java/org/wildfly/clustering/tomcat/SessionManagerConfiguration.java @@ -0,0 +1,39 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2023, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.wildfly.clustering.tomcat; + +import java.time.Duration; +import java.util.function.ToIntFunction; + +/** + * @author Paul Ferraro + */ +public interface SessionManagerConfiguration extends org.wildfly.clustering.web.session.SessionManagerConfiguration { + + ToIntFunction getSessionTimeoutFunction(); + + @Override + default Duration getTimeout() { + return Duration.ofMinutes(this.getSessionTimeoutFunction().applyAsInt(this.getServletContext())); + } +} diff --git a/pom.xml b/pom.xml index 96fbd3e2..6fc1a8cb 100644 --- a/pom.xml +++ b/pom.xml @@ -54,12 +54,12 @@ 1.0 5.2.1 14.0.7.Final - 4.6.0.Final + 4.6.1.Final ${version.org.infinispan} 1.6.0.Final 1.1.0.Final 1.9 - 27.0.1.Final + 28.0.0.Beta1 4.13.2