Skip to content

Commit

Permalink
optimize some code
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed May 27, 2024
1 parent 96e5b12 commit 8557029
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void testDnsTimeout() {
int timeout = 5;
SystemDns dns = new SystemDns(timeout);
try {
List<IDnsNetworkAddress> result = dns.lookup("a.a.a.cn");
List<IDnsNetworkAddress> result = dns.lookup("abc.mock.cn");
assertTrue("testDnsTimeout fail:", result == null || result.size() == 0);
} catch (UnknownHostException e) {
e.printStackTrace();
Expand Down
5 changes: 2 additions & 3 deletions library/src/main/java/com/qiniu/android/common/AutoZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -132,7 +131,7 @@ public ZonesInfo getZonesInfo(UpToken token) {

@Override
public void preQuery(final UpToken token, final QueryHandler completeHandler) {
preQuery(null, token, new QueryHandlerV2() {
query(null, token, new QueryHandlerV2() {
@Override
public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics metrics, ZonesInfo zonesInfo) {
if (completeHandler != null) {
Expand All @@ -151,7 +150,7 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics metri
}

@Override
public void preQuery(Configuration configuration, UpToken token, QueryHandlerV2 completeHandler) {
public void query(Configuration configuration, UpToken token, QueryHandlerV2 completeHandler) {
if (token == null || !token.isValid()) {
completeHandler.complete(ResponseInfo.invalidToken("invalid token"), null, null);
return;
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/com/qiniu/android/common/FixedZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ public void preQuery(UpToken token, QueryHandler completeHandler) {
}

@Override
public void preQuery(Configuration configuration, UpToken token, QueryHandlerV2 completeHandler) {
public void query(Configuration configuration, UpToken token, QueryHandlerV2 completeHandler) {
if (completeHandler != null) {
completeHandler.complete(null, null, zonesInfo);
completeHandler.complete(ResponseInfo.successResponse(), null, zonesInfo);
}
}
}
2 changes: 1 addition & 1 deletion library/src/main/java/com/qiniu/android/common/Zone.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected Zone() {
* @param token 上传 token
* @param completeHandler 预查询结束回调
*/
public abstract void preQuery(Configuration configuration, UpToken token, final QueryHandlerV2 completeHandler);
public abstract void query(Configuration configuration, UpToken token, final QueryHandlerV2 completeHandler);

/**
* 预查询结束回调
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ private String[] getCurrentZoneHosts(Configuration configuration, Zone currentZo
final Wait wait = new Wait();

final ZonesInfo[] zonesInfoArray = {null};
currentZone.preQuery(configuration, token, new Zone.QueryHandlerV2() {
currentZone.query(configuration, token, new Zone.QueryHandlerV2() {
@Override
public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics metrics, ZonesInfo zonesInfo) {
zonesInfoArray[0] = zonesInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public IUploadServer getNextServer(UploadRequestState requestState, ResponseInfo
boolean accelerate = true;
synchronized (this) {
if (enableAccelerateUpload && responseInfo.error != null &&
responseInfo.error.equals("transfer acceleration is not configured on this bucket")) {
responseInfo.error.contains("transfer acceleration is not configured on this bucket")) {
enableAccelerateUpload = false;
}
accelerate = enableAccelerateUpload;
Expand All @@ -218,9 +218,7 @@ public IUploadServer getNextServer(UploadRequestState requestState, ResponseInfo
!MapUtils.isEmpty(accelerateDomainHashMap)) {
hostList.addAll(accelerateDomainHostList);
domainInfo.putAll(accelerateDomainHashMap);
}

if (!ListUtils.isEmpty(domainHostList) &&
} else if (!ListUtils.isEmpty(domainHostList) &&
!MapUtils.isEmpty(domainHashMap)) {
hostList = domainHostList;
domainInfo = domainHashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ public void run() {
private void innerRun() {
metrics.start();

config.zone.preQuery(config, token, new Zone.QueryHandlerV2() {
config.zone.query(config, token, new Zone.QueryHandlerV2() {
@Override
public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics requestMetrics, ZonesInfo zonesInfo) {
metrics.setUcQueryMetrics(requestMetrics);

if (zonesInfo != null) {
if (responseInfo != null && responseInfo.isOK() && zonesInfo != null) {
if (!setupRegions(zonesInfo)) {
completeAction(responseInfo, null);
return;
Expand All @@ -118,7 +118,7 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque
} else {
if (responseInfo == null) {
// responseInfo 一定会有值
responseInfo = ResponseInfo.errorInfo(ResponseInfo.UnknownError, "");
responseInfo = ResponseInfo.sdkInteriorError("can't get regions");
}
completeAction(responseInfo, responseInfo.response);
}
Expand Down

0 comments on commit 8557029

Please sign in to comment.