http-client-branch: (cleanup) http-client-branch
authorprappo
Thu, 09 Nov 2017 20:04:33 +0300
branchhttp-client-branch
changeset 55796 dfc99ea2b65a
parent 55795 074bb951658a
child 55797 85a692428288
http-client-branch: (cleanup)
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/BufferHandler.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/ConnectionExpiredException.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/DebugLogger.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/HttpHeadersImpl.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/Utils.java
test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java
test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/FlowTest.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/BufferHandler.java	Thu Nov 09 14:28:00 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.incubator.http.internal.common;
-
-import java.nio.ByteBuffer;
-
-/**
- * Implemented by buffer pools.
- */
-public interface BufferHandler {
-
-    ByteBuffer getBuffer();
-
-    void returnBuffer(ByteBuffer buffer);
-}
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/ConnectionExpiredException.java	Thu Nov 09 14:28:00 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/ConnectionExpiredException.java	Thu Nov 09 20:04:33 2017 +0300
@@ -36,16 +36,6 @@
 
     /**
      * Constructs a {@code ConnectionExpiredException} with the specified detail
-     * message.
-     *
-     * @param   s   the detail message
-     */
-    public ConnectionExpiredException(String s) {
-        super(s);
-    }
-
-    /**
-     * Constructs a {@code ConnectionExpiredException} with the specified detail
      * message and cause.
      *
      * @param   s     the detail message
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/DebugLogger.java	Thu Nov 09 14:28:00 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/DebugLogger.java	Thu Nov 09 20:04:33 2017 +0300
@@ -188,7 +188,6 @@
         String tag = dbgTag == null ? null : dbgTag.get();
         String res = msg == null ? "" : msg;
         long elapsed = System.nanoTime() - START_NANOS;
-        long nanos =  elapsed % 1000_000;
         long millis = elapsed / 1000_000;
         long secs   = millis / 1000;
         sb.append('[').append(Thread.currentThread().getName()).append(']')
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/HttpHeadersImpl.java	Thu Nov 09 14:28:00 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/HttpHeadersImpl.java	Thu Nov 09 20:04:33 2017 +0300
@@ -49,10 +49,6 @@
         return Collections.unmodifiableMap(headers);
     }
 
-    public Map<String, List<String>> directMap() {
-        return headers;
-    }
-
     // package private mutators
 
     public HttpHeadersImpl deepCopy() {
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/Utils.java	Thu Nov 09 14:28:00 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/Utils.java	Thu Nov 09 20:04:33 2017 +0300
@@ -38,7 +38,6 @@
 import java.lang.System.Logger;
 import java.lang.System.Logger.Level;
 import java.net.InetSocketAddress;
-import java.net.NetPermission;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
@@ -50,7 +49,6 @@
 import java.util.List;
 import java.util.LinkedList;
 import java.util.Set;
-import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CompletionException;
 import java.util.function.Predicate;
 import java.util.function.Supplier;
@@ -84,7 +82,7 @@
      * if smaller allocation units preferred. HTTP/2 mandates that all
      * implementations support frame payloads of at least 16K.
      */
-    public static final int DEFAULT_BUFSIZE = 16 * 1024;
+    private static final int DEFAULT_BUFSIZE = 16 * 1024;
 
     public static final int BUFSIZE = getIntegerNetProperty(
             "jdk.httpclient.bufsize", DEFAULT_BUFSIZE
@@ -98,20 +96,10 @@
     public static final Predicate<String>
         ALLOWED_HEADERS = header -> !Utils.DISALLOWED_HEADERS_SET.contains(header);
 
-    public static final Predicate<String>
-        ALL_HEADERS = header -> true;
-
     public static ByteBuffer getBuffer() {
         return ByteBuffer.allocate(BUFSIZE);
     }
 
-    // Used when we know the max amount we want to put in the buffer
-    // In that case there's no reason to allocate a greater amount.
-    // Still not allow to allocate more than BUFSIZE.
-    public static ByteBuffer getBufferWithAtMost(int maxAmount) {
-        return ByteBuffer.allocate(Math.min(BUFSIZE, maxAmount));
-    }
-
     public static Throwable getCompletionCause(Throwable x) {
         if (!(x instanceof CompletionException)) return x;
         final Throwable cause = x.getCause();
@@ -129,22 +117,6 @@
         return new IOException(t);
     }
 
-    /**
-     * Puts position to limit and limit to capacity so we can resume reading
-     * into this buffer, but if required > 0 then limit may be reduced so that
-     * no more than required bytes are read next time.
-     */
-    static void resumeChannelRead(ByteBuffer buf, int required) {
-        int limit = buf.limit();
-        buf.position(limit);
-        int capacity = buf.capacity() - limit;
-        if (required > 0 && required < capacity) {
-            buf.limit(limit + required);
-        } else {
-            buf.limit(buf.capacity());
-        }
-    }
-
     private Utils() { }
 
     // ABNF primitives defined in RFC 7230
@@ -229,23 +201,6 @@
         return accepted;
     }
 
-    public static void checkNetPermission(String target) {
-        SecurityManager sm = System.getSecurityManager();
-        if (sm == null) {
-            return;
-        }
-        NetPermission np = new NetPermission(target);
-        sm.checkPermission(np);
-    }
-
-    public static void sleep(int millis) {
-        try {
-            Thread.sleep(millis);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
     public static int getIntegerNetProperty(String name, int defaultValue) {
         return AccessController.doPrivileged((PrivilegedAction<Integer>) () ->
                 NetProperties.getInteger(name, defaultValue));
@@ -298,7 +253,7 @@
             t.printStackTrace(p);
             s = bos.toString("US-ASCII");
         } catch (UnsupportedEncodingException ex) {
-            // can't happen
+            throw new InternalError(ex); // Can't happen
         }
         return s;
     }
@@ -331,7 +286,7 @@
      * data from a particular buffer to the last buffer in the list ( if
      * there is enough unused space ), or 2) adds it to the list.
      *
-     * @returns the number of bytes added
+     * @return the number of bytes added
      */
     public static long accumulateBuffers(List<ByteBuffer> currentList,
                                          List<ByteBuffer> buffersToAdd) {
@@ -365,13 +320,6 @@
         return accumulatedBytes;
     }
 
-    // copy up to amount from src to dst, but no more
-    public static int copyUpTo(ByteBuffer src, ByteBuffer dst, int amount) {
-        int toCopy = Math.min(src.remaining(), Math.min(dst.remaining(), amount));
-        copy(src, dst, toCopy);
-        return toCopy;
-    }
-
     /**
      * Copy amount bytes from src to dst. at least amount must be
      * available in both dst and in src
@@ -406,10 +354,6 @@
         return Arrays.toString(source.toArray());
     }
 
-    public static int remaining(ByteBuffer buf) {
-        return buf.remaining();
-    }
-
     public static long remaining(ByteBuffer[] bufs) {
         long remain = 0;
         for (ByteBuffer buf : bufs) {
@@ -481,12 +425,6 @@
         return (int) remain;
     }
 
-    // assumes buffer was written into starting at position zero
-    static void unflip(ByteBuffer buf) {
-        buf.position(buf.limit());
-        buf.limit(buf.capacity());
-    }
-
     public static void close(Closeable... closeables) {
         for (Closeable c : closeables) {
             try {
@@ -495,40 +433,7 @@
         }
     }
 
-    public static void close(Throwable t, Closeable... closeables) {
-        for (Closeable c : closeables) {
-            try {
-                ExceptionallyCloseable.close(t, c);
-            } catch (IOException ignored) { }
-        }
-    }
-
-    /**
-     * Returns an array with the same buffers, but starting at position zero
-     * in the array.
-     */
-    public static ByteBuffer[] reduce(ByteBuffer[] bufs, int start, int number) {
-        if (start == 0 && number == bufs.length) {
-            return bufs;
-        }
-        ByteBuffer[] nbufs = new ByteBuffer[number];
-        int j = 0;
-        for (int i=start; i<start+number; i++) {
-            nbufs[j++] = bufs[i];
-        }
-        return nbufs;
-    }
-
-    static String asString(ByteBuffer buf) {
-        byte[] b = new byte[buf.remaining()];
-        buf.get(b);
-        return new String(b, StandardCharsets.US_ASCII);
-    }
-
     // Put all these static 'empty' singletons here
-    @SuppressWarnings("rawtypes")
-    public static final CompletableFuture[] EMPTY_CFARRAY = new CompletableFuture[0];
-
     public static final ByteBuffer EMPTY_BYTEBUFFER = ByteBuffer.allocate(0);
     public static final ByteBuffer[] EMPTY_BB_ARRAY = new ByteBuffer[0];
     public static final List<ByteBuffer> EMPTY_BB_LIST;
@@ -648,28 +553,6 @@
     }
 
     /**
-     * Get a logger for debug HPACK traces.
-     *
-     * The logger should only be used with levels whose severity is
-     * {@code <= DEBUG}. By default, this logger will forward all messages
-     * logged to an internal logger named "jdk.internal.httpclient.hpack.debug".
-     * In addition, if the property -Djdk.internal.httpclient.hpack.debug=true
-     * is set,  it will print the messages on stdout.
-     * The logger will add some decoration to the printed message, in the form of
-     * {@code <Level>:[<thread-name>] [<elapsed-time>] <dbgTag>: <formatted message>}
-     *
-     * @param dbgTag A lambda that returns a string that identifies the caller
-     *               (e.g: "Http2Connection(SocketTube(3))/hpack.Decoder(3)")
-     *
-     * @return A logger for HPACK internal debug traces
-     */
-    public static Logger getHpackLogger(Supplier<String> dbgTag) {
-        Level errLevel = Level.OFF;
-        Level outLevel = DEBUG_HPACK ? Level.ALL : Level.OFF;
-        return DebugLogger.createHpackLogger(dbgTag, outLevel, errLevel);
-    }
-
-    /**
      * Get a logger for debug HPACK traces.The logger should only be used
      * with levels whose severity is {@code <= DEBUG}.
      *
@@ -734,5 +617,4 @@
         Level outLevel = on ? Level.ALL : Level.OFF;
         return getHpackLogger(dbgTag, outLevel);
     }
-
 }
--- a/test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java	Thu Nov 09 14:28:00 2017 +0000
+++ b/test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java	Thu Nov 09 20:04:33 2017 +0300
@@ -39,7 +39,6 @@
 import java.util.concurrent.ExecutorService;
 import java.util.function.Consumer;
 import jdk.incubator.http.internal.common.ByteBufferReference;
-import jdk.incubator.http.internal.common.BufferHandler;
 import jdk.incubator.http.internal.common.HttpHeadersImpl;
 import jdk.incubator.http.internal.common.Queue;
 import jdk.incubator.http.internal.frame.DataFrame;
@@ -236,22 +235,6 @@
         exec.submit(this::writeLoop);
     }
 
-    static class BufferPool implements BufferHandler {
-
-        public void setMinBufferSize(int size) {
-        }
-
-        @Override
-        public ByteBuffer getBuffer() {
-            int size = 32 * 1024;
-            return ByteBuffer.allocate(size);
-        }
-
-        @Override
-        public void returnBuffer(ByteBuffer buffer) {
-        }
-    }
-
     private void writeFrame(Http2Frame frame) throws IOException {
         ByteBufferReference[] refs = new FramesEncoder().encodeFrame(frame);
         //System.err.println("TestServer: Writing frame " + frame.toString());
--- a/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/FlowTest.java	Thu Nov 09 14:28:00 2017 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/FlowTest.java	Thu Nov 09 20:04:33 2017 +0300
@@ -228,7 +228,7 @@
                     if (n == -1) {
                         System.out.println("clientReader close");
                         publisher.close();
-                        Utils.sleep(2000);
+                        sleep(2000);
                         Utils.close(is, clientSock);
                         return;
                     }
@@ -294,7 +294,7 @@
                 while (true) {
                     int n = is.read(bb);
                     if (n == -1) {
-                        Utils.sleep(2000);
+                        sleep(2000);
                         is.close();
                         serverSock.close();
                         return;
@@ -503,4 +503,12 @@
             return ssl;
         }
     }
+
+    private static void sleep(int millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 }