当前位置: 首页>>代码示例>>Java>>正文


Java ConnRestrictEntry.MAX_HASH_RESTRICT_SLOT属性代码示例

本文整理汇总了Java中com.taobao.tddl.atom.utils.ConnRestrictEntry.MAX_HASH_RESTRICT_SLOT属性的典型用法代码示例。如果您正苦于以下问题:Java ConnRestrictEntry.MAX_HASH_RESTRICT_SLOT属性的具体用法?Java ConnRestrictEntry.MAX_HASH_RESTRICT_SLOT怎么用?Java ConnRestrictEntry.MAX_HASH_RESTRICT_SLOT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.taobao.tddl.atom.utils.ConnRestrictEntry的用法示例。


在下文中一共展示了ConnRestrictEntry.MAX_HASH_RESTRICT_SLOT属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseConnRestrictEntries

/**
 * 解析应用连接限制, 完整格式是:
 * "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,代码行数:59,代码来源:TAtomConfParser.java


注:本文中的com.taobao.tddl.atom.utils.ConnRestrictEntry.MAX_HASH_RESTRICT_SLOT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。