本文整理汇总了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);
}
示例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());
}
示例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());
}
示例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;
}
示例5: getConnRestrictEntries
import com.taobao.tddl.atom.utils.ConnRestrictEntry; //导入依赖的package包/类
public List<ConnRestrictEntry> getConnRestrictEntries() {
return connRestrictEntries;
}
示例6: setConnRestrictEntries
import com.taobao.tddl.atom.utils.ConnRestrictEntry; //导入依赖的package包/类
public void setConnRestrictEntries(List<ConnRestrictEntry> connRestrictEntries) {
this.connRestrictEntries = connRestrictEntries;
}