Introduction
Use these APIs with custom resolution functions when basic resolution scenarios do not meet your requirements.
Configure the common parameters required for each custom domain name resolution request. For more information, see Set global parameters for custom resolution.
Custom synchronous resolution API
The custom synchronous resolution API blocks the current thread until a valid resolution result is returned.
This API first queries the cache using the `cacheKey`. If an active resolution result exists in the cache, the API immediately returns the cached result. If no active result is found, the API blocks the calling thread and performs domain name resolution in a worker thread. After the resolution is complete, the result is returned. If the request times out, a null value is returned.
The timeout configuration controls the overall duration of synchronous resolution. If resolution is not completed within the timeout period, an empty result is returned.
getHttpDnsResultForHostSync
API definition
HTTPDNSResult getHttpDnsResultForHostSync(String host, RequestIpType requestIpType, Map<String, String> params, String cacheKey)
Version introduced
2.4.0
Class
HttpDnsService
Parameters
|
Parameter |
Type |
Required |
Description |
|
host |
String |
Yes |
The domain name to resolve. |
|
requestIpType |
RequestIpType |
Yes |
The IP address type to resolve. We recommend that you set this to RequestIpType.both. Valid values:
|
|
params |
Map<String, String> |
Yes |
Extra parameters for domain name resolution. This corresponds to the event.parameters parameter in the custom resolution function on the server. |
|
cacheKey |
String |
Yes |
The local cache key for the domain name. If extra parameters change and the server must resolve the domain name again, you must also change the cacheKey. |
Return value
|
Type |
Description |
|
The resolution result. |
Sample code
val httpdns = HttpDns.getService(accountID)
val httpDnsResult = dnsService?.getHttpDnsResultForHostSync(host, RequestIpType.auto, params, cacheKey)HttpDnsService httpdns = HttpDns.getService(accountID);
HTTPDNSResult httpDnsResult = httpdns.getHttpDnsResultForHostSync(host, RequestIpType.auto, params, cacheKey);Custom asynchronous resolution API
The custom asynchronous resolution API resolves domain names without blocking the current thread. Results are returned through a callback.
This API first queries the cache. If an active resolution result exists in the cache, the API immediately returns the cached result through the callback. If no active result is found, the API performs domain name resolution in a worker thread. After the resolution is complete or the request times out, the result is returned through the callback.
For the asynchronous resolution API, the total resolution time is controlled by the timeout configuration. If resolution is not completed within the configured timeout period, an empty result is returned.
getHttpDnsResultForHostAsync
API definition
void getHttpDnsResultForHostAsync(String host, RequestIpType requestIpType, Map<String, String> params, String cacheKey, HttpDnsCallback callback)
Version introduced
2.4.0
Class
HttpDnsService
Parameters
|
Parameter |
Type |
Required |
Description |
|
host |
String |
Yes |
The domain name to resolve. |
|
requestIpType |
RequestIpType |
Yes |
The IP address type to resolve. We recommend that you set this to RequestIpType.both. Valid values:
|
|
params |
Map<String, String> |
Yes |
Extra parameters for domain name resolution. This corresponds to the event.parameters parameter in the custom resolution function on the server. |
|
cacheKey |
String |
Yes |
The local cache key for the domain name. If extra parameters change and the server must resolve the domain name again, you must also change the cacheKey. |
|
callback |
Yes |
The callback class for the resolution result. |
Sample code
val httpdns = HttpDns.getService(accountID)
dnsService?.getHttpDnsResultForHostAsync(host, RequestIpType.auto, params, cacheKey, HttpDnsCallback {
httpDnsResult = it
})HttpDnsService httpdns = HttpDns.getService(accountID);
httpdns.getHttpDnsResultForHostAsync(host, RequestIpType.auto, params, cacheKey, new HttpDnsCallback() {
void onHttpDnsCompleted(HTTPDNSResult result) {
}
});Custom synchronous non-blocking resolution API
The custom synchronous non-blocking API resolves domain names without blocking the current thread, but may return an empty result.
This API only queries the cache and returns the resolution result from the cache. If no resolution result exists in the cache or the cached result has expired, domain name resolution is performed in a worker thread. After a successful resolution, the cache is updated for the next call.
getHttpDnsResultForHostSyncNonBlocking
API definition
HTTPDNSResult getHttpDnsResultForHostSyncNonBlocking(String host, RequestIpType requestIpType, Map<String, String> params, String cacheKey)
Version introduced
2.4.0
Class
HttpDnsService
Parameters
|
Parameter |
Type |
Required |
Description |
|
host |
String |
Yes |
The domain name to resolve. |
|
requestIpType |
RequestIpType |
Yes |
The IP address type to resolve. We recommend that you set this to RequestIpType.both. Valid values:
|
|
params |
Map<String, String> |
Yes |
Extra parameters for domain name resolution. This corresponds to the event.parameters parameter in the custom resolution function on the server. |
|
cacheKey |
String |
Yes |
The local cache key for the domain name. If extra parameters change and the server must resolve the domain name again, you must also change the cacheKey. |
Return value
|
Type |
Description |
|
The resolution result. |
Sample code
val httpdns = HttpDns.getService(accountID)
val httpDnsResult = dnsService?.getHttpDnsResultForHostSyncNonBlocking(host, RequestIpType.auto, params, cacheKey)HttpDnsService httpdns = HttpDns.getService(accountID);
HTTPDNSResult httpDnsResult = httpdns.getHttpDnsResultForHostSyncNonBlocking(host, RequestIpType.auto, params, cacheKey);