當前位置: 首頁>>代碼示例>>Java>>正文


Java ConnRestrictEntry.isNullKey方法代碼示例

本文整理匯總了Java中com.taobao.tddl.atom.utils.ConnRestrictEntry.isNullKey方法的典型用法代碼示例。如果您正苦於以下問題:Java ConnRestrictEntry.isNullKey方法的具體用法?Java ConnRestrictEntry.isNullKey怎麽用?Java ConnRestrictEntry.isNullKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.taobao.tddl.atom.utils.ConnRestrictEntry的用法示例。


在下文中一共展示了ConnRestrictEntry.isNullKey方法的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;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:60,代碼來源:TAtomConfParser.java


注:本文中的com.taobao.tddl.atom.utils.ConnRestrictEntry.isNullKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。