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

com.github.fashionbrot.ribbon.ping.PingUrl Maven / Gradle / Ivy

Go to download

mars-ribbon-api 负载均衡工具 https://github.com/fashionbrot/mars-dynamic-config

There is a newer version: 0.1.3
Show newest version
package com.github.fashionbrot.ribbon.ping;

import com.github.fashionbrot.ribbon.constants.GlobalConstants;
import com.github.fashionbrot.ribbon.enums.SchemeEnum;
import com.github.fashionbrot.ribbon.loadbalancer.Server;
import com.github.fashionbrot.ribbon.util.HttpClientUtil;
import com.github.fashionbrot.ribbon.util.HttpResult;
import lombok.extern.slf4j.Slf4j;

/**
 * @author fashionbrot
 * @version 0.1.1
 * @date 2019/12/8 22:45
 */
@Slf4j
public class PingUrl implements IPing {



    @Override
    public boolean isAlive(Server server,boolean enableLog) {
        String url = server.getServer();
        HttpResult httpResult;
        try {
            httpResult = HttpClientUtil.httpGet(url,null,null, GlobalConstants.ENCODE_UTF8,2000,2000,enableLog);
        } catch (Exception e) {
            if (enableLog) {
                log.error("pingUrl alive error:", e.getMessage());
            }
            return false;
        }
        if (log.isDebugEnabled()){
            log.debug("isAlive url:{} result:{}",url,httpResult.toString());
        }
        if (httpResult.isSuccess()){
            return true;
        }
        return false;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy