Skip to content

Commit

Permalink
➕ caching misdepends session #221
Browse files Browse the repository at this point in the history
  • Loading branch information
trydofor committed Mar 18, 2024
1 parent 3da942b commit e317192
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 28 deletions.
2 changes: 1 addition & 1 deletion observe/docs
5 changes: 0 additions & 5 deletions wings/slardar-hazel-caching/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,5 @@
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
</dependency>
<!-- session-->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-hazelcast</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package pro.fessional.wings.slardar.spring.bean;

import com.hazelcast.config.GlobalSerializerConfig;
import com.hazelcast.config.SerializationConfig;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastConfigCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import pro.fessional.wings.silencer.spring.boot.ConditionalWingsEnabled;
import pro.fessional.wings.slardar.cache.hazelcast.WingsHazelcastCacheCustomizer;
import pro.fessional.wings.slardar.serialize.KryoHazelcast;
import pro.fessional.wings.slardar.spring.prop.SlardarCacheProp;
import pro.fessional.wings.slardar.spring.prop.SlardarEnabledProp;

Expand Down Expand Up @@ -39,4 +42,23 @@ public HazelcastConfigCustomizer wingsHazelcastCacheCustomizer(SlardarCacheProp
log.info("SlardarHazelCaching spring-bean wingsHazelcastCacheCustomizer");
return new WingsHazelcastCacheCustomizer(conf);
}

@Bean
@ConditionalWingsEnabled
public HazelcastConfigCustomizer wingsHazelcastGlobalSerializer() {
log.info("SlardarHazelCaching spring-bean wingsHazelcastGlobalSerializer");
return config -> {
SerializationConfig serialization = config.getSerializationConfig();
GlobalSerializerConfig gs = serialization.getGlobalSerializerConfig();
if (gs == null) {
GlobalSerializerConfig ngs = new GlobalSerializerConfig();
ngs.setClassName(KryoHazelcast.class.getName());
serialization.setGlobalSerializerConfig(ngs);
log.info("Wings hazelcast setGlobalSerializerConfig class=KryoHazelcast");
}
else {
log.info("Wings hazelcast setGlobalSerializerConfig skipped, current=" + gs);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@
<serialize-keys>true</serialize-keys>
<local-update-policy>INVALIDATE</local-update-policy>
</near-cache>
<serialization>
<serializers>
<!-- need UnmodifiableCollectionsSerializer -->
<global-serializer>pro.fessional.wings.slardar.serialize.KryoHazelcast</global-serializer>
<!-- spring FindByIndexNameSessionRepository -->
<serializer class-name="org.springframework.session.hazelcast.HazelcastSessionSerializer"
type-class="org.springframework.session.MapSession"/>
</serializers>
</serialization>
<user-code-deployment enabled="true">
<!-- <jarPaths>-->
<!-- <jarPath>example.jar</jarPath>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@
</near-cache>
</map>

<serialization>
<serializers>
<!-- need UnmodifiableCollectionsSerializer -->
<global-serializer>pro.fessional.wings.slardar.serialize.KryoHazelcast</global-serializer>
<!-- spring FindByIndexNameSessionRepository -->
<serializer class-name="org.springframework.session.hazelcast.HazelcastSessionSerializer"
type-class="org.springframework.session.MapSession"/>
</serializers>
</serialization>

<!-- HazelcastSerializationException: java.lang.ClassNotFoundException -->
<user-code-deployment enabled="true">
<class-cache-mode>ETERNAL</class-cache-mode>
Expand Down
12 changes: 9 additions & 3 deletions wings/slardar-hazel-session/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
<dependencies>
<dependency>
<groupId>pro.fessional.wings</groupId>
<artifactId>slardar-hazel-caching</artifactId>
<artifactId>slardar-webmvc</artifactId>
</dependency>
<!-- session-->
<dependency>
<groupId>pro.fessional.wings</groupId>
<artifactId>slardar-webmvc</artifactId>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-hazelcast</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>pro.fessional.wings</groupId>
<artifactId>slardar-hazel-caching</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package pro.fessional.wings.slardar.spring.bean;

import com.hazelcast.config.SerializationConfig;
import com.hazelcast.config.SerializerConfig;
import com.hazelcast.core.HazelcastInstance;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastConfigCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
import org.springframework.session.hazelcast.HazelcastSessionSerializer;
import org.springframework.session.security.SpringSessionBackedSessionRegistry;
import pro.fessional.wings.silencer.spring.boot.ConditionalWingsEnabled;
import pro.fessional.wings.slardar.session.HazelcastSessionHelper;
Expand Down Expand Up @@ -39,4 +44,37 @@ public HazelcastSessionHelper wingsSessionHelper(
log.info("SlardarHazelSession spring-bean wingsSessionHelper");
return new HazelcastSessionHelper(sessionRepository, hazelcastInstance, mapName);
}

/**
* spring FindByIndexNameSessionRepository
*/
@Bean
@ConditionalWingsEnabled
public HazelcastConfigCustomizer wingsHazelcastSessionSerializer() {
log.info("SlardarHazelSession spring-bean wingsHazelcastSessionSerializer");
return config -> {
String msc = MapSession.class.getName();
SerializationConfig serialization = config.getSerializationConfig();
for (SerializerConfig ss : serialization.getSerializerConfigs()) {
String tcn = ss.getTypeClassName();
if (tcn == null) {
Class<?> tc = ss.getTypeClass();
if (tc != null) {
tcn = tc.getName();
}
}

if (msc.equals(tcn)) {
log.warn("Wings hazelcast addSerializerConfig skipped, current=" + ss);
return;
}
}

log.info("Wings hazelcast addSerializerConfig type=MapSession");
SerializerConfig sessionSerializer = new SerializerConfig();
sessionSerializer.setClass(HazelcastSessionSerializer.class);
sessionSerializer.setTypeClass(MapSession.class);
serialization.addSerializerConfig(sessionSerializer);
};
}
}
4 changes: 4 additions & 0 deletions wings/slardar-sprint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<description>Integration of WebMvc/hazelcast/security-conf/admin/actuator</description>

<dependencies>
<dependency>
<groupId>pro.fessional.wings</groupId>
<artifactId>slardar-hazel-caching</artifactId>
</dependency>
<dependency>
<groupId>pro.fessional.wings</groupId>
<artifactId>slardar-hazel-session</artifactId>
Expand Down

0 comments on commit e317192

Please sign in to comment.