All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.blankcat.websocket.handler.HelloHandler Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package cn.blankcat.websocket.handler;

import cn.blankcat.config.BotConfig;
import cn.blankcat.dto.websocket.WSHelloData;
import cn.blankcat.dto.websocket.WSPayload;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HelloHandler implements WebsocketHandler{

    private static final Logger logger = LoggerFactory.getLogger("helloHandler");
    @Override
    public void handle(String message) {
        try {
            // 发送心跳获取心跳周期
            ObjectMapper mapper = new ObjectMapper();
            WSPayload wsPayloadHello = mapper.readValue(message, mapper.getTypeFactory().constructParametricType(WSPayload.class, WSHelloData.class));
            if (BotConfig.DEFAULT.getLastDelay() != wsPayloadHello.getData().getHeartbeatInterval()){
                BotConfig.DEFAULT.setLastDelay(wsPayloadHello.getData().getHeartbeatInterval());
            }
            logger.info("收到Hello消息, 本次delay为{}ms", wsPayloadHello.getData().getHeartbeatInterval());
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy