diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/PingHandlingStrategy.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/PingHandlingStrategy.java deleted file mode 100644 index 54051742..00000000 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/PingHandlingStrategy.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package ch.ethz.seb.sebserver.webservice.servicelayer.session; - -/** Defines a SEB Client connection ping handling strategy. - * The strategy may be different in case of stand-alone or distributed SEB Server setup. */ -public interface PingHandlingStrategy { - - /** Initializes the ping handling for a new SEB Connection. - * - * @param connectionId the SEB Connection identifier - * @param connectionToken the SEB Connection token */ - void initForConnection(Long connectionId, String connectionToken); - - /** Used to notify a ping from a SEB Client connection. - * - * @param connectionToken the SEB Client connection token - * @param timestamp the ping time-stamp - * @param pingNumber the ping number */ - void notifyPing(final String connectionToken, final long timestamp, final int pingNumber); - -} diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientPingBatchService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientPingBatchService.java index ce57a7f8..5f49dcfa 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientPingBatchService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientPingBatchService.java @@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.context.annotation.Lazy; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.stereotype.Component; @@ -40,41 +41,21 @@ public class SEBClientPingBatchService implements SEBClientPingService { private final ExamSessionCacheService examSessionCacheService; private final SEBClientInstructionService sebClientInstructionService; - private final ThreadPoolTaskScheduler threadPoolTaskScheduler; - private final long schendulerInterval; + private final Set pingKeys = new HashSet<>(); private final Map pings = new ConcurrentHashMap<>(); private final Map instructions = new ConcurrentHashMap<>(); - private ScheduledFuture scheduleAtFixedRate = null; - public SEBClientPingBatchService( final ExamSessionCacheService examSessionCacheService, - final SEBClientInstructionService sebClientInstructionService, - final ThreadPoolTaskScheduler threadPoolTaskScheduler, - @Value("${sebserver.webservice.api.exam.session.ping.batch.interval:500}") final long schendulerInterval) { + final SEBClientInstructionService sebClientInstructionService) { this.examSessionCacheService = examSessionCacheService; this.sebClientInstructionService = sebClientInstructionService; - this.threadPoolTaskScheduler = threadPoolTaskScheduler; - this.schendulerInterval = schendulerInterval; } - void init() { - if (this.scheduleAtFixedRate == null) { - - log.info( - "Initialize SEBClientPingBatchService for schedule batch update at a rate of {} milliseconds", - this.schendulerInterval); - - this.scheduleAtFixedRate = this.threadPoolTaskScheduler.scheduleAtFixedRate( - () -> processPings(), - this.schendulerInterval); - } - } - - //@Scheduled(fixedDelayString = "${sebserver.webservice.api.exam.session.ping.batch.interval:500}") + @Scheduled(fixedDelayString = "${sebserver.webservice.api.exam.session.ping.batch.interval:500}") public void processPings() { if (this.pings.isEmpty()) { return; @@ -160,12 +141,4 @@ public class SEBClientPingBatchService implements SEBClientPingService { this.instructions.put(connectionToken, instructionJSON); } } - - @PreDestroy - protected void shutdown() { - if (this.scheduleAtFixedRate != null) { - this.scheduleAtFixedRate.cancel(true); - } - } - }