Avoid blocking on session id generation
see https://github.com/spring-projects/spring-session/issues/2393
This commit is contained in:
committed by
Marcus Hert Da Coregio
parent
21ab473b2a
commit
b4e9af9ca4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2022 the original author or authors.
|
* Copyright 2014-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,6 +20,7 @@ import java.time.Duration;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
import reactor.core.scheduler.Schedulers;
|
||||||
|
|
||||||
import org.springframework.session.events.SessionDeletedEvent;
|
import org.springframework.session.events.SessionDeletedEvent;
|
||||||
import org.springframework.session.events.SessionExpiredEvent;
|
import org.springframework.session.events.SessionExpiredEvent;
|
||||||
@@ -37,6 +38,7 @@ import org.springframework.util.Assert;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
|
* @author Yanming Zhou
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class ReactiveMapSessionRepository implements ReactiveSessionRepository<MapSession> {
|
public class ReactiveMapSessionRepository implements ReactiveSessionRepository<MapSession> {
|
||||||
@@ -98,11 +100,17 @@ public class ReactiveMapSessionRepository implements ReactiveSessionRepository<M
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<MapSession> createSession() {
|
public Mono<MapSession> createSession() {
|
||||||
return Mono.defer(() -> {
|
// @formatter:off
|
||||||
MapSession result = new MapSession(this.sessionIdGenerator);
|
return Mono.fromSupplier(() -> this.sessionIdGenerator.generate())
|
||||||
result.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
|
.subscribeOn(Schedulers.boundedElastic())
|
||||||
return Mono.just(result);
|
.publishOn(Schedulers.parallel())
|
||||||
});
|
.map((sessionId) -> {
|
||||||
|
MapSession result = new MapSession(sessionId);
|
||||||
|
result.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
|
||||||
|
result.setSessionIdGenerator(this.sessionIdGenerator);
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user