Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android-sdk.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="jdk" jdkName="JDK" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


public final class Constants {
public static final String VERSION = "7.5.1";
public static final String VERSION = "7.5.2";

public static final String UTF_8 = "utf-8";
}
46 changes: 15 additions & 31 deletions library/src/main/java/com/qiniu/android/http/DnsPrefetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -37,7 +38,6 @@ public class DnsPrefetcher {
private static Configuration config;

private static ConcurrentHashMap<String, List<InetAddress>> mConcurrentHashMap = new ConcurrentHashMap<String, List<InetAddress>>();
private static List<String> mHosts = new ArrayList<String>();
private static AtomicReference mDnsCacheKey = new AtomicReference();

private DnsPrefetcher() {
Expand Down Expand Up @@ -75,7 +75,6 @@ public void localFetch() {
preFetch(localHosts);
}


public DnsPrefetcher init(String token, Configuration config) throws UnknownHostException {
this.token = token;
this.config = config;
Expand All @@ -89,15 +88,6 @@ public void setConcurrentHashMap(ConcurrentHashMap<String, List<InetAddress>> mC
this.mConcurrentHashMap = mConcurrentHashMap;
}

//use for test
public List<String> getHosts() {
return this.mHosts;
}

public void setHosts(List mHosts) {
this.mHosts = mHosts;
}

//use for test
public ConcurrentHashMap<String, List<InetAddress>> getConcurrentHashMap() {
return this.mConcurrentHashMap;
Expand Down Expand Up @@ -145,7 +135,6 @@ private void preFetch(List<String> fetchHost) {
try {
inetAddresses = okhttp3.Dns.SYSTEM.lookup(host);
mConcurrentHashMap.put(host, inetAddresses);
mHosts.add(host);
} catch (UnknownHostException e) {
e.printStackTrace();
rePreHosts.add(host);
Expand Down Expand Up @@ -181,7 +170,6 @@ private boolean rePreFetch(String host, Dns customeDns) {
inetAddresses = customeDns.lookup(host);
}
mConcurrentHashMap.put(host, inetAddresses);
mHosts.add(host);
return true;
} catch (UnknownHostException e) {
e.printStackTrace();
Expand All @@ -198,14 +186,20 @@ private boolean rePreFetch(String host, Dns customeDns) {
*/
public void dnsPreByCustom(Dns dns) {
List<String> rePreHosts = new ArrayList<String>();
for (String host : mHosts) {
List<InetAddress> inetAddresses = null;
try {
inetAddresses = dns.lookup(host);
mConcurrentHashMap.put(host, inetAddresses);
} catch (UnknownHostException e) {
e.printStackTrace();
rePreHosts.add(host);
if (mConcurrentHashMap != null && mConcurrentHashMap.size() > 0) {
Iterator iter = mConcurrentHashMap.keySet().iterator();
while (iter.hasNext()) {
String tmpkey = (String) iter.next();
if (!(tmpkey == null) && !(tmpkey.length() == 0)) {
List<InetAddress> inetAddresses = null;
try {
inetAddresses = dns.lookup(tmpkey);
mConcurrentHashMap.put(tmpkey, inetAddresses);
} catch (UnknownHostException e) {
e.printStackTrace();
rePreHosts.add(tmpkey);
}
}
}
}
rePreFetch(rePreHosts, dns);
Expand Down Expand Up @@ -405,16 +399,6 @@ public static boolean recoverDnsCache(byte[] data) {
return true;
}
DnsPrefetcher.getDnsPrefetcher().setConcurrentHashMap(concurrentHashMap);

ArrayList<String> list = new ArrayList<String>();
Iterator iter = concurrentHashMap.keySet().iterator();
while (iter.hasNext()) {
String tmpkey = (String) iter.next();
if (tmpkey == null || tmpkey.length() == 0)
continue;
list.add(tmpkey);
}
DnsPrefetcher.getDnsPrefetcher().setHosts(list);
return false;
}
}
24 changes: 12 additions & 12 deletions library/src/main/java/com/qiniu/android/storage/UploadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ public void put(final byte[] data, final String key, final String token,
}
//此处是对uc.qbox.me接口获取的域名进行预取
if (DnsPrefetcher.checkRePrefetchDns(token, config)) {
new Thread(new Runnable() {
@Override
public void run() {
DnsPrefetcher.startPrefetchDns(token, config);
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
DnsPrefetcher.startPrefetchDns(token, config);
}
}).start();
}

Zone z = config.zone;
Expand Down Expand Up @@ -220,12 +220,12 @@ public void put(final File file, final String key, final String token,
}
//此处是每次上传时判断,对uc.qbox.me接口获取的host+sdk内置的host进行预取(去重)
if (DnsPrefetcher.checkRePrefetchDns(token, config)) {
new Thread(new Runnable() {
@Override
public void run() {
DnsPrefetcher.startPrefetchDns(token, config);
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
DnsPrefetcher.startPrefetchDns(token, config);
}
}).start();
}

Zone z = config.zone;
Expand Down