revert DeferredResult

This commit is contained in:
anhefti 2023-05-31 12:57:06 +02:00
parent 9c82f20763
commit 62a6db12c6
2 changed files with 103 additions and 226 deletions

View file

@ -101,6 +101,7 @@ public class SEBServer {
protocolHandler.setProcessorCache(-1); protocolHandler.setProcessorCache(-1);
protocolHandler.setTcpNoDelay(true); protocolHandler.setTcpNoDelay(true);
protocolHandler.setThreadPriority(Thread.NORM_PRIORITY + 1); protocolHandler.setThreadPriority(Thread.NORM_PRIORITY + 1);
protocolHandler.setMaxConnections(2000);
if (protocolHandler instanceof Http11NioProtocol) { if (protocolHandler instanceof Http11NioProtocol) {
System.out.println("*************** Http11NioProtocol"); System.out.println("*************** Http11NioProtocol");
((Http11NioProtocol) protocolHandler).setPollerThreadPriority(Thread.MAX_PRIORITY); ((Http11NioProtocol) protocolHandler).setPollerThreadPriority(Thread.MAX_PRIORITY);

View file

@ -36,7 +36,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.api.API;
@ -94,7 +93,7 @@ public class ExamAPI_V1_Controller {
method = RequestMethod.POST, method = RequestMethod.POST,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
public DeferredResult<Collection<RunningExamInfo>> handshakeCreate( public CompletableFuture<Collection<RunningExamInfo>> handshakeCreate(
@RequestParam(name = API.PARAM_INSTITUTION_ID, required = false) final Long instIdRequestParam, @RequestParam(name = API.PARAM_INSTITUTION_ID, required = false) final Long instIdRequestParam,
@RequestParam(name = API.EXAM_API_PARAM_EXAM_ID, required = false) final Long examIdRequestParam, @RequestParam(name = API.EXAM_API_PARAM_EXAM_ID, required = false) final Long examIdRequestParam,
@RequestParam(name = API.EXAM_API_PARAM_CLIENT_ID, required = false) final String clientIdRequestParam, @RequestParam(name = API.EXAM_API_PARAM_CLIENT_ID, required = false) final String clientIdRequestParam,
@ -103,133 +102,69 @@ public class ExamAPI_V1_Controller {
final HttpServletRequest request, final HttpServletRequest request,
final HttpServletResponse response) { final HttpServletResponse response) {
final DeferredResult<Collection<RunningExamInfo>> deferredResult = new DeferredResult<>(); return CompletableFuture.supplyAsync(
this.executor.execute(() -> { () -> {
final POSTMapper mapper = new POSTMapper(formParams, request.getQueryString());
final String remoteAddr = this.getClientAddress(request); final POSTMapper mapper = new POSTMapper(formParams, request.getQueryString());
final Long institutionId = (instIdRequestParam != null)
? instIdRequestParam
: mapper.getLong(API.PARAM_INSTITUTION_ID);
final Long examId = (examIdRequestParam != null)
? examIdRequestParam
: mapper.getLong(API.EXAM_API_PARAM_EXAM_ID);
final String clientId = (clientIdRequestParam != null)
? clientIdRequestParam
: mapper.getString(API.EXAM_API_PARAM_CLIENT_ID);
// Create and get new ClientConnection if all integrity checks passes final String remoteAddr = this.getClientAddress(request);
final ClientConnection clientConnection = this.sebClientConnectionService final Long institutionId = (instIdRequestParam != null)
.createClientConnection( ? instIdRequestParam
principal, : mapper.getLong(API.PARAM_INSTITUTION_ID);
institutionId, final Long examId = (examIdRequestParam != null)
remoteAddr, ? examIdRequestParam
mapper.getString(API.EXAM_API_PARAM_SEB_VERSION), : mapper.getLong(API.EXAM_API_PARAM_EXAM_ID);
mapper.getString(API.EXAM_API_PARAM_SEB_OS_NAME), final String clientId = (clientIdRequestParam != null)
mapper.getString(API.EXAM_API_PARAM_SEB_MACHINE_NAME), ? clientIdRequestParam
examId, : mapper.getString(API.EXAM_API_PARAM_CLIENT_ID);
clientId)
.getOrThrow();
response.setHeader( // Create and get new ClientConnection if all integrity checks passes
API.EXAM_API_SEB_CONNECTION_TOKEN, final ClientConnection clientConnection = this.sebClientConnectionService
clientConnection.connectionToken); .createClientConnection(
principal,
institutionId,
remoteAddr,
mapper.getString(API.EXAM_API_PARAM_SEB_VERSION),
mapper.getString(API.EXAM_API_PARAM_SEB_OS_NAME),
mapper.getString(API.EXAM_API_PARAM_SEB_MACHINE_NAME),
examId,
clientId)
.getOrThrow();
// Crate list of running exams response.setHeader(
List<RunningExamInfo> result; API.EXAM_API_SEB_CONNECTION_TOKEN,
if (examId == null) { clientConnection.connectionToken);
result = this.examSessionService.getRunningExamsForInstitution(institutionId)
.getOrThrow()
.stream()
.map(this::createRunningExamInfo)
.filter(this::checkConsistency)
.collect(Collectors.toList());
} else {
final Exam exam = this.examSessionService // Crate list of running exams
.getExamDAO() List<RunningExamInfo> result;
.byPK(examId) if (examId == null) {
.getOrThrow(); result = this.examSessionService.getRunningExamsForInstitution(institutionId)
.getOrThrow()
.stream()
.map(this::createRunningExamInfo)
.filter(this::checkConsistency)
.collect(Collectors.toList());
} else {
result = Arrays.asList(createRunningExamInfo(exam)); final Exam exam = this.examSessionService
processASKSalt(response, clientConnection); .getExamDAO()
processAlternativeBEK(response, clientConnection.examId); .byPK(examId)
} .getOrThrow();
if (result.isEmpty()) { result = Arrays.asList(createRunningExamInfo(exam));
log.warn( processASKSalt(response, clientConnection);
"There are no currently running exams for institution: {}. SEB connection creation denied", processAlternativeBEK(response, clientConnection.examId);
institutionId); }
}
deferredResult.setResult(result); if (result.isEmpty()) {
}); log.warn(
"There are no currently running exams for institution: {}. SEB connection creation denied",
institutionId);
}
return deferredResult; return result;
},
// return CompletableFuture.supplyAsync( this.executor);
// () -> {
//
// final POSTMapper mapper = new POSTMapper(formParams, request.getQueryString());
//
// final String remoteAddr = this.getClientAddress(request);
// final Long institutionId = (instIdRequestParam != null)
// ? instIdRequestParam
// : mapper.getLong(API.PARAM_INSTITUTION_ID);
// final Long examId = (examIdRequestParam != null)
// ? examIdRequestParam
// : mapper.getLong(API.EXAM_API_PARAM_EXAM_ID);
// final String clientId = (clientIdRequestParam != null)
// ? clientIdRequestParam
// : mapper.getString(API.EXAM_API_PARAM_CLIENT_ID);
//
// // Create and get new ClientConnection if all integrity checks passes
// final ClientConnection clientConnection = this.sebClientConnectionService
// .createClientConnection(
// principal,
// institutionId,
// remoteAddr,
// mapper.getString(API.EXAM_API_PARAM_SEB_VERSION),
// mapper.getString(API.EXAM_API_PARAM_SEB_OS_NAME),
// mapper.getString(API.EXAM_API_PARAM_SEB_MACHINE_NAME),
// examId,
// clientId)
// .getOrThrow();
//
// response.setHeader(
// API.EXAM_API_SEB_CONNECTION_TOKEN,
// clientConnection.connectionToken);
//
// // Crate list of running exams
// List<RunningExamInfo> result;
// if (examId == null) {
// result = this.examSessionService.getRunningExamsForInstitution(institutionId)
// .getOrThrow()
// .stream()
// .map(this::createRunningExamInfo)
// .filter(this::checkConsistency)
// .collect(Collectors.toList());
// } else {
//
// final Exam exam = this.examSessionService
// .getExamDAO()
// .byPK(examId)
// .getOrThrow();
//
// result = Arrays.asList(createRunningExamInfo(exam));
// processASKSalt(response, clientConnection);
// processAlternativeBEK(response, clientConnection.examId);
// }
//
// if (result.isEmpty()) {
// log.warn(
// "There are no currently running exams for institution: {}. SEB connection creation denied",
// institutionId);
// }
//
// return result;
// },
// this.executor);
} }
private boolean checkConsistency(final RunningExamInfo info) { private boolean checkConsistency(final RunningExamInfo info) {
@ -248,7 +183,7 @@ public class ExamAPI_V1_Controller {
path = API.EXAM_API_HANDSHAKE_ENDPOINT, path = API.EXAM_API_HANDSHAKE_ENDPOINT,
method = RequestMethod.PATCH, method = RequestMethod.PATCH,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public DeferredResult<Void> handshakeUpdate( public CompletableFuture<Void> handshakeUpdate(
@RequestHeader(name = API.EXAM_API_SEB_CONNECTION_TOKEN, required = true) final String connectionToken, @RequestHeader(name = API.EXAM_API_SEB_CONNECTION_TOKEN, required = true) final String connectionToken,
@RequestParam(name = API.EXAM_API_PARAM_EXAM_ID, required = false) final Long examId, @RequestParam(name = API.EXAM_API_PARAM_EXAM_ID, required = false) final Long examId,
@RequestParam(name = API.EXAM_API_USER_SESSION_ID, required = false) final String userSessionId, @RequestParam(name = API.EXAM_API_USER_SESSION_ID, required = false) final String userSessionId,
@ -263,71 +198,39 @@ public class ExamAPI_V1_Controller {
final HttpServletRequest request, final HttpServletRequest request,
final HttpServletResponse response) { final HttpServletResponse response) {
final DeferredResult<Void> deferredResult = new DeferredResult<>(); return CompletableFuture.runAsync(
this.executor.execute(() -> { () -> {
{
final String remoteAddr = this.getClientAddress(request); final String remoteAddr = this.getClientAddress(request);
final Long institutionId = getInstitutionId(principal); final Long institutionId = getInstitutionId(principal);
final ClientConnection clientConnection = this.sebClientConnectionService final ClientConnection clientConnection = this.sebClientConnectionService
.updateClientConnection( .updateClientConnection(
connectionToken, connectionToken,
institutionId, institutionId,
examId, examId,
remoteAddr, remoteAddr,
sebVersion, sebVersion,
sebOSName, sebOSName,
sebMachinName, sebMachinName,
userSessionId, userSessionId,
clientId, clientId,
browserSignatureKey) browserSignatureKey)
.getOrThrow(); .getOrThrow();
if (clientConnection.examId != null) { if (clientConnection.examId != null) {
processASKSalt(response, clientConnection); processASKSalt(response, clientConnection);
processAlternativeBEK(response, clientConnection.examId); processAlternativeBEK(response, clientConnection.examId);
} }
},
deferredResult.setResult(null); this.executor);
}
});
return deferredResult;
// return CompletableFuture.runAsync(
// () -> {
//
// final String remoteAddr = this.getClientAddress(request);
// final Long institutionId = getInstitutionId(principal);
//
// final ClientConnection clientConnection = this.sebClientConnectionService
// .updateClientConnection(
// connectionToken,
// institutionId,
// examId,
// remoteAddr,
// sebVersion,
// sebOSName,
// sebMachinName,
// userSessionId,
// clientId,
// browserSignatureKey)
// .getOrThrow();
//
// if (clientConnection.examId != null) {
// processASKSalt(response, clientConnection);
// processAlternativeBEK(response, clientConnection.examId);
// }
// },
// this.executor);
} }
@RequestMapping( @RequestMapping(
path = API.EXAM_API_HANDSHAKE_ENDPOINT, path = API.EXAM_API_HANDSHAKE_ENDPOINT,
method = RequestMethod.PUT, method = RequestMethod.PUT,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public DeferredResult<Void> handshakeEstablish( public CompletableFuture<Void> handshakeEstablish(
@RequestHeader(name = API.EXAM_API_SEB_CONNECTION_TOKEN, required = true) final String connectionToken, @RequestHeader(name = API.EXAM_API_SEB_CONNECTION_TOKEN, required = true) final String connectionToken,
@RequestParam(name = API.EXAM_API_PARAM_EXAM_ID, required = false) final Long examId, @RequestParam(name = API.EXAM_API_PARAM_EXAM_ID, required = false) final Long examId,
@RequestParam(name = API.EXAM_API_USER_SESSION_ID, required = false) final String userSessionId, @RequestParam(name = API.EXAM_API_USER_SESSION_ID, required = false) final String userSessionId,
@ -342,58 +245,31 @@ public class ExamAPI_V1_Controller {
final HttpServletRequest request, final HttpServletRequest request,
final HttpServletResponse response) { final HttpServletResponse response) {
final DeferredResult<Void> deferredResult = new DeferredResult<>(); return CompletableFuture.runAsync(
this.executor.execute(() -> { () -> {
final String remoteAddr = this.getClientAddress(request); final String remoteAddr = this.getClientAddress(request);
final Long institutionId = getInstitutionId(principal); final Long institutionId = getInstitutionId(principal);
final ClientConnection clientConnection = this.sebClientConnectionService final ClientConnection clientConnection = this.sebClientConnectionService
.establishClientConnection( .establishClientConnection(
connectionToken, connectionToken,
institutionId, institutionId,
examId, examId,
remoteAddr, remoteAddr,
sebVersion, sebVersion,
sebOSName, sebOSName,
sebMachinName, sebMachinName,
userSessionId, userSessionId,
clientId, clientId,
browserSignatureKey) browserSignatureKey)
.getOrThrow(); .getOrThrow();
if (clientConnection.examId != null) { if (clientConnection.examId != null) {
processAlternativeBEK(response, clientConnection.examId); processAlternativeBEK(response, clientConnection.examId);
} }
},
deferredResult.setResult(null); this.executor);
});
return deferredResult;
// return CompletableFuture.runAsync(
// () -> {
//
// final String remoteAddr = this.getClientAddress(request);
// final Long institutionId = getInstitutionId(principal);
//
// final ClientConnection clientConnection = this.sebClientConnectionService
// .establishClientConnection(
// connectionToken,
// institutionId,
// examId,
// remoteAddr,
// sebVersion,
// sebOSName,
// sebMachinName,
// userSessionId,
// clientId,
// browserSignatureKey)
// .getOrThrow();
//
// if (clientConnection.examId != null) {
// processAlternativeBEK(response, clientConnection.examId);
// }
// },
// this.executor);
} }
@RequestMapping( @RequestMapping(