From 66f3fff05e32af95ef129febc22e6c28c87b030a Mon Sep 17 00:00:00 2001 From: tanyawen Date: Mon, 30 Dec 2019 20:35:21 +0800 Subject: [PATCH] fix:use global var --- src/main/java/org/csource/fastdfs/ClientGlobal.java | 12 ------------ .../org/csource/fastdfs/pool/ConnectionManager.java | 12 ++++++------ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/csource/fastdfs/ClientGlobal.java b/src/main/java/org/csource/fastdfs/ClientGlobal.java index b102fdc..d364ac9 100644 --- a/src/main/java/org/csource/fastdfs/ClientGlobal.java +++ b/src/main/java/org/csource/fastdfs/ClientGlobal.java @@ -331,18 +331,6 @@ public class ClientGlobal { 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() { String trackerServers = ""; if (g_tracker_group != null) { diff --git a/src/main/java/org/csource/fastdfs/pool/ConnectionManager.java b/src/main/java/org/csource/fastdfs/pool/ConnectionManager.java index cd9ccae..69fe51e 100644 --- a/src/main/java/org/csource/fastdfs/pool/ConnectionManager.java +++ b/src/main/java/org/csource/fastdfs/pool/ConnectionManager.java @@ -53,23 +53,23 @@ public class ConnectionManager { if (freeCount.get() > 0) { freeCount.decrementAndGet(); 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); 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); totalCount.incrementAndGet(); } else { 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 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) { 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; @@ -110,7 +110,7 @@ public class ConnectionManager { @Override public String toString() { return "ConnectionManager{" + - "ip:port='" + inetSocketAddress.getHostName() + ":" + inetSocketAddress.getPort() + + "ip:port='" + inetSocketAddress.getAddress().getHostAddress() + ":" + inetSocketAddress.getPort() + ", totalCount=" + totalCount + ", freeCount=" + freeCount + ", freeConnections =" + freeConnections +