Skip to content

Commit

Permalink
Merge pull request #148 from pferraro/main
Browse files Browse the repository at this point in the history
Upgrade wildfly-clustering to 1.0.7.Final.
  • Loading branch information
pferraro authored Mar 3, 2024
2 parents 1979e53 + b3f6495 commit 8bfd35c
Show file tree
Hide file tree
Showing 40 changed files with 231 additions and 611 deletions.
2 changes: 1 addition & 1 deletion context/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</dependency>
<dependency>
<groupId>org.wildfly.clustering</groupId>
<artifactId>wildfly-clustering-session-spi</artifactId>
<artifactId>wildfly-clustering-session-spec-spi</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package org.wildfly.clustering.spring.context;

import java.io.ObjectInputFilter;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.BiFunction;

import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
Expand All @@ -23,28 +22,27 @@
/**
* @author Paul Ferraro
*/
public enum SessionMarshallerFactory implements Function<Map.Entry<Environment, ResourceLoader>, ByteBufferMarshaller> {
public enum SessionMarshallerFactory implements BiFunction<Environment, ResourceLoader, ByteBufferMarshaller> {

JAVA() {
@Override
public ByteBufferMarshaller apply(Map.Entry<Environment, ResourceLoader> context) {
Environment environment = context.getKey();
public ByteBufferMarshaller apply(Environment environment, ResourceLoader loader) {
ObjectInputFilter filter = Optional.ofNullable(environment.getProperty("jdk.serialFilter")).map(ObjectInputFilter.Config::createFilter).orElse(null);
return new JavaByteBufferMarshaller(Serializer.of(context.getValue().getClassLoader()), filter);
return new JavaByteBufferMarshaller(Serializer.of(loader.getClassLoader()), filter);
}
},
JBOSS() {
@Override
public ByteBufferMarshaller apply(Map.Entry<Environment, ResourceLoader> context) {
ClassLoader loader = context.getValue().getClassLoader();
return new JBossByteBufferMarshaller(MarshallingConfigurationRepository.from(JBossMarshallingVersion.CURRENT, loader), loader);
public ByteBufferMarshaller apply(Environment environment, ResourceLoader loader) {
ClassLoader classLoader = loader.getClassLoader();
return new JBossByteBufferMarshaller(MarshallingConfigurationRepository.from(JBossMarshallingVersion.CURRENT, classLoader), classLoader);
}
},
PROTOSTREAM() {
@Override
public ByteBufferMarshaller apply(Map.Entry<Environment, ResourceLoader> context) {
ClassLoader loader = context.getValue().getClassLoader();
SerializationContextBuilder builder = SerializationContextBuilder.newInstance(ClassLoaderMarshaller.of(loader)).load(loader);
public ByteBufferMarshaller apply(Environment environment, ResourceLoader loader) {
ClassLoader classLoader = loader.getClassLoader();
SerializationContextBuilder builder = SerializationContextBuilder.newInstance(ClassLoaderMarshaller.of(classLoader)).load(classLoader);
return new ProtoStreamByteBufferMarshaller(builder.build());
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package org.wildfly.clustering.spring.context.config;

import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.OptionalInt;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -30,6 +29,7 @@
import org.wildfly.clustering.session.SessionManagerConfiguration;
import org.wildfly.clustering.session.SessionManagerFactory;
import org.wildfly.clustering.session.SessionManagerFactoryConfiguration;
import org.wildfly.clustering.session.spec.SessionSpecificationProvider;
import org.wildfly.clustering.spring.context.SessionManagerBean;
import org.wildfly.clustering.spring.context.SessionMarshallerFactory;
import org.wildfly.common.function.Functions;
Expand All @@ -38,14 +38,14 @@
* Spring configuration bean for a distributable session repository.
* @author Paul Ferraro
*/
public abstract class SessionManagementConfiguration<S, C, L> implements SessionManagerFactoryConfiguration<S, C, L, Void>, SessionManagerConfiguration<C>, EnvironmentAware, ImportAware, ResourceLoaderAware, Consumer<AnnotationAttributes> {
public abstract class SessionManagementConfiguration<S, C, L> implements SessionManagerFactoryConfiguration<Void>, SessionManagerConfiguration<C>, EnvironmentAware, ImportAware, ResourceLoaderAware, Consumer<AnnotationAttributes>, Supplier<SessionSpecificationProvider<S, C, L>> {

private final Class<? extends Annotation> annotationClass;

private IdGenerator generator = new JdkIdGenerator();
private OptionalInt maxActiveSessions = OptionalInt.empty();
private SessionAttributePersistenceStrategy persistenceStrategy = SessionAttributePersistenceStrategy.COARSE;
private Function<Map.Entry<Environment, ResourceLoader>, ByteBufferMarshaller> marshallerFactory = SessionMarshallerFactory.JAVA;
private BiFunction<Environment, ResourceLoader, ByteBufferMarshaller> marshallerFactory = SessionMarshallerFactory.JAVA;
private Environment environment;
private ResourceLoader loader;

Expand Down Expand Up @@ -95,7 +95,7 @@ public SessionAttributePersistenceStrategy getAttributePersistenceStrategy() {

@Override
public ByteBufferMarshaller getMarshaller() {
return this.marshallerFactory.apply(Map.entry(this.environment, this.loader));
return this.marshallerFactory.apply(this.environment, this.loader);
}

@Autowired(required = false)
Expand All @@ -114,7 +114,7 @@ public void setPersistenceStrategy(SessionAttributePersistenceStrategy persisten
}

@Autowired(required = false)
public void setMarshallerFactory(Function<Map.Entry<Environment, ResourceLoader>, ByteBufferMarshaller> marshallerFactory) {
public void setMarshallerFactory(BiFunction<Environment, ResourceLoader, ByteBufferMarshaller> marshallerFactory) {
this.marshallerFactory = marshallerFactory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,26 @@
import org.wildfly.clustering.session.infinispan.embedded.InfinispanSessionManagerFactory;
import org.wildfly.clustering.session.infinispan.embedded.InfinispanSessionManagerFactoryConfiguration;
import org.wildfly.clustering.session.infinispan.embedded.metadata.SessionMetaDataKey;
import org.wildfly.clustering.session.spec.SessionSpecificationProvider;
import org.wildfly.clustering.spring.context.AutoDestroyBean;

/**
* @author Paul Ferraro
*/
public class InfinispanSessionManagerFactoryBean<S, C, L> extends AutoDestroyBean implements SessionManagerFactory<C, Void, TransactionBatch>, InitializingBean {

private final SessionManagerFactoryConfiguration<S, C, L, Void> configuration;
private final SessionManagerFactoryConfiguration<Void> configuration;
private final SessionSpecificationProvider<S, C, L> provider;
private final InfinispanConfiguration infinispan;
private final ChannelEmbeddedCacheManagerCommandDispatcherFactoryConfiguration embeddedCacheManagerConfiguration;

private SessionManagerFactory<C, Void, TransactionBatch> sessionManagerFactory;

public InfinispanSessionManagerFactoryBean(SessionManagerFactoryConfiguration<S, C, L, Void> configuration, InfinispanConfiguration infinispan, ChannelEmbeddedCacheManagerCommandDispatcherFactoryConfiguration embeddedCacheManagerConfiguration) {
public InfinispanSessionManagerFactoryBean(SessionManagerFactoryConfiguration<Void> configuration, SessionSpecificationProvider<S, C, L> provider, InfinispanConfiguration infinispan, ChannelEmbeddedCacheManagerCommandDispatcherFactoryConfiguration embeddedCacheManagerConfiguration) {
this.configuration = configuration;
this.provider = provider;
this.infinispan = infinispan;
this.embeddedCacheManagerConfiguration = embeddedCacheManagerConfiguration;
this.configuration = configuration;
}

@Override
Expand Down Expand Up @@ -120,7 +123,7 @@ public CacheContainerCommandDispatcherFactory getCommandDispatcherFactory() {
}
};

this.sessionManagerFactory = new InfinispanSessionManagerFactory<>(this.configuration, infinispanConfiguration);
this.sessionManagerFactory = new InfinispanSessionManagerFactory<>(this.configuration, this.provider, infinispanConfiguration);
this.accept(this.sessionManagerFactory::close);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ public interface HotRodConfiguration {
URI getUri();
Properties getProperties();
String getTemplateName();
int getExpirationThreadPoolSize();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,30 @@
import org.infinispan.client.hotrod.configuration.TransactionMode;
import org.springframework.beans.factory.InitializingBean;
import org.wildfly.clustering.cache.infinispan.batch.TransactionBatch;
import org.wildfly.clustering.cache.infinispan.remote.RemoteCacheConfiguration;
import org.wildfly.clustering.session.SessionManager;
import org.wildfly.clustering.session.SessionManagerConfiguration;
import org.wildfly.clustering.session.SessionManagerFactory;
import org.wildfly.clustering.session.SessionManagerFactoryConfiguration;
import org.wildfly.clustering.session.infinispan.remote.HotRodSessionFactoryConfiguration;
import org.wildfly.clustering.session.infinispan.remote.HotRodSessionManagerFactory;
import org.wildfly.clustering.session.spec.SessionSpecificationProvider;
import org.wildfly.clustering.spring.context.AutoDestroyBean;

/**
* @author Paul Ferraro
*/
public class HotRodSessionManagerFactoryBean<S, C, L> extends AutoDestroyBean implements SessionManagerFactory<C, Void, TransactionBatch>, InitializingBean {

private final SessionManagerFactoryConfiguration<S, C, L, Void> configuration;
private final SessionManagerFactoryConfiguration<Void> configuration;
private final SessionSpecificationProvider<S, C, L> specProvider;
private final HotRodConfiguration hotrod;
private final RemoteCacheContainerProvider provider;

private SessionManagerFactory<C, Void, TransactionBatch> sessionManagerFactory;

public HotRodSessionManagerFactoryBean(SessionManagerFactoryConfiguration<S, C, L, Void> configuration, HotRodConfiguration hotrod, RemoteCacheContainerProvider provider) {
public HotRodSessionManagerFactoryBean(SessionManagerFactoryConfiguration<Void> configuration, SessionSpecificationProvider<S, C, L> specProvider, HotRodConfiguration hotrod, RemoteCacheContainerProvider provider) {
this.hotrod = hotrod;
this.specProvider = specProvider;
this.provider = provider;
this.configuration = configuration;
}
Expand All @@ -47,26 +50,20 @@ public void afterPropertiesSet() throws Exception {

container.getConfiguration().addRemoteCache(deploymentName, builder -> builder.forceReturnValues(false).nearCacheMode(maxActiveSessions.isEmpty() ? NearCacheMode.DISABLED : NearCacheMode.INVALIDATED).transactionMode(TransactionMode.NONE).templateName(templateName));

int expirationThreadPoolSize = this.hotrod.getExpirationThreadPoolSize();
RemoteCache<?, ?> cache = container.getCache(deploymentName);

cache.start();
this.accept(cache::stop);

HotRodSessionFactoryConfiguration hotrodConfiguration = new HotRodSessionFactoryConfiguration() {
@Override
public int getExpirationThreadPoolSize() {
return expirationThreadPoolSize;
}

RemoteCacheConfiguration hotrodConfiguration = new RemoteCacheConfiguration() {
@SuppressWarnings("unchecked")
@Override
public <CK, CV> RemoteCache<CK, CV> getCache() {
return (RemoteCache<CK, CV>) cache;
}
};

this.sessionManagerFactory = new HotRodSessionManagerFactory<>(this.configuration, hotrodConfiguration);
this.sessionManagerFactory = new HotRodSessionManagerFactory<>(this.configuration, this.specProvider, hotrodConfiguration);
this.accept(this.sessionManagerFactory::close);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ default void setProperties(Properties properties) {
void setProperty(String name, String value);

void setTemplateName(String templateName);

void setExpirationThreadPoolSize(int size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class HotRodConfigurationBean implements MutableHotRodConfiguration {
private URI uri;
private Properties properties = new Properties();
private String templateName = DefaultTemplate.DIST_SYNC.getTemplateName();
private int expirationThreadPoolSize = 16;
private StringValueResolver resolver = value -> value;

@Override
Expand All @@ -43,11 +42,6 @@ public String getTemplateName() {
return this.templateName;
}

@Override
public int getExpirationThreadPoolSize() {
return this.expirationThreadPoolSize;
}

@Override
public void setUri(String uri) {
this.uri = URI.create(this.resolver.resolveStringValue(uri));
Expand All @@ -63,11 +57,6 @@ public void setTemplateName(String templateName) {
this.templateName = this.resolver.resolveStringValue(templateName);
}

@Override
public void setExpirationThreadPoolSize(int size) {
this.expirationThreadPoolSize = size;
}

@Override
public void accept(AnnotationAttributes attributes) {
AnnotationAttributes config = attributes.getAnnotation("config");
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
<version.org.kohsuke.metainf-services>1.11</version.org.kohsuke.metainf-services>

<!-- Runtime dependency versions -->
<version.io.projectreactor.core>3.6.2</version.io.projectreactor.core>
<version.io.projectreactor.core>3.6.3</version.io.projectreactor.core>
<version.org.springframework>6.1.4</version.org.springframework>
<version.org.springframework.security>6.2.2</version.org.springframework.security>
<version.org.springframework.session>3.2.1</version.org.springframework.session>
<version.org.infinispan>14.0.25.Final</version.org.infinispan>
<version.org.jboss.marshalling>2.1.4.Final</version.org.jboss.marshalling>
<version.org.wildfly.clustering>1.0.6.Final</version.org.wildfly.clustering>
<version.org.wildfly.clustering>1.0.7.Final</version.org.wildfly.clustering>

<!-- Test dependency versions -->
<version.org.apache.tomcat>10.1.19</version.org.apache.tomcat>
Expand Down
11 changes: 11 additions & 0 deletions session/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.clustering</groupId>
<artifactId>wildfly-clustering-session-spec-servlet-6.0</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
Expand All @@ -55,6 +59,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.wildfly.clustering</groupId>
<artifactId>wildfly-clustering-session-spi</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpSession;
import jakarta.servlet.http.HttpSessionActivationListener;
import jakarta.servlet.http.HttpSessionBindingEvent;
import jakarta.servlet.http.HttpSessionBindingListener;

Expand All @@ -18,6 +19,7 @@
import org.springframework.session.Session;
import org.wildfly.clustering.cache.batch.Batch;
import org.wildfly.clustering.session.ImmutableSession;
import org.wildfly.clustering.session.spec.SessionSpecificationProvider;
import org.wildfly.clustering.session.user.User;
import org.wildfly.clustering.session.user.UserManager;

Expand All @@ -28,19 +30,21 @@ public class ImmutableSessionDestroyAction<B extends Batch> implements BiConsume

private final ApplicationEventPublisher publisher;
private final ServletContext context;
private final SessionSpecificationProvider<HttpSession, ServletContext, HttpSessionActivationListener> provider;
private final UserConfiguration<B> indexing;

public ImmutableSessionDestroyAction(ApplicationEventPublisher publisher, ServletContext context, UserConfiguration<B> indexing) {
public ImmutableSessionDestroyAction(ApplicationEventPublisher publisher, ServletContext context, SessionSpecificationProvider<HttpSession, ServletContext, HttpSessionActivationListener> provider, UserConfiguration<B> indexing) {
this.publisher = publisher;
this.context = context;
this.provider = provider;
this.indexing = indexing;
}

@Override
public void accept(ImmutableSession session, BiFunction<Object, Session, ApplicationEvent> eventFactory) {
ApplicationEvent event = eventFactory.apply(this, new DistributableImmutableSession(session));
this.publisher.publishEvent(event);
HttpSession httpSession = JakartaServletFacadeProvider.INSTANCE.asSession(session, this.context);
HttpSession httpSession = this.provider.asSession(session, this.context);
for (Map.Entry<String, HttpSessionBindingListener> entry : session.getAttributes().getAttributes(HttpSessionBindingListener.class).entrySet()) {
HttpSessionBindingListener listener = entry.getValue();
try {
Expand Down
Loading

0 comments on commit 8bfd35c

Please sign in to comment.