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


Java ConnRestrictEntry類代碼示例

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


ConnRestrictEntry類屬於com.taobao.tddl.atom.utils包,在下文中一共展示了ConnRestrictEntry類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import com.taobao.tddl.atom.utils.ConnRestrictEntry; //導入依賴的package包/類
public void init() {
    // changyuan.lh: 初始化連接分桶
    final String datasourceKey = connectionProperties.datasourceName;
    List<ConnRestrictEntry> connRestrictEntries = runTimeConf.getConnRestrictEntries();
    if (connRestrictEntries != null) {
        this.connRestrictor = new ConnRestrictor(datasourceKey, connRestrictEntries);
    }
    this.statConnNumber = Monitor.connStat(datasourceKey, "-", Monitor.KEY3_CONN_NUMBER);
    this.statConnBlocking = Monitor.connStat(datasourceKey, "-", Monitor.KEY3_CONN_BLOCKING);

    // timerTask = new TimerTaskC();
    Monitor.addSnapshotValuesCallbask(this);
    // Monitor.addGlobalConfigListener(globalConfigListener);
    // timer.schedule(timerTask, 0,
    // this.connectionProperties.timeSliceInMillis);
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:17,代碼來源:TDataSourceWrapper.java

示例2: for

import com.taobao.tddl.atom.utils.ConnRestrictEntry; //導入依賴的package包/類
@Test
public void findSlot_HASH槽測試() {
    String connRestrictStr = "*:80%";
    List<ConnRestrictEntry> connRestrictEntries = TAtomConfParser.parseConnRestrictEntries(connRestrictStr, 30);
    for (ConnRestrictEntry connRestrictEntry : connRestrictEntries) {
        System.out.println(connRestrictEntry.toString());
    }
    ConnRestrictor connRestrictor = new ConnRestrictor("TEST", connRestrictEntries);
    ConnRestrictSlot slotK1 = connRestrictor.findSlot("K1");
    ConnRestrictSlot slotK2 = connRestrictor.findSlot("K2");
    ConnRestrictSlot slotK3 = connRestrictor.findSlot("K3");
    ConnRestrictSlot slotNull = connRestrictor.findSlot(null);
    Assert.assertNotNull(slotK1);
    Assert.assertNotNull(slotK2);
    Assert.assertNotNull(slotK3);
    Assert.assertNull(slotNull);

    Assert.assertSame(slotK1, slotK2);
    Assert.assertSame(slotK2, slotK3);
    Assert.assertEquals(24, slotK1.getLimits());
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:22,代碼來源:ConnRestrictorUnitTest.java

示例3: for

import com.taobao.tddl.atom.utils.ConnRestrictEntry; //導入依賴的package包/類
@Test
public void parseConnRestrictEntries_解析應用連接限製() {
    String connRestrictStr = "K1,K2,K3,,K4:80%; K5:60%; K6,K7,:90%; ,K8:1%; K9,:10; ,K10,K11:70%; *:16,50%; *:40%; *:,30%; ~:20;";
    List<ConnRestrictEntry> connRestrictEntries = TAtomConfParser.parseConnRestrictEntries(connRestrictStr, 30);
    for (ConnRestrictEntry connRestrictEntry : connRestrictEntries) {
        System.out.println(connRestrictEntry.toString());
    }
    Assert.assertEquals(10, connRestrictEntries.size());
    Assert.assertEquals(24, connRestrictEntries.get(0).getLimits());
    Assert.assertEquals(18, connRestrictEntries.get(1).getLimits());
    Assert.assertEquals(27, connRestrictEntries.get(2).getLimits());
    Assert.assertEquals(1, connRestrictEntries.get(3).getLimits());
    Assert.assertEquals(10, connRestrictEntries.get(4).getLimits());
    Assert.assertEquals(21, connRestrictEntries.get(5).getLimits());
    Assert.assertEquals(16, connRestrictEntries.get(6).getHashSize());
    Assert.assertEquals(15, connRestrictEntries.get(6).getLimits());
    Assert.assertEquals(1, connRestrictEntries.get(7).getHashSize());
    Assert.assertEquals(12, connRestrictEntries.get(7).getLimits());
    Assert.assertEquals(1, connRestrictEntries.get(8).getHashSize());
    Assert.assertEquals(9, connRestrictEntries.get(8).getLimits());
    Assert.assertEquals(20, connRestrictEntries.get(9).getLimits());
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:23,代碼來源:TAtomConfParserUnitTest.java

示例4: 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

示例5: getConnRestrictEntries

import com.taobao.tddl.atom.utils.ConnRestrictEntry; //導入依賴的package包/類
public List<ConnRestrictEntry> getConnRestrictEntries() {
    return connRestrictEntries;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:4,代碼來源:TAtomDsConfDO.java

示例6: setConnRestrictEntries

import com.taobao.tddl.atom.utils.ConnRestrictEntry; //導入依賴的package包/類
public void setConnRestrictEntries(List<ConnRestrictEntry> connRestrictEntries) {
    this.connRestrictEntries = connRestrictEntries;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:4,代碼來源:TAtomDsConfDO.java


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