mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: improved concurrent Session initializaion
parent
9dd62009fb
commit
91d24ccd42
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue