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

org.sdn.api.event.SdkEventHandler Maven / Gradle / Ivy

package org.sdn.api.event;

import com.alibaba.fastjson.JSON;
import org.sdn.api.vo.EventMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


/**
 * @author gaosong
 * @date 2018/12/4.
 */
@Component
public class SdkEventHandler {

    private static final Logger logger = LoggerFactory.getLogger(SdkEventHandler.class);

    /**
     * 重启服务事件
     */
    private static final String SDK_SERVICE_RESTART = "SDK-SERVICE-RESTART";

    @EventListener("SDK-SERVICE-NOTIFY")
    public void sdkEventHandler(String payload) {
        logger.info("SDK SdkEventHandler msg={}", payload);
        try {
            EventMessage message = JSON.parseObject(payload, EventMessage.class);
            String  type = message.getEventType();
            switch (type) {
                case SDK_SERVICE_RESTART:
                    logger.info("SDK 重启服务 {}",message.getAppId());
                    Runtime.getRuntime().exit(0);
                    break;
                default:
                    logger.info("SDK  EventHandler handlePush msg={}","事件类型不匹配");
                    break;
            }
        } catch (Exception e) {
            logger.info("SDK EventHandler handlePush error e={}", e.getMessage(), e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy