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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return null if concurrent storing of session
|
||||||
|
*/
|
||||||
public Session storeSessionNotActive(String sessionId, SessionProperties sessionProperties) {
|
public Session storeSessionNotActive(String sessionId, SessionProperties sessionProperties) {
|
||||||
Session sessionNotActive = this
|
Session sessionNotActive = this
|
||||||
.storeSessionNotActive(new Session(sessionId, sessionProperties, openviduConfig, recordingManager));
|
.storeSessionNotActive(new Session(sessionId, sessionProperties, openviduConfig, recordingManager));
|
||||||
sessionEventsHandler.onSessionCreated(sessionNotActive);
|
if (sessionNotActive == null) {
|
||||||
return sessionNotActive;
|
return null;
|
||||||
|
} else {
|
||||||
|
sessionEventsHandler.onSessionCreated(sessionNotActive);
|
||||||
|
return sessionNotActive;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Session storeSessionNotActive(Session sessionNotActive) {
|
public Session storeSessionNotActive(Session sessionNotActive) {
|
||||||
final String sessionId = sessionNotActive.getSessionId();
|
final String sessionId = sessionNotActive.getSessionId();
|
||||||
if (this.sessionsNotActive.putIfAbsent(sessionId, sessionNotActive) != null) {
|
if (this.sessionsNotActive.putIfAbsent(sessionId, sessionNotActive) != null) {
|
||||||
log.warn("Concurrent initialization of session {}", sessionId);
|
log.warn("Concurrent initialization of session {}", sessionId);
|
||||||
return this.sessionsNotActive.get(sessionId);
|
return null;
|
||||||
}
|
}
|
||||||
this.initializeCollections(sessionId);
|
this.initializeCollections(sessionId);
|
||||||
return sessionNotActive;
|
return sessionNotActive;
|
||||||
|
|
|
@ -121,11 +121,15 @@ public class SessionRestController {
|
||||||
}
|
}
|
||||||
|
|
||||||
Session sessionNotActive = sessionManager.storeSessionNotActive(sessionId, sessionProperties);
|
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(),
|
if (sessionNotActive == null) {
|
||||||
HttpStatus.OK);
|
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)
|
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET)
|
||||||
|
|
Loading…
Reference in New Issue