|
6 | 6 | import com.qiniu.android.http.request.Request; |
7 | 7 | import com.qiniu.android.http.request.httpclient.SystemHttpClient; |
8 | 8 | import com.qiniu.android.storage.GlobalConfiguration; |
| 9 | +import com.qiniu.android.utils.LogUtil; |
9 | 10 | import com.qiniu.android.utils.SingleFlight; |
10 | 11 | import com.qiniu.android.utils.Wait; |
11 | 12 |
|
@@ -66,37 +67,44 @@ private static void checkAllHosts(final CheckCompleteHandler completeHandler) { |
66 | 67 | allHosts = allHosts.clone(); |
67 | 68 | final CheckStatus checkStatus = new CheckStatus(); |
68 | 69 | checkStatus.totalCount = allHosts.length; |
| 70 | + checkStatus.completeCount = 0; |
69 | 71 | for (String host : allHosts) { |
70 | 72 | checkHost(host, new CheckCompleteHandler() { |
71 | 73 | @Override |
72 | 74 | public void complete(boolean isHostConnected) { |
73 | 75 |
|
74 | | - synchronized (this) { |
| 76 | + synchronized (checkStatus) { |
75 | 77 | checkStatus.completeCount += 1; |
76 | 78 | } |
77 | 79 | if (isHostConnected) { |
78 | 80 | checkStatus.isConnected = true; |
79 | 81 | } |
80 | 82 | if (checkStatus.completeCount == checkStatus.totalCount) { |
| 83 | + LogUtil.i("== check all hosts has completed totalCount:" + checkStatus.totalCount + " completeCount:" + checkStatus.completeCount); |
81 | 84 | completeHandler.complete(checkStatus.isConnected); |
| 85 | + } else { |
| 86 | + LogUtil.i("== check all hosts not completed totalCount:" + checkStatus.totalCount + " completeCount:" + checkStatus.completeCount); |
82 | 87 | } |
83 | 88 | } |
84 | 89 | }); |
85 | 90 | } |
86 | 91 |
|
87 | 92 | } |
88 | 93 |
|
89 | | - private static void checkHost(String host, final CheckCompleteHandler completeHandler) { |
| 94 | + private static void checkHost(final String host, final CheckCompleteHandler completeHandler) { |
90 | 95 |
|
91 | | - Request request = new Request(host, "HEAD", null, null, 3); |
| 96 | + Request request = new Request(host, Request.HttpMethodHEAD, null, null, 3); |
92 | 97 | SystemHttpClient client = new SystemHttpClient(); |
93 | 98 |
|
| 99 | + LogUtil.i("== checkHost:" + host); |
94 | 100 | client.request(request, true, null, null, new IRequestClient.RequestClientCompleteHandler() { |
95 | 101 | @Override |
96 | 102 | public void complete(ResponseInfo responseInfo, UploadSingleRequestMetrics metrics, JSONObject response) { |
97 | 103 | if (responseInfo.statusCode > 99) { |
| 104 | + LogUtil.i("== checkHost:" + host + "result: true"); |
98 | 105 | completeHandler.complete(true); |
99 | 106 | } else { |
| 107 | + LogUtil.i("== checkHost:" + host + "result: false"); |
100 | 108 | completeHandler.complete(false); |
101 | 109 | } |
102 | 110 | } |
|
0 commit comments