Made monitoring instruction propagation async to not block the request
This commit is contained in:
parent
da431da9b4
commit
fda22b5b7e
3 changed files with 28 additions and 4 deletions
|
@ -14,8 +14,14 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
|
||||||
|
import ch.ethz.seb.sebserver.SEBServerInitEvent;
|
||||||
import ch.ethz.seb.sebserver.gbl.Constants;
|
import ch.ethz.seb.sebserver.gbl.Constants;
|
||||||
|
import ch.ethz.seb.sebserver.gbl.async.AsyncServiceSpringConfig;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientInstruction;
|
import ch.ethz.seb.sebserver.gbl.model.session.ClientInstruction;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientInstruction.InstructionType;
|
import ch.ethz.seb.sebserver.gbl.model.session.ClientInstruction.InstructionType;
|
||||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||||
|
@ -27,11 +33,31 @@ import ch.ethz.seb.sebserver.webservice.WebserviceInfo;
|
||||||
* If there is an instruction in the queue for a specified SEB Client. */
|
* If there is an instruction in the queue for a specified SEB Client. */
|
||||||
public interface SEBClientInstructionService {
|
public interface SEBClientInstructionService {
|
||||||
|
|
||||||
|
static final Logger log = LoggerFactory.getLogger(SEBClientInstructionService.class);
|
||||||
|
|
||||||
/** Get the underling WebserviceInfo
|
/** Get the underling WebserviceInfo
|
||||||
*
|
*
|
||||||
* @return the underling WebserviceInfo */
|
* @return the underling WebserviceInfo */
|
||||||
WebserviceInfo getWebserviceInfo();
|
WebserviceInfo getWebserviceInfo();
|
||||||
|
|
||||||
|
/** This is called from the SEB Server initializer to initialize this service.
|
||||||
|
* Do not use this directly. */
|
||||||
|
@EventListener(SEBServerInitEvent.class)
|
||||||
|
void init();
|
||||||
|
|
||||||
|
/** Used to register a SEB client instruction for one or more active client connections
|
||||||
|
* within an other background thread. This is none-blocking.
|
||||||
|
*
|
||||||
|
* @param clientInstruction the ClientInstruction instance to register
|
||||||
|
* @return A Result refer to a void marker or to an error if happened */
|
||||||
|
@Async(AsyncServiceSpringConfig.EXECUTOR_BEAN_NAME)
|
||||||
|
default void registerInstructionAsync(final ClientInstruction clientInstruction) {
|
||||||
|
registerInstruction(clientInstruction, false)
|
||||||
|
.onError(error -> log.error("Failed to register client instruction asynchronously: {}",
|
||||||
|
clientInstruction,
|
||||||
|
error));
|
||||||
|
}
|
||||||
|
|
||||||
/** Used to register a SEB client instruction for one or more active client connections
|
/** Used to register a SEB client instruction for one or more active client connections
|
||||||
*
|
*
|
||||||
* @param clientInstruction the ClientInstruction instance to register
|
* @param clientInstruction the ClientInstruction instance to register
|
||||||
|
|
|
@ -22,11 +22,9 @@ import org.joda.time.DateTimeZone;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.context.event.EventListener;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import ch.ethz.seb.sebserver.SEBServerInit;
|
import ch.ethz.seb.sebserver.SEBServerInit;
|
||||||
import ch.ethz.seb.sebserver.SEBServerInitEvent;
|
|
||||||
import ch.ethz.seb.sebserver.gbl.Constants;
|
import ch.ethz.seb.sebserver.gbl.Constants;
|
||||||
import ch.ethz.seb.sebserver.gbl.api.JSONMapper;
|
import ch.ethz.seb.sebserver.gbl.api.JSONMapper;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
|
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
|
||||||
|
@ -80,7 +78,7 @@ public class SEBClientInstructionServiceImpl implements SEBClientInstructionServ
|
||||||
return this.webserviceInfo;
|
return this.webserviceInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(SEBServerInitEvent.class)
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
SEBServerInit.INIT_LOGGER.info("------>");
|
SEBServerInit.INIT_LOGGER.info("------>");
|
||||||
SEBServerInit.INIT_LOGGER.info("------> Run SEBInstructionService...");
|
SEBServerInit.INIT_LOGGER.info("------> Run SEBInstructionService...");
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class ExamMonitoringController {
|
||||||
@Valid @RequestBody final ClientInstruction clientInstruction) {
|
@Valid @RequestBody final ClientInstruction clientInstruction) {
|
||||||
|
|
||||||
checkPrivileges(institutionId, examId);
|
checkPrivileges(institutionId, examId);
|
||||||
this.sebClientInstructionService.registerInstruction(clientInstruction);
|
this.sebClientInstructionService.registerInstructionAsync(clientInstruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(
|
@RequestMapping(
|
||||||
|
|
Loading…
Reference in a new issue