From 3c61ba0e7aec4ffc3f84ead93101cbef8e8553e2 Mon Sep 17 00:00:00 2001 From: tanyawen Date: Sat, 28 Dec 2019 00:08:45 +0800 Subject: [PATCH] feature: add socket connection pool --- .../org/csource/fastdfs/TrackerServer.java | 20 +++++++++++++------ .../csource/fastdfs/pool/ConnectionPool.java | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/csource/fastdfs/TrackerServer.java b/src/main/java/org/csource/fastdfs/TrackerServer.java index cab264a..bfce3b4 100644 --- a/src/main/java/org/csource/fastdfs/TrackerServer.java +++ b/src/main/java/org/csource/fastdfs/TrackerServer.java @@ -86,12 +86,20 @@ public class TrackerServer { if (ClientGlobal.g_connection_pool_enabled) { ConnectionPool.freeConnection(this); } else { - if (this.sock != null) { - try { - ProtoCommon.closeSocket(this.sock); - } finally { - this.sock = null; - } + this.closeDirect(); + } + } + + /** + * close direct if not create from pool or not open pool + * @throws IOException + */ + public void closeDirect() throws IOException { + if (this.sock != null) { + try { + ProtoCommon.closeSocket(this.sock); + } finally { + this.sock = null; } } } diff --git a/src/main/java/org/csource/fastdfs/pool/ConnectionPool.java b/src/main/java/org/csource/fastdfs/pool/ConnectionPool.java index cb4b803..5e92ec5 100644 --- a/src/main/java/org/csource/fastdfs/pool/ConnectionPool.java +++ b/src/main/java/org/csource/fastdfs/pool/ConnectionPool.java @@ -38,7 +38,7 @@ public class ConnectionPool { ConnectionManager connectionManager = CP.get(key); connectionManager.closeConnection(new ConnectionInfo(trackerServer.getSocket(), trackerServer.getInetSocketAddress(),trackerServer.getLastAccessTime(),true)); } else { - trackerServer.close(); + trackerServer.closeDirect(); } } @@ -51,7 +51,7 @@ public class ConnectionPool { ConnectionManager connectionManager = CP.get(key); connectionManager.freeConnection(trackerServer); } else { - trackerServer.close(); + trackerServer.closeDirect(); } }