本文整理汇总了Java中com.taobao.tddl.atom.utils.ConnRestrictEntry.getHashSize方法的典型用法代码示例。如果您正苦于以下问题:Java ConnRestrictEntry.getHashSize方法的具体用法?Java ConnRestrictEntry.getHashSize怎么用?Java ConnRestrictEntry.getHashSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.taobao.tddl.atom.utils.ConnRestrictEntry
的用法示例。
在下文中一共展示了ConnRestrictEntry.getHashSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseConnRestrictEntries
import com.taobao.tddl.atom.utils.ConnRestrictEntry; //导入方法依赖的package包/类
/**
* 解析应用连接限制, 完整格式是:
* "K1,K2,K3,K4:80%; K5,K6,K7,K8:80%; K9,K10,K11,K12:80%; *:16,80%; ~:80%;"
* 这样可以兼容 HASH: "*:16,80%", 也可以兼容 LIST:
* "K1:80%; K2:80%; K3:80%; K4:80%; ~:80%;" 配置可以是连接数, 也可以是百分比。
*/
public static List<ConnRestrictEntry> parseConnRestrictEntries(String connRestrictStr, int maxPoolSize) {
List<ConnRestrictEntry> connRestrictEntries = null;
if (TStringUtil.isNotBlank(connRestrictStr)) {
// Split "K1:number1; K2:number2; ...; *:count,number3; ~:number4"
String[] entries = TStringUtil.split(connRestrictStr, ";");
if (null != entries && entries.length > 0) {
HashMap<String, String> existKeys = new HashMap<String, String>();
connRestrictEntries = new ArrayList<ConnRestrictEntry>(entries.length);
for (String entry : entries) {
// Parse "K1,K2,K3:number | *:count,number | ~:number"
int find = entry.indexOf(':');
if (find >= 1 && find < (entry.length() - 1)) {
String key = entry.substring(0, find).trim();
String value = entry.substring(find + 1).trim();
// "K1,K2,K3:number | *:count,number | ~:number"
ConnRestrictEntry connRestrictEntry = ConnRestrictEntry.parseEntry(key, value, maxPoolSize);
if (connRestrictEntry == null) {
logger.error("[connRestrict Error] parse entry error: " + entry);
} else {
// Remark entry config problem
if (0 >= connRestrictEntry.getLimits()) {
logger.error("[connRestrict Error] connection limit is 0: " + entry);
connRestrictEntry.setLimits(/* 至少允许一个连接 */1);
}
if (ConnRestrictEntry.MAX_HASH_RESTRICT_SLOT < connRestrictEntry.getHashSize()) {
logger.error("[connRestrict Error] hash size exceed maximum: " + entry);
connRestrictEntry.setHashSize(ConnRestrictEntry.MAX_HASH_RESTRICT_SLOT);
}
// Remark Key config confliction
for (String slotKey : connRestrictEntry.getKeys()) {
if (!existKeys.containsKey(slotKey)) {
existKeys.put(slotKey, entry);
} else if (ConnRestrictEntry.isWildcard(slotKey)) {
logger.error("[connRestrict Error] hash config [" + entry + "] conflict with ["
+ existKeys.get(slotKey) + "]");
} else if (ConnRestrictEntry.isNullKey(slotKey)) {
logger.error("[connRestrict Error] null-key config [" + entry + "] conflict with ["
+ existKeys.get(slotKey) + "]");
} else {
logger.error("[connRestrict Error] " + slotKey + " config [" + entry
+ "] conflict with [" + existKeys.get(slotKey) + "]");
}
}
connRestrictEntries.add(connRestrictEntry);
}
} else {
logger.error("[connRestrict Error] unknown entry: " + entry);
}
}
}
}
return connRestrictEntries;
}