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

com.taobao.api.HttpdnsClient Maven / Gradle / Ivy

The newest version!
package com.taobao.api;

import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.taobao.api.internal.cluster.ClusterManager;
import com.taobao.api.internal.cluster.DnsConfig;
import com.taobao.api.internal.util.WebUtils;

/**
 * HTTP DNS客户端。
 * 
 * @author xiaoxuan
 * @since 2019-03-08
 */
public class HttpdnsClient {

	private static final AtomicBoolean init = new AtomicBoolean(false);
	private static final Log log = LogFactory.getLog(ClusterManager.class);

	public static void init(String appKey, String appSecret) {
		if (init.compareAndSet(false, true)) {
			WebUtils.setIgnoreHostCheck(true);
			ClusterManager.initRefreshThread(appKey, appSecret);
		}
	}

	public static String getUrl(String url) {
		if (!init.get()) {
			log.error("Taobao HttpdnsClient is not initialized...");
			return url;
		}
		DnsConfig dnsConfig = ClusterManager.GetDnsConfigFromCache();
		if (dnsConfig == null) {
			return url;
		} else {
			return dnsConfig.getVipUrl(url);
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy