Skip to content

Commit c3e0902

Browse files
committed
Make the inbound queue in DefaultHttp2Stream use the Buffer type consistently
1 parent 493fbef commit c3e0902

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

vertx-core/src/main/java/io/vertx/core/http/impl/http2/DefaultHttp2Stream.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
*/
4141
abstract class DefaultHttp2Stream<S extends DefaultHttp2Stream<S>> implements HttpStream, Http2Stream {
4242

43-
private static final HttpHeaders EMPTY = new HttpHeaders(EmptyHttp2Headers.INSTANCE);
43+
private static final Buffer EMPTY = BufferInternal.buffer(Unpooled.EMPTY_BUFFER);
4444

4545
private final OutboundMessageQueue<MessageWrite> outboundQueue;
46-
private final InboundMessageQueue<Object> inboundQueue;
46+
private final InboundMessageQueue<Buffer> inboundQueue;
4747
private final Http2Connection connection;
4848
protected final VertxInternal vertx;
4949
protected final ContextInternal context;
@@ -56,6 +56,9 @@ abstract class DefaultHttp2Stream<S extends DefaultHttp2Stream<S>> implements Ht
5656
private boolean trailersSent;
5757
private boolean writable;
5858

59+
// Written by event-loop - read by context with happens-before relationship
60+
private MultiMap trailers;
61+
5962
// Client context
6063
private StreamPriority priority;
6164
private long bytesRead;
@@ -85,14 +88,13 @@ abstract class DefaultHttp2Stream<S extends DefaultHttp2Stream<S>> implements Ht
8588
this.id = id_;
8689
this.inboundQueue = new InboundMessageQueue<>(connection.context().eventLoop(), context.executor()) {
8790
@Override
88-
protected void handleMessage(Object item) {
89-
if (item instanceof MultiMap) {
90-
handleTrailers((MultiMap) item);
91+
protected void handleMessage(Buffer item) {
92+
if (item == EMPTY) {
93+
handleTrailers(trailers);
9194
} else {
92-
Buffer data = (Buffer) item;
93-
int len = data.length();
95+
int len = item.length();
9496
connection.context().execute(len, v -> connection.consumeCredits(DefaultHttp2Stream.this.id, v));
95-
handleData(data);
97+
handleData(item);
9698
}
9799
}
98100
};
@@ -241,20 +243,21 @@ public void onWritabilityChanged() {
241243
}
242244

243245
public final void onTrailers() {
244-
onTrailers(EMPTY);
246+
onTrailers(null);
245247
}
246248

247-
public final void onTrailers(HttpHeaders trailers) {
249+
public final void onTrailers(HttpHeaders t) {
248250
if (trailersReceived) {
249251
throw new IllegalStateException();
250252
}
251253
trailersReceived = true;
254+
trailers = t;
252255
StreamObserver observer = observer();
253256
if (observer != null) {
254257
observer.observeInboundTrailers(bytesRead);
255258
}
256259
connection.flushBytesRead();
257-
inboundQueue.write(trailers);
260+
inboundQueue.write(EMPTY);
258261
}
259262

260263
public final long id() {

0 commit comments

Comments
 (0)