From c822798998b72fd2dccd748438fbd8563e733485 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 28 Nov 2018 13:11:36 +0300 Subject: Ping SSE event --- src/main/java/com/juick/server/ServerManager.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/main') 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 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())); + } } -- cgit v1.2.3