openvidu-server: improved concurrent Session initializaion

pull/651/head
pabloFuente 2021-09-10 13:10:52 +02:00
parent 9dd62009fb
commit 91d24ccd42
2 changed files with 18 additions and 7 deletions

View File

@ -304,18 +304,25 @@ public abstract class SessionManager {
return null;
}
/**
* @return null if concurrent storing of session
*/
public Session storeSessionNotActive(String sessionId, SessionProperties sessionProperties) {
Session sessionNotActive = this
.storeSessionNotActive(new Session(sessionId, sessionProperties, openviduConfig, recordingManager));
sessionEventsHandler.onSessionCreated(sessionNotActive);
return sessionNotActive;
if (sessionNotActive == null) {
return null;
} else {
sessionEventsHandler.onSessionCreated(sessionNotActive);
return sessionNotActive;
}
}
public Session storeSessionNotActive(Session sessionNotActive) {
final String sessionId = sessionNotActive.getSessionId();
if (this.sessionsNotActive.putIfAbsent(sessionId, sessionNotActive) != null) {
log.warn("Concurrent initialization of session {}", sessionId);
return this.sessionsNotActive.get(sessionId);
return null;
}
this.initializeCollections(sessionId);
return sessionNotActive;

View File

@ -121,11 +121,15 @@ public class SessionRestController {
}
Session sessionNotActive = sessionManager.storeSessionNotActive(sessionId, sessionProperties);
log.info("New session {} created {}", sessionId, this.sessionManager.getSessionsWithNotActive().stream()
.map(Session::getSessionId).collect(Collectors.toList()).toString());
return new ResponseEntity<>(sessionNotActive.toJson(false, false).toString(), RestUtils.getResponseHeaders(),
HttpStatus.OK);
if (sessionNotActive == null) {
return new ResponseEntity<>(HttpStatus.CONFLICT);
} else {
log.info("New session {} created {}", sessionId, this.sessionManager.getSessionsWithNotActive().stream()
.map(Session::getSessionId).collect(Collectors.toList()).toString());
return new ResponseEntity<>(sessionNotActive.toJson(false, false).toString(),
RestUtils.getResponseHeaders(), HttpStatus.OK);
}
}
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET)