ping with executor

This commit is contained in:
anhefti 2023-05-31 20:30:12 +02:00
parent 2a16813cd7
commit b344ee22e5
4 changed files with 26 additions and 32 deletions

View file

@ -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();

View file

@ -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()));

View file

@ -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<Void> 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(

View file

@ -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=