use of com.alibaba.cobar.mysql.bio.Channel in project cobar by alibaba.
the class MySQLDataSource method releaseChannel.
public void releaseChannel(Channel c) {
// 状态检查
if (c == null || c.isClosed()) {
return;
}
// 释放资源
final ReentrantLock lock = this.lock;
lock.lock();
try {
final Channel[] items = this.items;
for (int i = 0; i < items.length; i++) {
if (items[i] == null) {
++idleCount;
--activeCount;
c.setLastActiveTime(TimeUtil.currentTimeMillis());
items[i] = c;
return;
}
}
} finally {
lock.unlock();
}
// 关闭多余的资源
c.close();
}
use of com.alibaba.cobar.mysql.bio.Channel in project cobar by alibaba.
the class MySQLDataNode method getChannel.
/**
* 取得数据源通道
*/
public Channel getChannel(int i) throws Exception {
if (initSuccess) {
Channel c = sources[i].getChannel();
++executeCount;
return c;
} else {
throw new IllegalArgumentException("Invalid DataSource:" + i);
}
}
use of com.alibaba.cobar.mysql.bio.Channel in project cobar by alibaba.
the class MySQLDataNode method initSource.
private boolean initSource(MySQLDataSource ds, int size) {
boolean success = true;
Channel[] list = new Channel[size < ds.size() ? size : ds.size()];
for (int i = 0; i < list.length; i++) {
try {
list[i] = ds.getChannel();
} catch (Exception e) {
success = false;
LOGGER.warn(getMessage(ds.getIndex(), " init error."), e);
break;
}
}
for (Channel c : list) {
if (c == null) {
continue;
}
if (success) {
c.release();
} else {
c.close();
}
}
return success;
}
use of com.alibaba.cobar.mysql.bio.Channel in project cobar by alibaba.
the class MySQLChannelMain method main.
public static void main(String[] args) throws Exception {
MySQLChannelMain test = new MySQLChannelMain();
Channel channel = test.getChannel();
channel.close();
}
Aggregations