xlang v4.0 Release
程序设计语言基础库文档
载入中...
搜索中...
未找到
结构体 | Public 成员函数 | 包函数 | 包属性 | 静态包属性
ConnectionPool类 参考

结构体

class  connectorMgr
 

Public 成员函数

包函数

包属性

静态包属性

详细描述

在文件 xsql.xcs26 行定义.

成员函数说明

◆ allocate()

Connection allocate ( )
package

在文件 xsql.xcs44 行定义.

44 {
45 Connection connector = callback.createConnection();
46 if (connector != nilptr){
48 }
49 return connector;
50 }
ConnPoolCallback callback
Definition xsql.xcs:41

引用了 List<_V>.List().

◆ clear()

void clear ( )

在文件 xsql.xcs194 行定义.

194 {
195 synchronized(_pool){
196 _pool.clear();
198 _wait_time = 0;
199 _maxConnect = 0;
200 _maxIdle = 0;
201 _active_cnt = 0;
203 }
204 }
void clear()
void clear()
List<connectorMgr> _pool
Definition xsql.xcs:32
static const int TIMEOU_LIMIT
Definition xsql.xcs:35
Map<int, bool> _error_map
Definition xsql.xcs:33

引用了 List<_V>.clear() , 以及 Map<_K, _V>.clear().

◆ config()

bool config ( ConnPoolCallback  _callback,
String  reset_error,
int  maxWait,
int  maxConnect,
int  maxIdle,
int  maxIdleTime,
int  validtesttime 
)

配置线程池:

参数
_callback回调
reset_error当出现这些错误时 并不关闭连接 "2003,2013"
maxWait最大等待数
maxConnect最大连接数
maxIdle最大空闲数
maxIdleTime最大空闲时间
validtesttime校验时间

在文件 xsql.xcs159 行定义.

159 {
160
161 if (maxIdle != 0 && maxConnect != 0 && maxIdle >= maxConnect){
162 throw new IllegalArgumentException("Connector config failed : maxIdle >= maxConnect\n");
163 return false;
164 }
165
166 if (_callback == nilptr){
167 return false;
168 }
169
170 callback = _callback;
171
172 _validtesttime = validtesttime;
173
174 if (reset_error != nilptr){
175 String err_list = reset_error;
176 String[] elist = err_list.split(',');
177 for (int i = 0; i < elist.length; i++){
178 String str = elist[i];
179 str.trim(true);
180 _error_map.put(str.parseInt(), true);
181 }
182 }
183
184 if (maxWait != -1){
185 _wait_time = maxWait;
186 }
187
188 _maxIdle = maxIdle;
189 _maxConnect = maxConnect;
190 _maxIdleTime = maxIdleTime;
191 return true;
192 }
Iterator put(K, V)
字符串类
int length()
String trim(bool)
String [] split(String)
int parseInt()

引用了 List<_V>.List(), Map<_K, _V>.put(), String.split() , 以及 String.trim().

◆ getConnector()

Connection getConnector ( )

在文件 xsql.xcs52 行定义.

52 {
53 Connection connector = nilptr;
54 long lastactive = 0;
55
56 synchronized(_pool){
57 if (_maxConnect != 0){
58 while ((_pool.size() == 0) && (_active_cnt >= _maxConnect)){
59 _pool.wait();
60 }
61 }
62
63 do{
64 if (connector != nilptr){
66 connector.close();
67 connector = nilptr;
68 }
69
70 lastactive = 0;
71
72 List.Iterator<connectorMgr> iter = _pool.iterator();
73 if (iter.hasNext()){
74 connectorMgr mgr = iter.get();
75 connector = mgr.pconnection;
76 lastactive = mgr.timestamp;
77 _pool.remove(iter);
78 }else{
79 break;
80 }
81
82 } while (test(connector, lastactive) == false);
83
84 if (connector == nilptr){
85 if ((_maxConnect == 0) || (_active_cnt < _maxConnect)){
86 connector = allocate();
87 }
88 }
89 }
90 return connector;
91 }
map的迭代器对象
Definition List.xcs:11
map容器
Definition List.xcs:6
Iterator iterator()
void remove(Iterator)
int size()
Connection allocate()
Definition xsql.xcs:44
bool test(Connection conn, long lastactive)
Definition xsql.xcs:93

引用了 List<_V>.iterator(), List<_V>.List(), List<_V>.remove() , 以及 List<_V>.size().

◆ recycle()

void recycle ( Connection  connection)

在文件 xsql.xcs100 行定义.

100 {
101
102 int mysql_error = connection.getErrorCode();
103
104 if (_error_map.containsKey(mysql_error) == false){
105 synchronized(_pool){
106 connectorMgr mgr = new connectorMgr();
107 mgr.pconnection = connection;
108 mgr.timestamp = _system_.currentTimeMillis();
109
110 if (_maxIdleTime != 0){
111 List.Iterator<connectorMgr> it = _pool.iterator();
112
113 while (it != nilptr && it.hasNext()){
114 List.Iterator<connectorMgr> tmp = it.getNext();
115 connectorMgr pmt = it.get();
116
117 if ((mgr.timestamp - pmt.timestamp) > _maxIdleTime){
118 pmt.pconnection.close();
119 _pool.remove(it);
120 _active_cnt--;
121 }
122 it = tmp;
123 }
124 }
125
126
127
128 if (_maxIdle != 0){
129 while (_pool.size() > _maxIdle){
130 List.Iterator<connectorMgr> tmp = _pool.iterator();
131 connectorMgr pmt = tmp.get();
132 pmt.pconnection.close();
133 _pool.remove(tmp);
134 _active_cnt--;
135 }
136 }
137 _pool.add(mgr);
138 _pool.notify();
139 }
140 } else{
141 connection.close();
142 synchronized(_pool){
143 _active_cnt--;
144 }
145 }
146 }
系统和IO相关
static final long currentTimeMillis()
_V get()
获取当前的值对象
void add(T)
bool containsKey(K)

引用了 List<_V>.add(), Map<_K, _V>.containsKey(), _system_.currentTimeMillis(), List<_V>.Iterator<_V>.get(), List<_V>.iterator(), List<_V>.List(), List<_V>.remove() , 以及 List<_V>.size().

◆ test()

bool test ( Connection  conn,
long  lastactive 
)
package

在文件 xsql.xcs93 行定义.

93 {
94 if ( (_system_.currentTimeMillis() - lastactive) > _validtesttime){
95 return callback.alive(conn);
96 }
97 return true;
98 }

引用了 _system_.currentTimeMillis() , 以及 List<_V>.List().

结构体成员变量说明

◆ _active_cnt

int _active_cnt
package

在文件 xsql.xcs38 行定义.

◆ _error_map

Map<int, bool> _error_map = new Map<int, bool>()
package

在文件 xsql.xcs33 行定义.

◆ _maxConnect

int _maxConnect
package

在文件 xsql.xcs37 行定义.

◆ _maxIdle

int _maxIdle
package

在文件 xsql.xcs39 行定义.

◆ _maxIdleTime

int _maxIdleTime
package

在文件 xsql.xcs39 行定义.

◆ _pool

List<connectorMgr> _pool = new List<connectorMgr>()
package

在文件 xsql.xcs32 行定义.

◆ _validtesttime

int _validtesttime
package

在文件 xsql.xcs39 行定义.

◆ _wait_time

int _wait_time
package

在文件 xsql.xcs38 行定义.

◆ callback

ConnPoolCallback callback
package

在文件 xsql.xcs41 行定义.

◆ TIMEOU_LIMIT

const int TIMEOU_LIMIT = 300000
staticpackage

在文件 xsql.xcs35 行定义.