[hg] cnd-main: Traffic is slow when measurements are on.

  • From: Andrew Krasny < >
  • To:
  • Subject: [hg] cnd-main: Traffic is slow when measurements are on.
  • Date: Mon, 24 Dec 2012 05:10:44 -0800

changeset 3ac6c6e851d8 in cnd-main ((none))
details: http://hg.netbeans.org/cnd-main/rev/3ac6c6e851d8
description:
        Traffic is slow when measurements are on.

        Re-defined missing methods... to avoid 1-byte-per-operation I/O

diffstat:

 
dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/jsch/MeasurableSocketFactory.java
 |  142 +++++++--
 1 files changed, 103 insertions(+), 39 deletions(-)

diffs (161 lines):

diff --git 
a/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/jsch/MeasurableSocketFactory.java
 
b/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/jsch/MeasurableSocketFactory.java
--- 
a/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/jsch/MeasurableSocketFactory.java
+++ 
b/dlight.nativeexecution/src/org/netbeans/modules/nativeexecution/jsch/MeasurableSocketFactory.java
@@ -91,49 +91,12 @@
 
     @Override
     public InputStream getInputStream(Socket socket) throws IOException {
-        final InputStream sis = socket.getInputStream();
-        InputStream is = new InputStream() {
-            @Override
-            public int read() throws IOException {
-                int res = sis.read();
-                fireDownload(1);
-                return res;
-            }
-
-            @Override
-            public int available() throws IOException {
-                return sis.available();
-            }
-
-            @Override
-            public void close() throws IOException {
-                sis.close();
-            }
-        };
-        return is;
+        return new MyIS(socket.getInputStream());
     }
 
     @Override
     public OutputStream getOutputStream(Socket socket) throws IOException {
-        final OutputStream sos = socket.getOutputStream();
-        OutputStream os = new OutputStream() {
-            @Override
-            public void write(int b) throws IOException {
-                fireUpload(1);
-                sos.write(b);
-            }
-
-            @Override
-            public void close() throws IOException {
-                sos.close();
-            }
-
-            @Override
-            public void flush() throws IOException {
-                sos.flush();
-            }
-        };
-        return os;
+        return new MyOS(socket.getOutputStream());
     }
 
     private void fireDownload(int bytes) {
@@ -154,4 +117,105 @@
 
         public void bytesDownloaded(int bytes);
     }
+
+    private final class MyIS extends InputStream {
+
+        private final InputStream in;
+
+        MyIS(InputStream is) {
+            this.in = is;
+        }
+
+        @Override
+        public int read() throws IOException {
+            int res = in.read();
+            fireDownload(res);
+            return res;
+        }
+
+        @Override
+        public int read(byte[] b) throws IOException {
+            int res = in.read(b);
+            fireDownload(res);
+            return res;
+        }
+
+        @Override
+        public int read(byte[] b, int off, int len) throws IOException {
+            int res = in.read(b, off, len);
+            fireDownload(res);
+            return res;
+        }
+
+        @Override
+        public void close() throws IOException {
+            in.close();
+        }
+
+        @Override
+        public int available() throws IOException {
+            return in.available();
+        }
+
+        @Override
+        public synchronized void mark(int readlimit) {
+            in.mark(readlimit);
+        }
+
+        @Override
+        public boolean markSupported() {
+            return in.markSupported();
+        }
+
+        @Override
+        public synchronized void reset() throws IOException {
+            in.reset();
+        }
+
+        @Override
+        public long skip(long n) throws IOException {
+            return in.skip(n);
+        }
+    }
+
+    private final class MyOS extends OutputStream {
+
+        private final OutputStream out;
+
+        MyOS(OutputStream out) {
+            this.out = out;
+        }
+
+        @Override
+        public void write(int b) throws IOException {
+            out.write(b);
+            fireUpload(1);
+        }
+
+        @Override
+        public void write(byte[] b) throws IOException {
+            out.write(b);
+            fireUpload(b.length);
+        }
+
+        @Override
+        public void write(byte[] b, int off, int len) throws IOException {
+            out.write(b, off, len);
+            fireUpload(len);
+        }
+
+        @Override
+        public void close() throws IOException {
+            try {
+                out.flush();
+            } finally {
+                out.close();
+            }
+        }
+
+        @Override
+        public void flush() throws IOException {
+            out.flush();
+        }
+    }
 }

[hg] cnd-main: Traffic is slow when measurements are on.

Andrew Krasny 12/24/2012

Project Features

About this Project

CND was started in November 2009, is owned by Leonid Lenyashin, and has 130 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close