src/java.net.http/share/classes/jdk/internal/net/http/websocket/MessageQueue.java
author chegar
Wed, 02 May 2018 02:36:17 -0700
changeset 49944 4690a2871b44
parent 49765 ee6f7a61f3a5
child 56451 9585061fdb04
permissions -rw-r--r--
8202423: Small HTTP Client refresh Reviewed-by: chegar, dfuchs, michaelm, prappo Contributed-by: Chris Hegarty <chris.hegarty@oracle.com>, Daniel Fuchs <daniel.fuchs@oracle.com>, Michael McMahon <michael.x.mcmahon@oracle.com>, Pavel Rappo <pavel.rappo@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     1
/*
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     4
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    10
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    15
 * accompanied this code).
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    16
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    20
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    23
 * questions.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    24
 */
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    25
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    26
package jdk.internal.net.http.websocket;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    27
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    28
import java.io.IOException;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    29
import java.nio.ByteBuffer;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    30
import java.nio.CharBuffer;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    31
import java.util.concurrent.CompletableFuture;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    32
import java.util.concurrent.atomic.AtomicInteger;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    33
import java.util.function.BiConsumer;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    34
import java.util.function.Supplier;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    35
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    36
import static jdk.internal.net.http.common.Utils.pow2Size;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    37
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    38
/*
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    39
 * A FIFO message storage facility.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    40
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    41
 * The queue supports at most one consumer and an arbitrary number of producers.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    42
 * Methods `peek`, `remove` and `isEmpty` must not be invoked concurrently.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    43
 * Methods `addText`, `addBinary`, `addPing`, `addPong` and `addClose` may be
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    44
 * invoked concurrently.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    45
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    46
 * This queue is of a bounded size. The queue pre-allocates array of the said
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    47
 * size and fills it with `Message` elements. The resulting structure never
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    48
 * changes. This allows to avoid re-allocation and garbage collection of
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    49
 * elements and arrays thereof. For this reason `Message` elements are never
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    50
 * returned from the `peek` method. Instead their components passed to the
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    51
 * provided callback.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    52
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    53
 * The queue consists of:
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    54
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    55
 *   - a ring array of n + 1 `Message` elements
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    56
 *   - indexes H and T denoting the head and the tail elements of the queue
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    57
 *     respectively
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    58
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    59
 * Each `Message` element contains a boolean flag. This flag is an auxiliary
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    60
 * communication between the producers and the consumer. The flag shows
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    61
 * whether or not the element is ready to be consumed (peeked at, removed). The
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    62
 * flag is required since updating an element involves many fields and thus is
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    63
 * not an atomic action. An addition to the queue happens in two steps:
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    64
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    65
 * # Step 1
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    66
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    67
 * Producers race with each other to secure an index for the element they add.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    68
 * T is atomically advanced [1] only if the advanced value doesn't equal to H
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    69
 * (a producer doesn't bump into the head of the queue).
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    70
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    71
 * # Step 2
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    72
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    73
 * Once T is advanced in the previous step, the producer updates the message
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    74
 * fields of the element at the previous value of T and then sets the flag of
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    75
 * this element.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    76
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    77
 * A removal happens in a single step. The consumer gets the element at index H.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    78
 * If the flag of this element is set, the consumer clears the fields of the
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    79
 * element, clears the flag and finally advances H.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    80
 *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    81
 * ----------------------------------------------------------------------------
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    82
 * [1] To advance the index is to change it from i to (i + 1) % (n + 1).
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    83
 */
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    84
public class MessageQueue {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    85
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    86
    private final Message[] elements;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    87
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    88
    private final AtomicInteger tail = new AtomicInteger();
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    89
    private volatile int head;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    90
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    91
    public MessageQueue(int capacity) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    92
        if (capacity < 1) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    93
            throw new IllegalArgumentException();
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    94
        }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    95
        int s = pow2Size(capacity + 1);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    96
        assert s % 2 == 0 : s;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    97
        Message[] array = new Message[s];
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    98
        for (int i = 0; i < array.length; i++) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
    99
            array[i] = new Message();
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   100
        }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   101
        elements = array;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   102
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   103
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   104
    /* Exposed for testing purposes */
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   105
    protected static int effectiveCapacityOf(int n) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   106
        return pow2Size(n + 1) - 1;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   107
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   108
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   109
    public <T> void addText(CharBuffer message,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   110
                            boolean isLast,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   111
                            T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   112
                            BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   113
                            CompletableFuture<T> future)
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   114
            throws IOException
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   115
    {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   116
        add(MessageQueue.Type.TEXT, null, null, message, isLast, -1, attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   117
            action, future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   118
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   119
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   120
    private <T> void add(Type type,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   121
                         Supplier<? extends ByteBuffer> binarySupplier,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   122
                         ByteBuffer binary,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   123
                         CharBuffer text,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   124
                         boolean isLast,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   125
                         int statusCode,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   126
                         T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   127
                         BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   128
                         CompletableFuture<? super T> future)
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   129
            throws IOException
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   130
    {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   131
        // Pong "subtype" is determined by whichever field (data carrier)
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   132
        // is not null. Both fields cannot be null or non-null simultaneously.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   133
        assert type != Type.PONG || (binary == null ^ binarySupplier == null);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   134
        int h, currentTail, newTail;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   135
        do {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   136
            h = head;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   137
            currentTail = tail.get();
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   138
            newTail = (currentTail + 1) & (elements.length - 1);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   139
            if (newTail == h) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   140
                throw new IOException("Queue full");
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   141
            }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   142
        } while (!tail.compareAndSet(currentTail, newTail));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   143
        Message t = elements[currentTail];
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   144
        if (t.ready) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   145
            throw new InternalError();
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   146
        }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   147
        t.type = type;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   148
        t.binarySupplier = binarySupplier;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   149
        t.binary = binary;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   150
        t.text = text;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   151
        t.isLast = isLast;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   152
        t.statusCode = statusCode;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   153
        t.attachment = attachment;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   154
        t.action = action;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   155
        t.future = future;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   156
        t.ready = true;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   157
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   158
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   159
    public <T> void addBinary(ByteBuffer message,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   160
                              boolean isLast,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   161
                              T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   162
                              BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   163
                              CompletableFuture<? super T> future)
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   164
            throws IOException
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   165
    {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   166
        add(MessageQueue.Type.BINARY, null, message, null, isLast, -1, attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   167
            action, future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   168
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   169
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   170
    public <T> void addPing(ByteBuffer message,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   171
                            T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   172
                            BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   173
                            CompletableFuture<? super T> future)
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   174
            throws IOException
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   175
    {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   176
        add(MessageQueue.Type.PING, null, message, null, false, -1, attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   177
            action, future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   178
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   179
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   180
    public <T> void addPong(ByteBuffer message,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   181
                            T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   182
                            BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   183
                            CompletableFuture<? super T> future)
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   184
            throws IOException
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   185
    {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   186
        add(MessageQueue.Type.PONG, null, message, null, false, -1, attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   187
            action, future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   188
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   189
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   190
    public <T> void addPong(Supplier<? extends ByteBuffer> message,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   191
                            T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   192
                            BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   193
                            CompletableFuture<? super T> future)
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   194
            throws IOException
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   195
    {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   196
        add(MessageQueue.Type.PONG, message, null, null, false, -1, attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   197
            action, future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   198
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   199
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   200
    public <T> void addClose(int statusCode,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   201
                             CharBuffer reason,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   202
                             T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   203
                             BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   204
                             CompletableFuture<? super T> future)
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   205
            throws IOException
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   206
    {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   207
        add(MessageQueue.Type.CLOSE, null, null, reason, false, statusCode,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   208
            attachment, action, future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   209
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   210
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   211
    @SuppressWarnings("unchecked")
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   212
    public <R, E extends Throwable> R peek(QueueCallback<R, E> callback)
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   213
            throws E
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   214
    {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   215
        Message h = elements[head];
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   216
        if (!h.ready) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   217
            return callback.onEmpty();
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   218
        }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   219
        Type type = h.type;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   220
        switch (type) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   221
            case TEXT:
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   222
                try {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   223
                    return (R) callback.onText(h.text, h.isLast, h.attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   224
                                               h.action, h.future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   225
                } catch (Throwable t) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   226
                    // Something unpleasant is going on here with the compiler.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   227
                    // If this seemingly useless catch is omitted, the compiler
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   228
                    // reports an error:
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   229
                    //
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   230
                    //   java: unreported exception java.lang.Throwable;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   231
                    //   must be caught or declared to be thrown
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   232
                    //
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   233
                    // My guess is there is a problem with both the type
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   234
                    // inference for the method AND @SuppressWarnings("unchecked")
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   235
                    // being working at the same time.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   236
                    throw (E) t;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   237
                }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   238
            case BINARY:
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   239
                try {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   240
                    return (R) callback.onBinary(h.binary, h.isLast, h.attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   241
                                                 h.action, h.future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   242
                } catch (Throwable t) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   243
                    throw (E) t;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   244
                }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   245
            case PING:
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   246
                try {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   247
                    return (R) callback.onPing(h.binary, h.attachment, h.action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   248
                                               h.future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   249
                } catch (Throwable t) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   250
                    throw (E) t;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   251
                }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   252
            case PONG:
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   253
                try {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   254
                    if (h.binarySupplier != null) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   255
                        return (R) callback.onPong(h.binarySupplier, h.attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   256
                                                   h.action, h.future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   257
                    } else {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   258
                        return (R) callback.onPong(h.binary, h.attachment, h.action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   259
                                                   h.future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   260
                    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   261
                } catch (Throwable t) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   262
                    throw (E) t;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   263
                }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   264
            case CLOSE:
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   265
                try {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   266
                    return (R) callback.onClose(h.statusCode, h.text, h.attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   267
                                                h.action, h.future);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   268
                } catch (Throwable t) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   269
                    throw (E) t;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   270
                }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   271
            default:
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   272
                throw new InternalError(String.valueOf(type));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   273
        }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   274
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   275
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   276
    public boolean isEmpty() {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   277
        return !elements[head].ready;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   278
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   279
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   280
    public void remove() {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   281
        int currentHead = head;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   282
        Message h = elements[currentHead];
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   283
        if (!h.ready) {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   284
            throw new InternalError("Queue empty");
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   285
        }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   286
        h.type = null;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   287
        h.binarySupplier = null;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   288
        h.binary = null;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   289
        h.text = null;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   290
        h.attachment = null;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   291
        h.action = null;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   292
        h.future = null;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   293
        h.ready = false;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   294
        head = (currentHead + 1) & (elements.length - 1);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   295
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   296
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   297
    private enum Type {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   298
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   299
        TEXT,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   300
        BINARY,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   301
        PING,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   302
        PONG,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   303
        CLOSE
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   304
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   305
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   306
    /*
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   307
     * A callback for consuming a queue element's fields. Can return a result of
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   308
     * type T or throw an exception of type E. This design allows to avoid
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   309
     * "returning" results or "throwing" errors by updating some objects from
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   310
     * the outside of the methods.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   311
     */
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   312
    public interface QueueCallback<R, E extends Throwable> {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   313
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   314
        <T> R onText(CharBuffer message,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   315
                     boolean isLast,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   316
                     T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   317
                     BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   318
                     CompletableFuture<? super T> future) throws E;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   319
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   320
        <T> R onBinary(ByteBuffer message,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   321
                       boolean isLast,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   322
                       T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   323
                       BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   324
                       CompletableFuture<? super T> future) throws E;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   325
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   326
        <T> R onPing(ByteBuffer message,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   327
                     T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   328
                     BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   329
                     CompletableFuture<? super T> future) throws E;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   330
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   331
        <T> R onPong(ByteBuffer message,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   332
                     T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   333
                     BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   334
                     CompletableFuture<? super T> future) throws E;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   335
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   336
        <T> R onPong(Supplier<? extends ByteBuffer> message,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   337
                     T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   338
                     BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   339
                     CompletableFuture<? super T> future) throws E;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   340
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   341
        <T> R onClose(int statusCode,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   342
                      CharBuffer reason,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   343
                      T attachment,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   344
                      BiConsumer<? super T, ? super Throwable> action,
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   345
                      CompletableFuture<? super T> future) throws E;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   346
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   347
        /* The queue is empty*/
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   348
        R onEmpty() throws E;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   349
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   350
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   351
    /*
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   352
     * A union of components of all WebSocket message types; also a node in a
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   353
     * queue.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   354
     *
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   355
     * A `Message` never leaves the context of the queue, thus the reference to
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   356
     * it cannot be retained by anyone other than the queue.
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   357
     */
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   358
    private static class Message {
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   359
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   360
        private volatile boolean ready;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   361
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   362
        // -- The source message fields --
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   363
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   364
        private Type type;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   365
        private Supplier<? extends ByteBuffer> binarySupplier;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   366
        private ByteBuffer binary;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   367
        private CharBuffer text;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   368
        private boolean isLast;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   369
        private int statusCode;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   370
        private Object attachment;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   371
        @SuppressWarnings("rawtypes")
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   372
        private BiConsumer action;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   373
        @SuppressWarnings("rawtypes")
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   374
        private CompletableFuture future;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   375
    }
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents:
diff changeset
   376
}