diff options
author | Vitaly Takmazov | 2018-11-28 13:11:36 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-11-28 13:11:36 +0300 |
commit | c822798998b72fd2dccd748438fbd8563e733485 (patch) | |
tree | 7bbf5ec6f55cadcb4e72168aa1f6f8f1564494f9 /src/main | |
parent | 94c5c00dd44c8ae5697f2079d1858af57a2143be (diff) |
Ping SSE event
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/juick/server/ServerManager.java | 8 |
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())); + } } |