httpdns 缓存策略,特殊接口获取 httpdns 服务
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.mogo.httpdns;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -7,7 +9,9 @@ public
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
@Keep
|
||||
class HttpDnsConst {
|
||||
|
||||
@Keep
|
||||
public static final String PATH = "/httpdns/api";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.mogo.httpdns;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/11/19
|
||||
*
|
||||
* dns 解析回调
|
||||
*/
|
||||
@Keep
|
||||
interface IHttpDnsCallback {
|
||||
|
||||
@Keep
|
||||
void onParsed( @Nullable String ip );
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mogo.httpdns;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/11/19
|
||||
*
|
||||
* dns ttl 通知
|
||||
*/
|
||||
@Keep
|
||||
interface IHttpDnsTtlCallback {
|
||||
|
||||
@Keep
|
||||
void onTtl();
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.mogo.httpdns;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.alibaba.android.arouter.facade.template.IProvider;
|
||||
import com.mogo.utils.network.HttpDns;
|
||||
|
||||
@@ -13,9 +16,47 @@ public
|
||||
*
|
||||
* http 请求做http dns转换
|
||||
*/
|
||||
@Keep
|
||||
interface IMogoHttpDns extends IProvider {
|
||||
|
||||
/**
|
||||
* 获取 dns 代理实例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
HttpDns dns();
|
||||
|
||||
Collection< String > getHttpDnsIps( String host );
|
||||
/**
|
||||
* 获取缓存中的 dns ip地址
|
||||
*
|
||||
* @param host
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
String getCachedHttpDnsIps( String host );
|
||||
|
||||
/**
|
||||
* dns 解析
|
||||
*
|
||||
* @param host 域名
|
||||
* @param useCache 是否使用缓存,是 - 如果没有缓存,则解析新地址、否 - 解析新地址,并将新地址缓存
|
||||
* @param callback
|
||||
*/
|
||||
void getHttpDnsIp( String host, boolean useCache, IHttpDnsCallback callback );
|
||||
|
||||
/**
|
||||
* 监听 ttl 回调
|
||||
*
|
||||
* @param host 域名
|
||||
* @param callback
|
||||
*/
|
||||
void addHttpDnsTtlCallback( String host, IHttpDnsTtlCallback callback );
|
||||
|
||||
/**
|
||||
* 注销 ttl 回调
|
||||
*
|
||||
* @param host 域名
|
||||
*/
|
||||
void removeHttpDnsTtlCallback( String host );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.mogo.httpdns;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/11/19
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
@Keep
|
||||
class MogoHttpDnsHandler {
|
||||
|
||||
private static IMogoHttpDns sHttpDns;
|
||||
|
||||
public static IMogoHttpDns getHttpDnsApi() {
|
||||
if ( sHttpDns == null ) {
|
||||
synchronized ( MogoHttpDnsHandler.class ) {
|
||||
if ( sHttpDns == null ) {
|
||||
sHttpDns = ARouter.getInstance().navigation( IMogoHttpDns.class );
|
||||
}
|
||||
}
|
||||
}
|
||||
return sHttpDns;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user