author | dfuchs |
Mon, 23 Apr 2018 15:45:40 +0100 | |
branch | http-client-branch |
changeset 56474 | fe2bf7b369b8 |
permissions | -rw-r--r-- |
56474
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
1 |
/* |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
4 |
* |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
10 |
* |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
15 |
* accompanied this code). |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
16 |
* |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
20 |
* |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
23 |
* questions. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
24 |
*/ |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
25 |
package jdk.internal.net.http.common; |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
26 |
|
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
27 |
import java.nio.ByteBuffer; |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
28 |
import java.util.concurrent.ConcurrentLinkedQueue; |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
29 |
import java.util.function.Supplier; |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
30 |
|
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
31 |
/** |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
32 |
* This interface allows to recycle buffers used for SSL decryption. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
33 |
* Buffers that are used for reading SSL encrypted data are typically |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
34 |
* very short lived, as it is necessary to aggregate their content |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
35 |
* before calling SSLEngine::unwrap. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
36 |
* Because both reading and copying happen in the SelectorManager |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
37 |
* thread, then it makes it possible to pool these buffers and |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
38 |
* recycle them for the next socket read, instead of simply |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
39 |
* letting them be GC'ed. That also makes it possible to use |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
40 |
* direct byte buffers, and avoid another layer of copying by |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
41 |
* the SocketChannel implementation. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
42 |
* |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
43 |
* The HttpClientImpl has an implementation of this interface |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
44 |
* that allows to reuse the same 3 direct buffers for reading |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
45 |
* off SSL encrypted data from the socket. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
46 |
* The BufferSupplier::get method is called by SocketTube |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
47 |
* (see SocketTube.SSLDirectBufferSource) and BufferSupplier::recycle |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
48 |
* is called by SSLFlowDelegate.Reader. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
49 |
**/ |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
50 |
public interface BufferSupplier extends Supplier<ByteBuffer> { |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
51 |
/** |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
52 |
* Returns a buffer to read encrypted data off the socket. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
53 |
* @return a buffer to read encrypted data off the socket. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
54 |
*/ |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
55 |
ByteBuffer get(); |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
56 |
|
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
57 |
/** |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
58 |
* Returns a buffer to the pool. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
59 |
* |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
60 |
* @param buffer This must be a buffer previously obtained |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
61 |
* by calling BufferSupplier::get. The caller must |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
62 |
* not touch the buffer after returning it to |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
63 |
* the pool. |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
64 |
*/ |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
65 |
void recycle(ByteBuffer buffer); |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
66 |
} |
fe2bf7b369b8
http-client-branch: use direct buffer pool for reading off SSL encrypted buffers from the socket + minor test fixes.
dfuchs
parents:
diff
changeset
|
67 |