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");
|
||||
* 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 reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import org.springframework.session.events.SessionDeletedEvent;
|
||||
import org.springframework.session.events.SessionExpiredEvent;
|
||||
@@ -37,6 +38,7 @@ import org.springframework.util.Assert;
|
||||
* </p>
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author Yanming Zhou
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ReactiveMapSessionRepository implements ReactiveSessionRepository<MapSession> {
|
||||
@@ -98,11 +100,17 @@ public class ReactiveMapSessionRepository implements ReactiveSessionRepository<M
|
||||
|
||||
@Override
|
||||
public Mono<MapSession> createSession() {
|
||||
return Mono.defer(() -> {
|
||||
MapSession result = new MapSession(this.sessionIdGenerator);
|
||||
result.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
|
||||
return Mono.just(result);
|
||||
});
|
||||
// @formatter:off
|
||||
return Mono.fromSupplier(() -> this.sessionIdGenerator.generate())
|
||||
.subscribeOn(Schedulers.boundedElastic())
|
||||
.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