fix bug of listener
This commit is contained in:
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="1.8" />
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
||||
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
@@ -7,7 +7,7 @@
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="1.8" />
|
||||
<option name="gradleJvm" value="11" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -13,7 +13,7 @@
|
||||
<option name="HEAP_SIZE" value="1024" />
|
||||
<option name="LOCALE" value="zh_CN" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.Message
|
||||
import android.util.ArrayMap
|
||||
import com.mogo.cloud.httpdns.listener.IHttpDnsTtlCallback
|
||||
import com.mogo.cloud.httpdns.listener.IMogoHttpDns
|
||||
import com.mogo.cloud.httpdns.listener.OnAddressChangedListener
|
||||
import com.mogo.cloud.httpdns.util.ApiManager
|
||||
@@ -35,14 +34,10 @@ internal class HttpDnsHelper(private val builder: MogoHttpDnsConfig) : Handler.C
|
||||
private val workThread = HandlerThread("mogo-http-dns-work-thread")
|
||||
private val handler: Handler
|
||||
private var addressMap: Map<String, String>? = null
|
||||
private val ttlCallbackMap: MutableMap<String, MutableList<IHttpDnsTtlCallback>> =
|
||||
mutableMapOf()
|
||||
|
||||
private var addressChangedListener: OnAddressChangedListener? = null
|
||||
|
||||
private val apiManager: ApiManager
|
||||
private var isInit = false
|
||||
|
||||
private var defaultUrl: String? = null
|
||||
|
||||
init {
|
||||
@@ -88,6 +83,10 @@ internal class HttpDnsHelper(private val builder: MogoHttpDnsConfig) : Handler.C
|
||||
|
||||
private val requestLock = Any()
|
||||
|
||||
override fun addressChangedListener(addressChangedListener: OnAddressChangedListener) {
|
||||
this.addressChangedListener = addressChangedListener
|
||||
}
|
||||
|
||||
override fun syncGetHttpDns(host: String, type: Int, useCache: Boolean): String? {
|
||||
L.d(TAG, "syncGetHttpDns $type-$host")
|
||||
return if (useCache) {
|
||||
@@ -152,17 +151,6 @@ internal class HttpDnsHelper(private val builder: MogoHttpDnsConfig) : Handler.C
|
||||
return addressMap
|
||||
}
|
||||
|
||||
override fun addHttpDnsTtlCallback(host: String, type: Int, callback: IHttpDnsTtlCallback) {
|
||||
if (ttlCallbackMap["$type-$host"] == null) {
|
||||
ttlCallbackMap["$type-$host"] = mutableListOf()
|
||||
}
|
||||
ttlCallbackMap["$type-$host"]!!.add(callback)
|
||||
}
|
||||
|
||||
override fun removeHttpDnsTtlCallback(host: String, type: Int) {
|
||||
ttlCallbackMap.remove("$type-$host")
|
||||
}
|
||||
|
||||
override fun handleMessage(msg: Message): Boolean {
|
||||
if (msg.what == MSG_REQUEST_IP_PORT) {
|
||||
L.d(TAG, "http dns loop check")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.mogo.cloud.httpdns
|
||||
|
||||
import com.mogo.cloud.httpdns.listener.IHttpDnsTtlCallback
|
||||
import com.mogo.cloud.httpdns.listener.IMogoHttpDns
|
||||
import com.mogo.cloud.httpdns.listener.OnAddressChangedListener
|
||||
|
||||
|
||||
object MogoHttpDnsClient : IMogoHttpDns {
|
||||
@@ -21,6 +21,13 @@ object MogoHttpDnsClient : IMogoHttpDns {
|
||||
return getHttpDnsCachedAddress(type, _host) ?: return getHttpDnsAddress(type, _host)
|
||||
}
|
||||
|
||||
override fun addressChangedListener(addressChangedListener: OnAddressChangedListener) {
|
||||
if (httpDnsHelper == null) {
|
||||
throw IllegalStateException("MogoHttpDnsClient init error")
|
||||
}
|
||||
return httpDnsHelper!!.addressChangedListener(addressChangedListener)
|
||||
}
|
||||
|
||||
override fun syncGetHttpDns(host: String, type: Int, useCache: Boolean): String? {
|
||||
if (httpDnsHelper == null) {
|
||||
throw IllegalStateException("MogoHttpDnsClient init error")
|
||||
@@ -49,20 +56,6 @@ object MogoHttpDnsClient : IMogoHttpDns {
|
||||
return httpDnsHelper!!.getAllAddress()
|
||||
}
|
||||
|
||||
override fun addHttpDnsTtlCallback(host: String, type: Int, callback: IHttpDnsTtlCallback) {
|
||||
if (httpDnsHelper == null) {
|
||||
throw IllegalStateException("MogoHttpDnsClient init error")
|
||||
}
|
||||
return httpDnsHelper!!.addHttpDnsTtlCallback(host, type, callback)
|
||||
}
|
||||
|
||||
override fun removeHttpDnsTtlCallback(host: String, type: Int) {
|
||||
if (httpDnsHelper == null) {
|
||||
throw IllegalStateException("MogoHttpDnsClient init error")
|
||||
}
|
||||
return httpDnsHelper!!.removeHttpDnsTtlCallback(host, type)
|
||||
}
|
||||
|
||||
override fun release() {
|
||||
if (httpDnsHelper == null) {
|
||||
throw IllegalStateException("MogoHttpDnsClient init error")
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.mogo.cloud.httpdns.listener
|
||||
|
||||
/**
|
||||
* dns ttl 通知
|
||||
*/
|
||||
interface IHttpDnsTtlCallback {
|
||||
fun onTtl()
|
||||
}
|
||||
@@ -4,6 +4,11 @@ import com.mogo.cloud.httpdns.HttpDnsHelper.Companion.HTTP_DNS_TYPE_HTTP
|
||||
|
||||
interface IMogoHttpDns {
|
||||
|
||||
/**
|
||||
* 地址变更回调
|
||||
*/
|
||||
fun addressChangedListener(addressChangedListener: OnAddressChangedListener);
|
||||
|
||||
/**
|
||||
* 同步进行dns解析,无需回调
|
||||
* @param host
|
||||
@@ -45,20 +50,5 @@ interface IMogoHttpDns {
|
||||
*/
|
||||
fun getAllAddress(): Map<String, String>?
|
||||
|
||||
/**
|
||||
* 监听ttl回调
|
||||
* @param host
|
||||
* @param type
|
||||
* @param callback
|
||||
*/
|
||||
fun addHttpDnsTtlCallback(host: String, type: Int, callback: IHttpDnsTtlCallback)
|
||||
|
||||
/**
|
||||
* 注销ttl回调
|
||||
* @param host
|
||||
* @param type
|
||||
*/
|
||||
fun removeHttpDnsTtlCallback(host: String, type: Int)
|
||||
|
||||
fun release()
|
||||
}
|
||||
@@ -30,22 +30,22 @@ PASSWORD=xintai2018
|
||||
RELEASE=true
|
||||
# AI CLOUD 云平台
|
||||
# 工具类
|
||||
MOGO_UTILS_VERSION=1.1.30
|
||||
MOGO_UTILS_VERSION=1.1.31
|
||||
# 网络请求
|
||||
MOGO_NETWORK_VERSION=1.1.30
|
||||
MOGO_NETWORK_VERSION=1.1.31
|
||||
# 网络DNS
|
||||
MOGO_HTTPDNS_VERSION=1.1.30
|
||||
MOGO_HTTPDNS_VERSION=1.1.31
|
||||
# 鉴权
|
||||
MOGO_PASSPORT_VERSION=1.1.30
|
||||
MOGO_PASSPORT_VERSION=1.1.31
|
||||
# 常链接
|
||||
MOGO_SOCKET_VERSION=1.1.30
|
||||
MOGO_SOCKET_VERSION=1.1.31
|
||||
# 数据采集
|
||||
MOGO_REALTIME_VERSION=1.1.30
|
||||
MOGO_REALTIME_VERSION=1.1.31
|
||||
# 探路,道路事件发布,获取
|
||||
MOGO_TANLU_VERSION=1.1.30
|
||||
MOGO_TANLU_VERSION=1.1.31
|
||||
# 直播推流
|
||||
MOGO_LIVE_VERSION=1.1.30
|
||||
MOGO_LIVE_VERSION=1.1.31
|
||||
# 直播拉流
|
||||
MOGO_TRAFFICLIVE_VERSION=1.1.30
|
||||
MOGO_TRAFFICLIVE_VERSION=1.1.31
|
||||
# 定位服务
|
||||
MOGO_LOCATION_VERSION=1.1.30
|
||||
MOGO_LOCATION_VERSION=1.1.31
|
||||
|
||||
Reference in New Issue
Block a user