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

org.zodiac.monitor.reload.EurekaClientReloadHealthCheck Maven / Gradle / Ivy

package org.zodiac.monitor.reload;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zodiac.eureka.client.EurekaClientService;
import org.zodiac.monitor.reload.model.ReloadHealthCheckResult;

//import com.netflix.appinfo.ApplicationInfoManager;

public class EurekaClientReloadHealthCheck implements ReloadHealthCheck {

    protected Logger log = LoggerFactory.getLogger(getClass());

    //private ApplicationInfoManager applicationInfoManager;
    private EurekaClientService eurekaClientService;

    public EurekaClientReloadHealthCheck(EurekaClientService eurekaClientService) {
        //this.applicationInfoManager = applicationInfoManager;
        this.eurekaClientService = eurekaClientService;
    }

    @Override
    public String name() {
        return "eurekaClient";
    }

    @Override
    public ReloadHealthCheckResult healthCheck() {
        return new ReloadHealthCheckResult();
    }

    @Override
    public void shutdownEvent() {
        try {
            //DiscoveryClientCaller.unregister();
            //applicationInfoManager.setInstanceStatus(InstanceInfo.InstanceStatus.OUT_OF_SERVICE);
            eurekaClientService.unregisterClient();
            eurekaClientService.clientStatusOutOfService();
            log.info("EurekaHealthCheck shutdown success.");
        } catch (Exception e) {
            log.error("EurekaHealthCheck shutdown failed, caused by {} .", e.getMessage());
        }
    }

    @Override
    public void startEvent() {
        try {
            /*
            如果调用 DiscoveryClientCaller.register,eureka-server会判断该节点是否之前有状态,并且以之前的状态标记该节点。
            导致本地状态虽然为UP,但是eureka-server端依旧标识为OUT_OF_SERVICE,
            因此重新注册为UP时,需要通过DiscoveryClientCaller.unregister将eureka-server内关于该节点的信息抹除。
            通过心跳将UP状态再注册进去
            */
            //applicationInfoManager.setInstanceStatus(InstanceStatus.UP);
            //DiscoveryClientCaller.unregister();
            eurekaClientService.clientStatusUp();
            eurekaClientService.unregisterClient();
            System.out.println("EurekaHealthCheck start success.");
        } catch (Exception e) {
            log.error("EurekaHealthCheck start failed, caused by {} .", e.getMessage());
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy