fix:use global var

dev
tanyawen 2019-12-30 20:35:21 +08:00
parent 4300ca717a
commit 66f3fff05e
2 changed files with 6 additions and 18 deletions

View File

@ -331,18 +331,6 @@ public class ClientGlobal {
return g_connection_pool_enabled; return g_connection_pool_enabled;
} }
public static int getG_connection_pool_max_count_per_entry() {
return g_connection_pool_max_count_per_entry;
}
public static int getG_connection_pool_max_idle_time() {
return g_connection_pool_max_idle_time;
}
public static int getG_connection_pool_max_wait_time_in_ms() {
return g_connection_pool_max_wait_time_in_ms;
}
public static String configInfo() { public static String configInfo() {
String trackerServers = ""; String trackerServers = "";
if (g_tracker_group != null) { if (g_tracker_group != null) {

View File

@ -53,23 +53,23 @@ public class ConnectionManager {
if (freeCount.get() > 0) { if (freeCount.get() > 0) {
freeCount.decrementAndGet(); freeCount.decrementAndGet();
connection = freeConnections.poll(); connection = freeConnections.poll();
if (!connection.isAvaliable() || (System.currentTimeMillis() - connection.getLastAccessTime()) > ClientGlobal.getG_connection_pool_max_idle_time()) { if (!connection.isAvaliable() || (System.currentTimeMillis() - connection.getLastAccessTime()) > ClientGlobal.g_connection_pool_max_idle_time) {
closeConnection(connection); closeConnection(connection);
continue; continue;
} }
} else if (ClientGlobal.getG_connection_pool_max_count_per_entry() == 0 || totalCount.get() < ClientGlobal.getG_connection_pool_max_count_per_entry()) { } else if (ClientGlobal.g_connection_pool_max_count_per_entry == 0 || totalCount.get() < ClientGlobal.g_connection_pool_max_count_per_entry) {
connection = ConnectionFactory.create(this.inetSocketAddress); connection = ConnectionFactory.create(this.inetSocketAddress);
totalCount.incrementAndGet(); totalCount.incrementAndGet();
} else { } else {
try { try {
if (condition.await(ClientGlobal.getG_connection_pool_max_wait_time_in_ms(), TimeUnit.MILLISECONDS)) { if (condition.await(ClientGlobal.g_connection_pool_max_wait_time_in_ms, TimeUnit.MILLISECONDS)) {
//wait single success //wait single success
continue; continue;
} }
throw new MyException("connect to server " + inetSocketAddress.getHostName() + ":" + inetSocketAddress.getPort() + " fail, wait_time > " + ClientGlobal.g_connection_pool_max_wait_time_in_ms + "ms"); throw new MyException("connect to server " + inetSocketAddress.getAddress().getHostAddress() + ":" + inetSocketAddress.getPort() + " fail, wait_time > " + ClientGlobal.g_connection_pool_max_wait_time_in_ms + "ms");
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
throw new MyException("connect to server " + inetSocketAddress.getHostName() + ":" + inetSocketAddress.getPort() + " fail, emsg:" + e.getMessage()); throw new MyException("connect to server " + inetSocketAddress.getAddress().getHostAddress() + ":" + inetSocketAddress.getPort() + " fail, emsg:" + e.getMessage());
} }
} }
return connection; return connection;
@ -110,7 +110,7 @@ public class ConnectionManager {
@Override @Override
public String toString() { public String toString() {
return "ConnectionManager{" + return "ConnectionManager{" +
"ip:port='" + inetSocketAddress.getHostName() + ":" + inetSocketAddress.getPort() + "ip:port='" + inetSocketAddress.getAddress().getHostAddress() + ":" + inetSocketAddress.getPort() +
", totalCount=" + totalCount + ", totalCount=" + totalCount +
", freeCount=" + freeCount + ", freeCount=" + freeCount +
", freeConnections =" + freeConnections + ", freeConnections =" + freeConnections +