try to improve ping performance

This commit is contained in:
anhefti 2020-02-26 12:42:05 +01:00
parent b774235903
commit 379c786064

View file

@ -279,47 +279,25 @@ 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_UTF8_VALUE) produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public CompletableFuture<ResponseEntity<String>> ping( public void ping(
@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_PING_TIMESTAMP, required = true) final long timestamp, @RequestParam(name = API.EXAM_API_PING_TIMESTAMP, required = true) final long timestamp,
@RequestParam(name = API.EXAM_API_PING_NUMBER, required = false) final int pingNumber) { @RequestParam(name = API.EXAM_API_PING_NUMBER, required = false) final int pingNumber,
final HttpServletResponse response) {
return CompletableFuture.supplyAsync( final String instruction = this.sebClientConnectionService
() -> {
final String notifyPing = this.sebClientConnectionService
.notifyPing(connectionToken, timestamp, pingNumber); .notifyPing(connectionToken, timestamp, pingNumber);
if (notifyPing == null) {
return EMPTY_PING_RESPONSE; if (instruction == null) {
return;
} }
return ResponseEntity try {
.ok() response.getOutputStream().write(instruction.getBytes());
.body(notifyPing); } catch (final IOException e) {
}, log.error("Failed to send instruction as response: {}", connectionToken, e);
this.executor); }
} }
// @RequestMapping(
// path = API.EXAM_API_PING_ENDPOINT,
// method = RequestMethod.POST,
// consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
// produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
// public ResponseEntity<String> ping(
// @RequestHeader(name = API.EXAM_API_SEB_CONNECTION_TOKEN, required = true) final String connectionToken,
// @RequestParam(name = API.EXAM_API_PING_TIMESTAMP, required = true) final long timestamp,
// @RequestParam(name = API.EXAM_API_PING_NUMBER, required = false) final int pingNumber) {
//
// final String instruction = this.sebClientConnectionService
// .notifyPing(connectionToken, timestamp, pingNumber);
//
// if (instruction == null) {
// return EMPTY_PING_RESPONSE;
// }
//
// return ResponseEntity
// .ok()
// .body(instruction);
// }
@RequestMapping( @RequestMapping(
path = API.EXAM_API_EVENT_ENDPOINT, path = API.EXAM_API_EVENT_ENDPOINT,