Skip to content

Commit

Permalink
Update to wildfly-clustering 1.0.8.Final.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Mar 7, 2024
1 parent 4c13414 commit c6181d2
Show file tree
Hide file tree
Showing 104 changed files with 1,434 additions and 3,228 deletions.
23 changes: 13 additions & 10 deletions 10.1/catalina/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,31 @@
<artifactId>wildfly-clustering-tomcat-10.1-catalina</artifactId>
<packaging>jar</packaging>

<name>Distributed session management for Tomcat 10.1: Catalina integration</name>
<name>WildFly Clustering: Tomcat 10.1: Catalina integration</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-clustering-tomcat-common</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.wildfly</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-clustering-tomcat-spi</artifactId>
</dependency>

<dependency>
<groupId>org.wildfly.clustering</groupId>
<artifactId>wildfly-clustering-context</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-clustering-web-cache</artifactId>
<groupId>org.wildfly.clustering</groupId>
<artifactId>wildfly-clustering-session-cache</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.clustering</groupId>
<artifactId>wildfly-clustering-session-spec-servlet-6.0</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import org.apache.catalina.LifecycleState;
import org.apache.catalina.Manager;
import org.apache.catalina.SessionIdGenerator;
import org.wildfly.clustering.ee.Batch;
import org.wildfly.clustering.marshalling.spi.Marshallability;
import org.wildfly.clustering.web.session.SessionManager;
import org.wildfly.clustering.cache.batch.Batch;
import org.wildfly.clustering.marshalling.Marshallability;
import org.wildfly.clustering.session.SessionManager;

/**
* Enhances Tomcat's Manager interface, providing default implementations for deprecated methods and methods we currently ignore.
Expand All @@ -46,7 +46,7 @@ public interface CatalinaManager<B extends Batch> extends Manager, Lifecycle {
* Returns underlying distributable session manager implementation.
* @return a session manager
*/
SessionManager<LocalSessionContext, B> getSessionManager();
SessionManager<CatalinaSessionContext, B> getSessionManager();

/**
* Returns a mechanism for determining the marshallability of a session attribute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* Local (i.e. non-persistent) context for a Tomcat session.
* @author Paul Ferraro
*/
public class LocalSessionContext {
public class CatalinaSessionContext {
private final Map<String, Object> notes = new ConcurrentHashMap<>();
private final List<SessionListener> listeners = new CopyOnWriteArrayList<>();
private volatile String authType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@
import java.util.function.Consumer;
import java.util.stream.Stream;

import org.apache.catalina.Context;
import org.wildfly.clustering.web.cache.session.attributes.coarse.ImmutableSessionAttributesFilter;
import org.wildfly.clustering.web.cache.session.attributes.coarse.SessionAttributesFilter;
import org.wildfly.clustering.web.session.ImmutableSession;

import jakarta.servlet.http.HttpSessionBindingEvent;
import jakarta.servlet.http.HttpSessionBindingListener;
import jakarta.servlet.http.HttpSessionEvent;
import jakarta.servlet.http.HttpSessionListener;

import org.apache.catalina.Context;
import org.wildfly.clustering.session.ImmutableSession;
import org.wildfly.clustering.session.spec.servlet.HttpSessionProvider;

/**
* Defines an action to be performed prior to destruction of a session.
* @author Paul Ferraro
Expand All @@ -49,8 +48,7 @@ public CatalinaSessionDestroyAction(Context context) {

@Override
public void accept(ImmutableSession session) {
SessionAttributesFilter filter = new ImmutableSessionAttributesFilter(session);
HttpSessionEvent event = new HttpSessionEvent(CatalinaSpecificationProvider.INSTANCE.createHttpSession(session, this.context.getServletContext()));
HttpSessionEvent event = new HttpSessionEvent(HttpSessionProvider.INSTANCE.asSession(session, this.context.getServletContext()));
Stream.of(this.context.getApplicationLifecycleListeners()).filter(HttpSessionListener.class::isInstance).map(HttpSessionListener.class::cast).forEach(listener -> {
try {
this.context.fireContainerEvent("beforeSessionDestroyed", listener);
Expand All @@ -61,12 +59,14 @@ public void accept(ImmutableSession session) {
this.context.fireContainerEvent("afterSessionDestroyed", listener);
}
});
for (Map.Entry<String, HttpSessionBindingListener> entry : filter.getAttributes(HttpSessionBindingListener.class).entrySet()) {
HttpSessionBindingListener listener = entry.getValue();
try {
listener.valueUnbound(new HttpSessionBindingEvent(event.getSession(), entry.getKey(), listener));
} catch (Throwable e) {
this.context.getLogger().warn(e.getMessage(), e);
for (Map.Entry<String, Object> entry : session.getAttributes().entrySet()) {
if (entry.getValue() instanceof HttpSessionBindingListener) {
HttpSessionBindingListener listener = (HttpSessionBindingListener) entry.getValue();
try {
listener.valueUnbound(new HttpSessionBindingEvent(event.getSession(), entry.getKey(), listener));
} catch (Throwable e) {
this.context.getLogger().warn(e.getMessage(), e);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

import org.apache.catalina.Context;
import org.wildfly.clustering.context.ContextClassLoaderReference;
import org.wildfly.clustering.context.ContextReferenceExecutor;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.context.ContextualExecutor;
import org.wildfly.clustering.session.ImmutableSession;

/**
* Invokes following timeout of a session.
Expand All @@ -41,7 +41,7 @@ public class CatalinaSessionExpirationListener implements Consumer<ImmutableSess

public CatalinaSessionExpirationListener(Context context) {
this.expireAction = new CatalinaSessionDestroyAction(context);
this.executor = new ContextReferenceExecutor<>(context.getLoader().getClassLoader(), ContextClassLoaderReference.INSTANCE);
this.executor = ContextualExecutor.withContext(context.getLoader().getClassLoader(), ContextClassLoaderReference.INSTANCE);
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,27 @@
import java.util.function.Consumer;
import java.util.stream.Stream;

import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.wildfly.clustering.ee.Batch;
import org.wildfly.clustering.ee.Batcher;
import org.wildfly.clustering.marshalling.spi.Marshallability;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.Session;
import org.wildfly.clustering.web.session.SessionManager;

import jakarta.servlet.http.HttpSessionEvent;
import jakarta.servlet.http.HttpSessionListener;

import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.wildfly.clustering.cache.batch.Batch;
import org.wildfly.clustering.cache.batch.Batcher;
import org.wildfly.clustering.marshalling.Marshallability;
import org.wildfly.clustering.session.ImmutableSession;
import org.wildfly.clustering.session.Session;
import org.wildfly.clustering.session.SessionManager;
import org.wildfly.clustering.session.spec.servlet.HttpSessionProvider;

/**
* Adapts a WildFly distributable SessionManager to Tomcat's Manager interface.
* @author Paul Ferraro
*/
public class DistributableManager<B extends Batch> implements CatalinaManager<B> {
private static final char ROUTE_DELIMITER = '.';

private final SessionManager<LocalSessionContext, B> manager;
private final SessionManager<CatalinaSessionContext, B> manager;
private final Context context;
private final Consumer<ImmutableSession> invalidateAction;
private final Marshallability marshallability;
Expand All @@ -58,7 +59,7 @@ public class DistributableManager<B extends Batch> implements CatalinaManager<B>
// Guarded by this
private OptionalLong lifecycleStamp = OptionalLong.empty();

public DistributableManager(SessionManager<LocalSessionContext, B> manager, Context context, Marshallability marshallability) {
public DistributableManager(SessionManager<CatalinaSessionContext, B> manager, Context context, Marshallability marshallability) {
this.manager = manager;
this.marshallability = marshallability;
this.context = context;
Expand All @@ -67,7 +68,7 @@ public DistributableManager(SessionManager<LocalSessionContext, B> manager, Cont
}

@Override
public SessionManager<LocalSessionContext, B> getSessionManager() {
public SessionManager<CatalinaSessionContext, B> getSessionManager() {
return this.manager;
}

Expand All @@ -87,7 +88,7 @@ private static String parseSessionId(String requestedSesssionId) {
/**
* Appends routing information to session identifier.
*/
private org.apache.catalina.Session getSession(Session<LocalSessionContext> session, Runnable closeTask) {
private org.apache.catalina.Session getSession(Session<CatalinaSessionContext> session, Runnable closeTask) {
String id = session.getId();
String internalId = (this.route != null) ? new StringBuilder(id.length() + this.route.length() + 1).append(id).append(ROUTE_DELIMITER).append(this.route).toString() : id;
return new DistributableSession<>(this, session, internalId, this.manager.getBatcher().suspendBatch(), () -> this.invalidateAction.accept(session), closeTask);
Expand Down Expand Up @@ -121,8 +122,8 @@ public org.apache.catalina.Session createSession(String sessionId) {
// Batch will be closed by Session.close();
B batch = batcher.createBatch();
try {
Session<LocalSessionContext> session = this.manager.createSession(id);
HttpSessionEvent event = new HttpSessionEvent(CatalinaSpecificationProvider.INSTANCE.createHttpSession(session, this.context.getServletContext()));
Session<CatalinaSessionContext> session = this.manager.createSession(id);
HttpSessionEvent event = new HttpSessionEvent(HttpSessionProvider.INSTANCE.asSession(session, this.context.getServletContext()));
Stream.of(this.context.getApplicationLifecycleListeners()).filter(HttpSessionListener.class::isInstance).map(HttpSessionListener.class::cast).forEach(listener -> {
try {
this.context.fireContainerEvent("beforeSessionCreated", listener);
Expand Down Expand Up @@ -161,7 +162,7 @@ public org.apache.catalina.Session findSession(String sessionId) throws IOExcept
// Batch will be closed by Session.close();
B batch = batcher.createBatch();
try {
Session<LocalSessionContext> session = this.manager.findSession(id);
Session<CatalinaSessionContext> session = this.manager.findSession(id);
if (session == null) {
return null;
}
Expand Down
Loading

0 comments on commit c6181d2

Please sign in to comment.