Created
January 26, 2013 13:09
-
-
Save yelcat/4642291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HostListHolder hostListHolder = HostListHolder.getInstance(); | |
Collection<String> hostList = hostListHolder.getHostList(HostListHolder.PRODUCTION); | |
if (hostList.size() > 0) { | |
addKeys(keys, hostList); | |
Result<List<DataEntry>> result = tairManager.mget(NAMESPACE, keys); | |
if ((ResultCode.PARTSUCC.equals(result.getRc()) || ResultCode.SUCCESS.equals(result.getRc())) | |
&& null != result.getValue()) { | |
doMerge(result.getValue(), unsortedHashmap); | |
} | |
else { | |
// 尝试daily环境 | |
hostList = hostListHolder.getHostList(HostListHolder.DAILY); | |
addKeys(keys, hostList); | |
Result<List<DataEntry>> dailyResult = tairManager.mget(NAMESPACE, keys); | |
if ((ResultCode.PARTSUCC.equals(dailyResult.getRc()) || ResultCode.SUCCESS.equals(dailyResult.getRc())) | |
&& null != result.getValue()) { | |
doMerge(dailyResult.getValue(), unsortedHashmap); | |
} | |
} | |
} | |
Map.Entry[] sortedHashTable = getSortedHashtableByValue(unsortedHashmap); | |
private void doMerge(List entryList, | |
Map unsortedHashmap) { | |
for(DataEntry de: entryList){ | |
Map top10Maper = new HashMap(); | |
String top10 = (String) de.getValue(); | |
String[] top10Items = StringUtils.split(top10, ';'); | |
for (int idx = 0; idx < top10Items.length; idx ++) { String[] itemKV = StringUtils.split(top10Items[idx],':'); long itemId = Long.parseLong(itemKV[0]); int counter = Integer.parseInt(itemKV[1]); Integer amount = top10Maper.get(itemId); if (amount == null || counter > amount) { | |
top10Maper.put(itemId, counter); | |
} | |
} | |
unsortedHashmap.putAll(top10Maper); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment