ItsWebSocketSession.java 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package com.its.pis.websocket;
  2. import lombok.Data;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.web.socket.TextMessage;
  5. import org.springframework.web.socket.WebSocketSession;
  6. import java.io.IOException;
  7. @Slf4j
  8. @Data
  9. public class ItsWebSocketSession {
  10. private ItsWebSocketHandler itsWebsocketHandler;
  11. private WebSocketSession session;
  12. private String groupId;
  13. public ItsWebSocketSession(ItsWebSocketHandler itsWebsocketHandler, org.springframework.web.socket.WebSocketSession session) {
  14. this.itsWebsocketHandler = itsWebsocketHandler;
  15. this.session = session;
  16. }
  17. public void sendMessage(String command, TextMessage message) {
  18. if (this.session != null && this.session.isOpen()) {
  19. synchronized (this.session) {
  20. try {
  21. this.session.sendMessage(message);
  22. } catch (IOException e) {
  23. log.error("sendMessage: nodeId: {}, session: {}", command, session);
  24. }
  25. }
  26. }
  27. }
  28. }