aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/juick/server/ServerManager.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/main/java/com/juick/server/ServerManager.java b/src/main/java/com/juick/server/ServerManager.java
index 586d5962..7a95ec43 100644
--- a/src/main/java/com/juick/server/ServerManager.java
+++ b/src/main/java/com/juick/server/ServerManager.java
@@ -35,6 +35,7 @@ import com.juick.util.MessageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import org.springframework.web.socket.TextMessage;
@@ -291,4 +292,11 @@ public class ServerManager implements NotificationListener {
public CopyOnWriteArrayList<EventSession> getSessions() {
return sessions;
}
+ @Scheduled(fixedRate = 30000)
+ public void ping() {
+ Message ping = new Message();
+ ping.setService(true);
+ sendSseEvent(ping, "ping", getSessions().stream().map(s -> s.user)
+ .distinct().collect(Collectors.toList()));
+ }
}