Skip to content

Commit

Permalink
Avoid blocking on session id generation
Browse files Browse the repository at this point in the history
see #2393
  • Loading branch information
quaff authored and marcusdacoregio committed Aug 12, 2023
1 parent 21ab473 commit b4e9af9
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,6 +20,7 @@
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;
Expand All @@ -37,6 +38,7 @@
* </p>
*
* @author Rob Winch
* @author Yanming Zhou
* @since 2.0
*/
public class ReactiveMapSessionRepository implements ReactiveSessionRepository<MapSession> {
Expand Down Expand Up @@ -98,11 +100,17 @@ public Mono<Void> deleteById(String id) {

@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
}

/**
Expand Down

0 comments on commit b4e9af9

Please sign in to comment.