accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [3/6] accumulo git commit: ACCUMULO-4067 Avoid repeatedly fetching the NetUtils#getInputStream method.
Date Fri, 04 Dec 2015 21:28:30 GMT
ACCUMULO-4067 Avoid repeatedly fetching the NetUtils#getInputStream method.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/4eb80855
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/4eb80855
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/4eb80855

Branch: refs/heads/master
Commit: 4eb80855f7185cc143b3d43928e57e19d5d761ef
Parents: 4d952ac
Author: Josh Elser <elserj@apache.org>
Authored: Fri Dec 4 16:19:51 2015 -0500
Committer: Josh Elser <elserj@apache.org>
Committed: Fri Dec 4 16:19:51 2015 -0500

----------------------------------------------------------------------
 .../accumulo/core/util/TTimeoutTransport.java   | 21 ++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/4eb80855/core/src/main/java/org/apache/accumulo/core/util/TTimeoutTransport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/TTimeoutTransport.java b/core/src/main/java/org/apache/accumulo/core/util/TTimeoutTransport.java
index 60ae292..1eac8be 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/TTimeoutTransport.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/TTimeoutTransport.java
@@ -35,10 +35,27 @@ import com.google.common.net.HostAndPort;
 
 public class TTimeoutTransport {
 
+  private static volatile Method GET_INPUT_STREAM_METHOD = null;
+
+  private static Method getNetUtilsInputStreamMethod() {
+    if (null == GET_INPUT_STREAM_METHOD) {
+      synchronized (TTimeoutTransport.class) {
+        if (null == GET_INPUT_STREAM_METHOD) {
+          try {
+            GET_INPUT_STREAM_METHOD = NetUtils.class.getMethod("getInputStream", Socket.class,
Long.TYPE);
+          } catch (Exception e) {
+            throw new RuntimeException(e);
+          }
+        }
+      }
+    }
+
+    return GET_INPUT_STREAM_METHOD;
+  }
+
   private static InputStream getInputStream(Socket socket, long timeout) {
     try {
-      Method m = NetUtils.class.getMethod("getInputStream", Socket.class, Long.TYPE);
-      return (InputStream) m.invoke(null, socket, timeout);
+      return (InputStream) getNetUtilsInputStreamMethod().invoke(null, socket, timeout);
     } catch (Exception e) {
       throw new RuntimeException(e);
     }


Mime
View raw message