From b344ee22e5f544f812660ee43382ce729663b579 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 31 May 2023 20:30:12 +0200 Subject: [PATCH] ping with executor --- .../gbl/async/AsyncServiceSpringConfig.java | 9 ---- .../sebserver/webservice/WebserviceInfo.java | 2 +- .../weblayer/api/ExamAPI_V1_Controller.java | 45 ++++++++++--------- .../config/application-ws.properties | 2 +- 4 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java b/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java index dcf25d9d..4595c63f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java @@ -74,15 +74,6 @@ public class AsyncServiceSpringConfig implements AsyncConfigurer { return executor; } -// @Bean -// public ThreadPoolTaskScheduler threadPoolTaskScheduler() { -// final ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); -// threadPoolTaskScheduler.setPoolSize(5); -// threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(false); -// threadPoolTaskScheduler.setThreadNamePrefix("SEB-Server-BgTask-"); -// return threadPoolTaskScheduler; -// } - @Override public Executor getAsyncExecutor() { return threadPoolTaskExecutor(); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceInfo.java b/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceInfo.java index 3be4b33c..340cca32 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceInfo.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceInfo.java @@ -101,7 +101,7 @@ public class WebserviceInfo { this.distributedUpdateInterval = environment.getProperty( "sebserver.webservice.distributed.updateInterval", Long.class, - 3000L); + 2000L); this.activeProfiles = new HashSet<>(Arrays.asList(environment.getActiveProfiles())); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java index 04a16689..d59a404f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java @@ -325,29 +325,32 @@ public class ExamAPI_V1_Controller { method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public void ping(final HttpServletRequest request, final HttpServletResponse response) { + public CompletableFuture ping(final HttpServletRequest request, final HttpServletResponse response) { + return CompletableFuture.runAsync( + () -> { + final String connectionToken = request.getHeader(API.EXAM_API_SEB_CONNECTION_TOKEN); + //final String pingNumString = request.getParameter(API.EXAM_API_PING_NUMBER); + final String instructionConfirm = request.getParameter(API.EXAM_API_PING_INSTRUCTION_CONFIRM); - final String connectionToken = request.getHeader(API.EXAM_API_SEB_CONNECTION_TOKEN); - //final String pingNumString = request.getParameter(API.EXAM_API_PING_NUMBER); - final String instructionConfirm = request.getParameter(API.EXAM_API_PING_INSTRUCTION_CONFIRM); + final String instruction = this.sebClientSessionService + .notifyPing( + connectionToken, + 0, + 0, + instructionConfirm); - final String instruction = this.sebClientSessionService - .notifyPing( - connectionToken, - 0, - 0, - instructionConfirm); - - if (instruction == null) { - response.setStatus(HttpStatus.NO_CONTENT.value()); - } else { - try { - response.setStatus(HttpStatus.OK.value()); - response.getOutputStream().write(instruction.getBytes(StandardCharsets.UTF_8)); - } catch (final IOException e) { - log.error("Failed to send instruction as response: {}", connectionToken, e); - } - } + if (instruction == null) { + response.setStatus(HttpStatus.NO_CONTENT.value()); + } else { + try { + response.setStatus(HttpStatus.OK.value()); + response.getOutputStream().write(instruction.getBytes(StandardCharsets.UTF_8)); + } catch (final IOException e) { + log.error("Failed to send instruction as response: {}", connectionToken, e); + } + } + }, + this.executor); } @RequestMapping( diff --git a/src/main/resources/config/application-ws.properties b/src/main/resources/config/application-ws.properties index acafe27a..0cab6d27 100644 --- a/src/main/resources/config/application-ws.properties +++ b/src/main/resources/config/application-ws.properties @@ -40,7 +40,7 @@ sebserver.webservice.internalSecret=${sebserver.password} ### webservice networking sebserver.webservice.forceMaster=false sebserver.webservice.distributed=false -sebserver.webservice.distributed.updateInterval=3000 +sebserver.webservice.distributed.updateInterval=2000 sebserver.webservice.http.external.scheme=https sebserver.webservice.http.external.servername= sebserver.webservice.http.external.port=