Renaming "Observer" to "Listener" for consistency in HTTP/2

Motivation:

We currently have a mix of "Observer" and "Listener" for interface
names. We should make them all "Listener" to be consistent.

Modifications:

Renamed Http2DataObserver->Http2DataListener and
Http2FrameObserver->Http2FrameListener.

Result:

Listener interface names are consistent.
This commit is contained in:
nmittler 2014-08-26 10:31:36 -07:00
parent 63d5925d6e
commit 102e781715
18 changed files with 292 additions and 292 deletions

View File

@ -45,7 +45,7 @@ import java.util.List;
* as well as management of connection state and flow control for both inbound and outbound data
* frames.
* <p>
* Subclasses need to implement the methods defined by the {@link Http2FrameObserver} interface for
* Subclasses need to implement the methods defined by the {@link Http2FrameListener} interface for
* receiving inbound frames. Outbound frames are sent via one of the {@code writeXXX} methods.
* <p>
* It should be noted that the connection preface is sent upon either activation or addition of this
@ -53,9 +53,9 @@ import java.util.List;
* must call this class to write the preface to the remote endpoint.
*/
public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecoder implements
Http2FrameObserver {
Http2FrameListener {
private final Http2FrameObserver internalFrameObserver = new FrameReadObserver();
private final Http2FrameListener internalFrameListener = new FrameReadListener();
private final Http2FrameReader frameReader;
private final Http2FrameWriter frameWriter;
private final Http2Connection connection;
@ -539,7 +539,7 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
return;
}
frameReader.readFrame(ctx, in, internalFrameObserver);
frameReader.readFrame(ctx, in, internalFrameListener);
} catch (Http2Exception e) {
onHttp2Exception(ctx, e);
} catch (Throwable e) {
@ -812,7 +812,7 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
/**
* Handles all inbound frames from the network.
*/
private final class FrameReadObserver implements Http2FrameObserver {
private final class FrameReadListener implements Http2FrameListener {
@Override
public void onDataRead(final ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding,

View File

@ -153,7 +153,7 @@ public class DefaultHttp2Connection implements Http2Connection {
}
private void removeStream(DefaultStream stream) {
// Notify the observers of the event first.
// Notify the listeners of the event first.
for (Listener listener : listeners) {
listener.streamRemoved(stream);
}
@ -724,7 +724,7 @@ public class DefaultHttp2Connection implements Http2Connection {
List<ParentChangedEvent> events = new ArrayList<ParentChangedEvent>(1);
connectionStream.takeChild(stream, false, events);
// Notify the observers of the event.
// Notify the listeners of the event.
for (Listener listener : listeners) {
listener.streamAdded(stream);
}

View File

@ -108,7 +108,7 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
}
@Override
public void readFrame(ChannelHandlerContext ctx, ByteBuf input, Http2FrameObserver observer)
public void readFrame(ChannelHandlerContext ctx, ByteBuf input, Http2FrameListener listener)
throws Http2Exception {
try {
while (input.isReadable()) {
@ -126,7 +126,7 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
// available, causing us to exit the loop. Instead, we just want to perform
// the first pass at payload processing now.
case FRAME_PAYLOAD:
processPayloadState(ctx, input, observer);
processPayloadState(ctx, input, listener);
if (state == State.FRAME_PAYLOAD) {
// Wait until the entire payload has arrived.
return;
@ -206,7 +206,7 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
state = State.FRAME_PAYLOAD;
}
private void processPayloadState(ChannelHandlerContext ctx, ByteBuf in, Http2FrameObserver observer)
private void processPayloadState(ChannelHandlerContext ctx, ByteBuf in, Http2FrameListener listener)
throws Http2Exception {
if (in.readableBytes() < payloadLength) {
// Wait until the entire payload has been read.
@ -216,40 +216,40 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
// Get a view of the buffer for the size of the payload.
ByteBuf payload = in.readSlice(payloadLength);
// Read the payload and fire the frame event to the observer.
// Read the payload and fire the frame event to the listener.
switch (frameType) {
case DATA:
readDataFrame(ctx, payload, observer);
readDataFrame(ctx, payload, listener);
break;
case HEADERS:
readHeadersFrame(ctx, payload, observer);
readHeadersFrame(ctx, payload, listener);
break;
case PRIORITY:
readPriorityFrame(ctx, payload, observer);
readPriorityFrame(ctx, payload, listener);
break;
case RST_STREAM:
readRstStreamFrame(ctx, payload, observer);
readRstStreamFrame(ctx, payload, listener);
break;
case SETTINGS:
readSettingsFrame(ctx, payload, observer);
readSettingsFrame(ctx, payload, listener);
break;
case PUSH_PROMISE:
readPushPromiseFrame(ctx, payload, observer);
readPushPromiseFrame(ctx, payload, listener);
break;
case PING:
readPingFrame(ctx, payload, observer);
readPingFrame(ctx, payload, listener);
break;
case GO_AWAY:
readGoAwayFrame(ctx, payload, observer);
readGoAwayFrame(ctx, payload, listener);
break;
case WINDOW_UPDATE:
readWindowUpdateFrame(ctx, payload, observer);
readWindowUpdateFrame(ctx, payload, listener);
break;
case CONTINUATION:
readContinuationFrame(payload, observer);
readContinuationFrame(payload, listener);
break;
default:
readUnknownFrame(ctx, payload, observer);
readUnknownFrame(ctx, payload, listener);
break;
}
@ -368,7 +368,7 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
}
private void readDataFrame(ChannelHandlerContext ctx, ByteBuf payload,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
short padding = readPadding(payload);
// Determine how much data there is to read by removing the trailing
@ -379,12 +379,12 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
}
ByteBuf data = payload.readSlice(dataLength);
observer.onDataRead(ctx, streamId, data, padding, flags.endOfStream());
listener.onDataRead(ctx, streamId, data, padding, flags.endOfStream());
payload.skipBytes(payload.readableBytes());
}
private void readHeadersFrame(final ChannelHandlerContext ctx, ByteBuf payload,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
final int headersStreamId = streamId;
final Http2Flags headersFlags = flags;
final int padding = readPadding(payload);
@ -398,7 +398,7 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
final short weight = (short) (payload.readUnsignedByte() + 1);
final ByteBuf fragment = payload.readSlice(payload.readableBytes() - padding);
// Create a handler that invokes the observer when the header block is complete.
// Create a handler that invokes the listener when the header block is complete.
headersContinuation = new HeadersContinuation() {
@Override
public int getStreamId() {
@ -407,24 +407,24 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
@Override
public void processFragment(boolean endOfHeaders, ByteBuf fragment,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
builder().addFragment(fragment, ctx.alloc(), endOfHeaders);
if (endOfHeaders) {
Http2Headers headers = builder().buildHeaders();
observer.onHeadersRead(ctx, headersStreamId, headers, streamDependency,
listener.onHeadersRead(ctx, headersStreamId, headers, streamDependency,
weight, exclusive, padding, headersFlags.endOfStream());
close();
}
}
};
// Process the initial fragment, invoking the observer's callback if end of headers.
headersContinuation.processFragment(flags.endOfHeaders(), fragment, observer);
// Process the initial fragment, invoking the listener's callback if end of headers.
headersContinuation.processFragment(flags.endOfHeaders(), fragment, listener);
return;
}
// The priority fields are not present in the frame. Prepare a continuation that invokes
// the observer callback without priority information.
// the listener callback without priority information.
headersContinuation = new HeadersContinuation() {
@Override
public int getStreamId() {
@ -433,41 +433,41 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
@Override
public void processFragment(boolean endOfHeaders, ByteBuf fragment,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
builder().addFragment(fragment, ctx.alloc(), endOfHeaders);
if (endOfHeaders) {
Http2Headers headers = builder().buildHeaders();
observer.onHeadersRead(ctx, headersStreamId, headers, padding,
listener.onHeadersRead(ctx, headersStreamId, headers, padding,
headersFlags.endOfStream());
close();
}
}
};
// Process the initial fragment, invoking the observer's callback if end of headers.
// Process the initial fragment, invoking the listener's callback if end of headers.
final ByteBuf fragment = payload.readSlice(payload.readableBytes() - padding);
headersContinuation.processFragment(flags.endOfHeaders(), fragment, observer);
headersContinuation.processFragment(flags.endOfHeaders(), fragment, listener);
}
private void readPriorityFrame(ChannelHandlerContext ctx, ByteBuf payload,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
long word1 = payload.readUnsignedInt();
boolean exclusive = (word1 & 0x80000000L) > 0;
int streamDependency = (int) (word1 & 0x7FFFFFFFL);
short weight = (short) (payload.readUnsignedByte() + 1);
observer.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
listener.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
}
private void readRstStreamFrame(ChannelHandlerContext ctx, ByteBuf payload,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
long errorCode = payload.readUnsignedInt();
observer.onRstStreamRead(ctx, streamId, errorCode);
listener.onRstStreamRead(ctx, streamId, errorCode);
}
private void readSettingsFrame(ChannelHandlerContext ctx, ByteBuf payload,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
if (flags.ack()) {
observer.onSettingsAckRead(ctx);
listener.onSettingsAckRead(ctx);
} else {
int numSettings = payloadLength / SETTING_ENTRY_LENGTH;
Http2Settings settings = new Http2Settings();
@ -484,19 +484,19 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
}
}
}
observer.onSettingsRead(ctx, settings);
// Provide an interface for non-observers to capture settings
listener.onSettingsRead(ctx, settings);
// Provide an interface for non-listeners to capture settings
ctx.fireChannelRead(settings);
}
}
private void readPushPromiseFrame(final ChannelHandlerContext ctx, ByteBuf payload,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
final int pushPromiseStreamId = streamId;
final int padding = readPadding(payload);
final int promisedStreamId = readUnsignedInt(payload);
// Create a handler that invokes the observer when the header block is complete.
// Create a handler that invokes the listener when the header block is complete.
headersContinuation = new HeadersContinuation() {
@Override
public int getStreamId() {
@ -505,58 +505,58 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
@Override
public void processFragment(boolean endOfHeaders, ByteBuf fragment,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
builder().addFragment(fragment, ctx.alloc(), endOfHeaders);
if (endOfHeaders) {
Http2Headers headers = builder().buildHeaders();
observer.onPushPromiseRead(ctx, pushPromiseStreamId, promisedStreamId, headers,
listener.onPushPromiseRead(ctx, pushPromiseStreamId, promisedStreamId, headers,
padding);
close();
}
}
};
// Process the initial fragment, invoking the observer's callback if end of headers.
// Process the initial fragment, invoking the listener's callback if end of headers.
final ByteBuf fragment = payload.readSlice(payload.readableBytes() - padding);
headersContinuation.processFragment(flags.endOfHeaders(), fragment, observer);
headersContinuation.processFragment(flags.endOfHeaders(), fragment, listener);
}
private void readPingFrame(ChannelHandlerContext ctx, ByteBuf payload,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
ByteBuf data = payload.readSlice(payload.readableBytes());
if (flags.ack()) {
observer.onPingAckRead(ctx, data);
listener.onPingAckRead(ctx, data);
} else {
observer.onPingRead(ctx, data);
listener.onPingRead(ctx, data);
}
}
private static void readGoAwayFrame(ChannelHandlerContext ctx, ByteBuf payload,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
int lastStreamId = readUnsignedInt(payload);
long errorCode = payload.readUnsignedInt();
ByteBuf debugData = payload.readSlice(payload.readableBytes());
observer.onGoAwayRead(ctx, lastStreamId, errorCode, debugData);
listener.onGoAwayRead(ctx, lastStreamId, errorCode, debugData);
}
private void readWindowUpdateFrame(ChannelHandlerContext ctx, ByteBuf payload,
Http2FrameObserver observer) throws Http2Exception {
Http2FrameListener listener) throws Http2Exception {
int windowSizeIncrement = readUnsignedInt(payload);
observer.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
listener.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
}
private void readContinuationFrame(ByteBuf payload, Http2FrameObserver observer)
private void readContinuationFrame(ByteBuf payload, Http2FrameListener listener)
throws Http2Exception {
// Process the initial fragment, invoking the observer's callback if end of headers.
// Process the initial fragment, invoking the listener's callback if end of headers.
final ByteBuf continuationFragment = payload.readSlice(payload.readableBytes());
headersContinuation.processFragment(flags.endOfHeaders(), continuationFragment,
observer);
listener);
}
private void readUnknownFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameObserver observer)
private void readUnknownFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener)
throws Http2Exception {
payload = payload.readSlice(payload.readableBytes());
observer.onUnknownFrame(ctx, frameType, streamId, flags, payload);
listener.onUnknownFrame(ctx, frameType, streamId, flags, payload);
}
/**
@ -572,7 +572,7 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
/**
* Base class for processing of HEADERS and PUSH_PROMISE header blocks that potentially span
* multiple frames. The implementation of this interface will perform the final callback to the
* {@link Http2FrameObserver} once the end of headers is reached.
* {@link Http2FrameListener} once the end of headers is reached.
*/
private abstract class HeadersContinuation {
private final HeadersBuilder builder = new HeadersBuilder();
@ -587,10 +587,10 @@ public class DefaultHttp2FrameReader implements Http2FrameReader {
*
* @param endOfHeaders whether the fragment is the last in the header block.
* @param fragment the fragment of the header block to be added.
* @param observer the observer to be notified if the header block is completed.
* @param listener the listener to be notified if the header block is completed.
*/
abstract void processFragment(boolean endOfHeaders, ByteBuf fragment,
Http2FrameObserver observer) throws Http2Exception;
Http2FrameListener listener) throws Http2Exception;
final HeadersBuilder builder() {
return builder;

View File

@ -25,30 +25,30 @@ import io.netty.channel.ChannelPromise;
* models, rather than having to subclass it directly.
* <p>
* Exposes all {@code writeXXX} methods as public and delegates all frame read events to a provided
* {@link Http2FrameObserver}.
* {@link Http2FrameListener}.
* <p>
* The {@link #channelActive} and {@link #handlerAdded} should called when appropriate to ensure
* that the initial SETTINGS frame is sent to the remote endpoint.
*/
public class DelegatingHttp2ConnectionHandler extends AbstractHttp2ConnectionHandler {
private final Http2FrameObserver observer;
private final Http2FrameListener listener;
public DelegatingHttp2ConnectionHandler(boolean server, Http2FrameObserver observer) {
public DelegatingHttp2ConnectionHandler(boolean server, Http2FrameListener listener) {
super(server);
this.observer = observer;
this.listener = listener;
}
public DelegatingHttp2ConnectionHandler(Http2Connection connection,
Http2FrameReader frameReader, Http2FrameWriter frameWriter,
Http2InboundFlowController inboundFlow, Http2OutboundFlowController outboundFlow,
Http2FrameObserver observer) {
Http2FrameListener listener) {
super(connection, frameReader, frameWriter, inboundFlow, outboundFlow);
this.observer = observer;
this.listener = listener;
}
public DelegatingHttp2ConnectionHandler(Http2Connection connection, Http2FrameObserver observer) {
public DelegatingHttp2ConnectionHandler(Http2Connection connection, Http2FrameListener listener) {
super(connection);
this.observer = observer;
this.listener = listener;
}
@Override
@ -103,70 +103,70 @@ public class DelegatingHttp2ConnectionHandler extends AbstractHttp2ConnectionHan
@Override
public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding,
boolean endOfStream) throws Http2Exception {
observer.onDataRead(ctx, streamId, data, padding, endOfStream);
listener.onDataRead(ctx, streamId, data, padding, endOfStream);
}
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
int streamDependency, short weight, boolean exclusive, int padding, boolean endStream)
throws Http2Exception {
observer.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive,
listener.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive,
padding, endStream);
}
@Override
public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency,
short weight, boolean exclusive) throws Http2Exception {
observer.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
listener.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
}
@Override
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode)
throws Http2Exception {
observer.onRstStreamRead(ctx, streamId, errorCode);
listener.onRstStreamRead(ctx, streamId, errorCode);
}
@Override
public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception {
observer.onSettingsAckRead(ctx);
listener.onSettingsAckRead(ctx);
}
@Override
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception {
observer.onSettingsRead(ctx, settings);
listener.onSettingsRead(ctx, settings);
}
@Override
public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
observer.onPingRead(ctx, data);
listener.onPingRead(ctx, data);
}
@Override
public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
observer.onPingAckRead(ctx, data);
listener.onPingAckRead(ctx, data);
}
@Override
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId,
Http2Headers headers, int padding) throws Http2Exception {
observer.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding);
listener.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding);
}
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData)
throws Http2Exception {
observer.onGoAwayRead(ctx, lastStreamId, errorCode, debugData);
listener.onGoAwayRead(ctx, lastStreamId, errorCode, debugData);
}
@Override
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement)
throws Http2Exception {
observer.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
listener.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
}
@Override
public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags,
ByteBuf payload) {
observer.onUnknownFrame(ctx, frameType, streamId, flags, payload);
listener.onUnknownFrame(ctx, frameType, streamId, flags, payload);
}
}

View File

@ -31,18 +31,18 @@ import java.util.Map;
*/
public class DelegatingHttp2HttpConnectionHandler extends DelegatingHttp2ConnectionHandler {
public DelegatingHttp2HttpConnectionHandler(boolean server, Http2FrameObserver observer) {
super(server, observer);
public DelegatingHttp2HttpConnectionHandler(boolean server, Http2FrameListener listener) {
super(server, listener);
}
public DelegatingHttp2HttpConnectionHandler(Http2Connection connection, Http2FrameReader frameReader,
Http2FrameWriter frameWriter, Http2InboundFlowController inboundFlow,
Http2OutboundFlowController outboundFlow, Http2FrameObserver observer) {
super(connection, frameReader, frameWriter, inboundFlow, outboundFlow, observer);
Http2OutboundFlowController outboundFlow, Http2FrameListener listener) {
super(connection, frameReader, frameWriter, inboundFlow, outboundFlow, listener);
}
public DelegatingHttp2HttpConnectionHandler(Http2Connection connection, Http2FrameObserver observer) {
super(connection, observer);
public DelegatingHttp2HttpConnectionHandler(Http2Connection connection, Http2FrameListener listener) {
super(connection, listener);
}
/**

View File

@ -18,16 +18,16 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
/**
* An observer of HTTP/2 {@code DATA} frames.
* An listener of HTTP/2 {@code DATA} frames.
*/
public interface Http2DataObserver {
public interface Http2DataListener {
/**
* Handles an inbound {@code DATA} frame.
*
* @param ctx the context from the handler where the frame was read.
* @param streamId the subject stream for the frame.
* @param data payload buffer for the frame. If this buffer needs to be retained by the observer
* @param data payload buffer for the frame. If this buffer needs to be retained by the listener
* they must make a copy.
* @param padding the number of padding bytes found at the end of the frame.
* @param endOfStream Indicates whether this is the last frame to be sent from the remote

View File

@ -18,10 +18,10 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
/**
* This class brings {@link Http2Connection.Listener} and {@link Http2FrameObserver} together to provide
* This class brings {@link Http2Connection.Listener} and {@link Http2FrameListener} together to provide
* NOOP implementation so inheriting classes can selectively choose which methods to override.
*/
public class Http2EventAdapter implements Http2Connection.Listener, Http2FrameObserver {
public class Http2EventAdapter implements Http2Connection.Listener, Http2FrameListener {
@Override
public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream)
throws Http2Exception {

View File

@ -18,9 +18,9 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
/**
* Convenience class that provides no-op implementations for all methods of {@link Http2FrameObserver}.
* Convenience class that provides no-op implementations for all methods of {@link Http2FrameListener}.
*/
public class Http2FrameAdapter implements Http2FrameObserver {
public class Http2FrameAdapter implements Http2FrameListener {
@Override
public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding,

View File

@ -19,9 +19,9 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
/**
* An observer of HTTP/2 frames.
* An listener of HTTP/2 frames.
*/
public interface Http2FrameObserver extends Http2DataObserver {
public interface Http2FrameListener extends Http2DataListener {
/**
* Handles an inbound HEADERS frame.
@ -117,7 +117,7 @@ public interface Http2FrameObserver extends Http2DataObserver {
* Handles an inbound PING frame.
*
* @param ctx the context from the handler where the frame was read.
* @param data the payload of the frame. If this buffer needs to be retained by the observer
* @param data the payload of the frame. If this buffer needs to be retained by the listener
* they must make a copy.
*/
void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception;
@ -126,7 +126,7 @@ public interface Http2FrameObserver extends Http2DataObserver {
* Handles an inbound PING acknowledgment.
*
* @param ctx the context from the handler where the frame was read.
* @param data the payload of the frame. If this buffer needs to be retained by the observer
* @param data the payload of the frame. If this buffer needs to be retained by the listener
* they must make a copy.
*/
void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception;
@ -162,7 +162,7 @@ public interface Http2FrameObserver extends Http2DataObserver {
* @param lastStreamId the last known stream of the remote endpoint.
* @param errorCode the error code, if abnormal closure.
* @param debugData application-defined debug data. If this buffer needs to be retained by the
* observer they must make a copy.
* listener they must make a copy.
*/
void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData)
throws Http2Exception;

View File

@ -22,15 +22,15 @@ import java.io.Closeable;
/**
* Reads HTTP/2 frames from an input {@link ByteBuf} and notifies the specified
* {@link Http2FrameObserver} when frames are complete.
* {@link Http2FrameListener} when frames are complete.
*/
public interface Http2FrameReader extends Closeable {
/**
* Attempts to read the next frame from the input buffer. If enough data is available to fully
* read the frame, notifies the observer of the read frame.
* read the frame, notifies the listener of the read frame.
*/
void readFrame(ChannelHandlerContext ctx, ByteBuf input, Http2FrameObserver observer)
void readFrame(ChannelHandlerContext ctx, ByteBuf input, Http2FrameListener listener)
throws Http2Exception;
/**

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec.http2;
/**
* Controls the inbound flow of data frames from the remote endpoint.
*/
public interface Http2InboundFlowController extends Http2DataObserver {
public interface Http2InboundFlowController extends Http2DataListener {
/**
* Sets the initial inbound flow control window size and updates all stream window sizes by the

View File

@ -21,7 +21,7 @@ import io.netty.channel.ChannelHandlerContext;
/**
* Decorator around a {@link Http2FrameReader} that logs all inbound frames before calling
* back the observer.
* back the listener.
*/
public class Http2InboundFrameLogger implements Http2FrameReader {
@ -40,16 +40,16 @@ public class Http2InboundFrameLogger implements Http2FrameReader {
}
@Override
public void readFrame(ChannelHandlerContext ctx, ByteBuf input, final Http2FrameObserver observer)
public void readFrame(ChannelHandlerContext ctx, ByteBuf input, final Http2FrameListener listener)
throws Http2Exception {
reader.readFrame(ctx, input, new Http2FrameObserver() {
reader.readFrame(ctx, input, new Http2FrameListener() {
@Override
public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data,
int padding, boolean endOfStream)
throws Http2Exception {
logger.logData(INBOUND, streamId, data, padding, endOfStream);
observer.onDataRead(ctx, streamId, data, padding, endOfStream);
listener.onDataRead(ctx, streamId, data, padding, endOfStream);
}
@Override
@ -57,7 +57,7 @@ public class Http2InboundFrameLogger implements Http2FrameReader {
Http2Headers headers, int padding, boolean endStream)
throws Http2Exception {
logger.logHeaders(INBOUND, streamId, headers, padding, endStream);
observer.onHeadersRead(ctx, streamId, headers, padding, endStream);
listener.onHeadersRead(ctx, streamId, headers, padding, endStream);
}
@Override
@ -66,7 +66,7 @@ public class Http2InboundFrameLogger implements Http2FrameReader {
int padding, boolean endStream) throws Http2Exception {
logger.logHeaders(INBOUND, streamId, headers, streamDependency, weight, exclusive,
padding, endStream);
observer.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive,
listener.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive,
padding, endStream);
}
@ -74,67 +74,67 @@ public class Http2InboundFrameLogger implements Http2FrameReader {
public void onPriorityRead(ChannelHandlerContext ctx, int streamId,
int streamDependency, short weight, boolean exclusive) throws Http2Exception {
logger.logPriority(INBOUND, streamId, streamDependency, weight, exclusive);
observer.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
listener.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
}
@Override
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode)
throws Http2Exception {
logger.logRstStream(INBOUND, streamId, errorCode);
observer.onRstStreamRead(ctx, streamId, errorCode);
listener.onRstStreamRead(ctx, streamId, errorCode);
}
@Override
public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception {
logger.logSettingsAck(INBOUND);
observer.onSettingsAckRead(ctx);
listener.onSettingsAckRead(ctx);
}
@Override
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings)
throws Http2Exception {
logger.logSettings(INBOUND, settings);
observer.onSettingsRead(ctx, settings);
listener.onSettingsRead(ctx, settings);
}
@Override
public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
logger.logPing(INBOUND, data);
observer.onPingRead(ctx, data);
listener.onPingRead(ctx, data);
}
@Override
public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
logger.logPingAck(INBOUND, data);
observer.onPingAckRead(ctx, data);
listener.onPingAckRead(ctx, data);
}
@Override
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId,
int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
logger.logPushPromise(INBOUND, streamId, promisedStreamId, headers, padding);
observer.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding);
listener.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding);
}
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode,
ByteBuf debugData) throws Http2Exception {
logger.logGoAway(INBOUND, lastStreamId, errorCode, debugData);
observer.onGoAwayRead(ctx, lastStreamId, errorCode, debugData);
listener.onGoAwayRead(ctx, lastStreamId, errorCode, debugData);
}
@Override
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement)
throws Http2Exception {
logger.logWindowsUpdate(INBOUND, streamId, windowSizeIncrement);
observer.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
listener.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
}
@Override
public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int streamId,
Http2Flags flags, ByteBuf payload) {
logger.logUnknownFrame(INBOUND, frameType, streamId, flags, payload);
observer.onUnknownFrame(ctx, frameType, streamId, flags, payload);
listener.onUnknownFrame(ctx, frameType, streamId, flags, payload);
}
});
}

View File

@ -47,7 +47,7 @@ public class DefaultHttp2FrameIOTest {
private ChannelHandlerContext ctx;
@Mock
private Http2FrameObserver observer;
private Http2FrameListener listener;
@Mock
private ChannelPromise promise;
@ -70,8 +70,8 @@ public class DefaultHttp2FrameIOTest {
writer.writeData(ctx, 1000, data, 0, false, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onDataRead(eq(ctx), eq(1000), eq(data), eq(0), eq(false));
reader.readFrame(ctx, frame, listener);
verify(listener).onDataRead(eq(ctx), eq(1000), eq(data), eq(0), eq(false));
frame.release();
}
@ -81,8 +81,8 @@ public class DefaultHttp2FrameIOTest {
writer.writeData(ctx, 1000, data.retain().duplicate(), 0, false, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onDataRead(eq(ctx), eq(1000), eq(data), eq(0), eq(false));
reader.readFrame(ctx, frame, listener);
verify(listener).onDataRead(eq(ctx), eq(1000), eq(data), eq(0), eq(false));
frame.release();
}
@ -92,8 +92,8 @@ public class DefaultHttp2FrameIOTest {
writer.writeData(ctx, 1, data.retain().duplicate(), 0xFF, true, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onDataRead(eq(ctx), eq(1), eq(data), eq(0xFF), eq(true));
reader.readFrame(ctx, frame, listener);
verify(listener).onDataRead(eq(ctx), eq(1), eq(data), eq(0xFF), eq(true));
frame.release();
}
@ -102,8 +102,8 @@ public class DefaultHttp2FrameIOTest {
writer.writePriority(ctx, 1, 2, (short) 255, true, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onPriorityRead(eq(ctx), eq(1), eq(2), eq((short) 255), eq(true));
reader.readFrame(ctx, frame, listener);
verify(listener).onPriorityRead(eq(ctx), eq(1), eq(2), eq((short) 255), eq(true));
frame.release();
}
@ -112,8 +112,8 @@ public class DefaultHttp2FrameIOTest {
writer.writeRstStream(ctx, 1, MAX_UNSIGNED_INT, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onRstStreamRead(eq(ctx), eq(1), eq(MAX_UNSIGNED_INT));
reader.readFrame(ctx, frame, listener);
verify(listener).onRstStreamRead(eq(ctx), eq(1), eq(MAX_UNSIGNED_INT));
frame.release();
}
@ -122,8 +122,8 @@ public class DefaultHttp2FrameIOTest {
writer.writeSettings(ctx, new Http2Settings(), promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onSettingsRead(eq(ctx), eq(new Http2Settings()));
reader.readFrame(ctx, frame, listener);
verify(listener).onSettingsRead(eq(ctx), eq(new Http2Settings()));
frame.release();
}
@ -138,8 +138,8 @@ public class DefaultHttp2FrameIOTest {
writer.writeSettings(ctx, settings, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onSettingsRead(eq(ctx), eq(settings));
reader.readFrame(ctx, frame, listener);
verify(listener).onSettingsRead(eq(ctx), eq(settings));
frame.release();
}
@ -148,8 +148,8 @@ public class DefaultHttp2FrameIOTest {
writer.writeSettingsAck(ctx, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onSettingsAckRead(eq(ctx));
reader.readFrame(ctx, frame, listener);
verify(listener).onSettingsAckRead(eq(ctx));
frame.release();
}
@ -159,8 +159,8 @@ public class DefaultHttp2FrameIOTest {
writer.writePing(ctx, false, data.retain().duplicate(), promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onPingRead(eq(ctx), eq(data));
reader.readFrame(ctx, frame, listener);
verify(listener).onPingRead(eq(ctx), eq(data));
frame.release();
}
@ -170,8 +170,8 @@ public class DefaultHttp2FrameIOTest {
writer.writePing(ctx, true, data.retain().duplicate(), promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onPingAckRead(eq(ctx), eq(data));
reader.readFrame(ctx, frame, listener);
verify(listener).onPingAckRead(eq(ctx), eq(data));
frame.release();
}
@ -180,8 +180,8 @@ public class DefaultHttp2FrameIOTest {
ByteBuf data = dummyData();
writer.writeGoAway(ctx, 1, MAX_UNSIGNED_INT, data.retain().duplicate(), promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onGoAwayRead(eq(ctx), eq(1), eq(MAX_UNSIGNED_INT), eq(data));
reader.readFrame(ctx, frame, listener);
verify(listener).onGoAwayRead(eq(ctx), eq(1), eq(MAX_UNSIGNED_INT), eq(data));
frame.release();
}
@ -189,8 +189,8 @@ public class DefaultHttp2FrameIOTest {
public void windowUpdateShouldRoundtrip() throws Exception {
writer.writeWindowUpdate(ctx, 1, Integer.MAX_VALUE, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onWindowUpdateRead(eq(ctx), eq(1), eq(Integer.MAX_VALUE));
reader.readFrame(ctx, frame, listener);
verify(listener).onWindowUpdateRead(eq(ctx), eq(1), eq(Integer.MAX_VALUE));
frame.release();
}
@ -199,8 +199,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = Http2Headers.EMPTY_HEADERS;
writer.writeHeaders(ctx, 1, headers, 0, true, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(0), eq(true));
reader.readFrame(ctx, frame, listener);
verify(listener).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(0), eq(true));
frame.release();
}
@ -209,8 +209,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = Http2Headers.EMPTY_HEADERS;
writer.writeHeaders(ctx, 1, headers, 0xFF, true, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(0xFF), eq(true));
reader.readFrame(ctx, frame, listener);
verify(listener).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(0xFF), eq(true));
frame.release();
}
@ -219,8 +219,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = dummyHeaders();
writer.writeHeaders(ctx, 1, headers, 0, true, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(0), eq(true));
reader.readFrame(ctx, frame, listener);
verify(listener).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(0), eq(true));
frame.release();
}
@ -229,8 +229,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = dummyHeaders();
writer.writeHeaders(ctx, 1, headers, 0xFF, true, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(0xFF), eq(true));
reader.readFrame(ctx, frame, listener);
verify(listener).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(0xFF), eq(true));
frame.release();
}
@ -239,8 +239,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = dummyHeaders();
writer.writeHeaders(ctx, 1, headers, 2, (short) 3, true, 0, true, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0),
reader.readFrame(ctx, frame, listener);
verify(listener).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0),
eq(true));
frame.release();
}
@ -250,8 +250,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = dummyHeaders();
writer.writeHeaders(ctx, 1, headers, 2, (short) 3, true, 0xFF, true, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0xFF),
reader.readFrame(ctx, frame, listener);
verify(listener).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0xFF),
eq(true));
frame.release();
}
@ -261,8 +261,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = largeHeaders();
writer.writeHeaders(ctx, 1, headers, 2, (short) 3, true, 0, true, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0),
reader.readFrame(ctx, frame, listener);
verify(listener).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0),
eq(true));
frame.release();
}
@ -272,8 +272,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = largeHeaders();
writer.writeHeaders(ctx, 1, headers, 2, (short) 3, true, 0xFF, true, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0xFF),
reader.readFrame(ctx, frame, listener);
verify(listener).onHeadersRead(eq(ctx), eq(1), eq(headers), eq(2), eq((short) 3), eq(true), eq(0xFF),
eq(true));
frame.release();
}
@ -283,8 +283,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = Http2Headers.EMPTY_HEADERS;
writer.writePushPromise(ctx, 1, 2, headers, 0, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0));
reader.readFrame(ctx, frame, listener);
verify(listener).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0));
frame.release();
}
@ -293,8 +293,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = dummyHeaders();
writer.writePushPromise(ctx, 1, 2, headers, 0, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0));
reader.readFrame(ctx, frame, listener);
verify(listener).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0));
frame.release();
}
@ -303,8 +303,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = dummyHeaders();
writer.writePushPromise(ctx, 1, 2, headers, 0xFF, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0xFF));
reader.readFrame(ctx, frame, listener);
verify(listener).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0xFF));
frame.release();
}
@ -313,8 +313,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = largeHeaders();
writer.writePushPromise(ctx, 1, 2, headers, 0, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0));
reader.readFrame(ctx, frame, listener);
verify(listener).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0));
frame.release();
}
@ -323,8 +323,8 @@ public class DefaultHttp2FrameIOTest {
Http2Headers headers = largeHeaders();
writer.writePushPromise(ctx, 1, 2, headers, 0xFF, promise);
ByteBuf frame = captureWrite();
reader.readFrame(ctx, frame, observer);
verify(observer).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0xFF));
reader.readFrame(ctx, frame, listener);
verify(listener).onPushPromiseRead(eq(ctx), eq(1), eq(2), eq(headers), eq(0xFF));
frame.release();
}

View File

@ -104,7 +104,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
private Http2Stream pushStream;
@Mock
private Http2FrameObserver observer;
private Http2FrameListener listener;
@Mock
private Http2FrameReader reader;
@ -139,7 +139,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
handler =
new DelegatingHttp2ConnectionHandler(connection, reader, writer, inboundFlow,
outboundFlow, observer);
outboundFlow, listener);
// Simulate activation of the handler to force writing the initial settings.
Http2Settings settings = new Http2Settings();
@ -162,7 +162,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
// Simulate receiving the initial settings from the remote endpoint.
decode().onSettingsRead(ctx, new Http2Settings());
verify(observer).onSettingsRead(eq(ctx), eq(new Http2Settings()));
verify(listener).onSettingsRead(eq(ctx), eq(new Http2Settings()));
verify(writer).writeSettingsAck(eq(ctx), eq(promise));
// Simulate receiving the SETTINGS ACK for the initial settings.
@ -182,7 +182,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
public void clientShouldSendClientPrefaceStringWhenActive() throws Exception {
when(connection.isServer()).thenReturn(false);
handler = new DelegatingHttp2ConnectionHandler(connection, reader, writer, inboundFlow,
outboundFlow, observer);
outboundFlow, listener);
handler.channelActive(ctx);
verify(ctx).write(eq(connectionPrefaceBuf()));
}
@ -191,7 +191,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
public void serverShouldNotSendClientPrefaceStringWhenActive() throws Exception {
when(connection.isServer()).thenReturn(true);
handler = new DelegatingHttp2ConnectionHandler(connection, reader, writer, inboundFlow,
outboundFlow, observer);
outboundFlow, listener);
handler.channelActive(ctx);
verify(ctx, never()).write(eq(connectionPrefaceBuf()));
}
@ -200,21 +200,21 @@ public class DelegatingHttp2ConnectionHandlerTest {
public void serverReceivingInvalidClientPrefaceStringShouldCloseConnection() throws Exception {
when(connection.isServer()).thenReturn(true);
handler = new DelegatingHttp2ConnectionHandler(connection, reader, writer, inboundFlow,
outboundFlow, observer);
outboundFlow, listener);
handler.channelRead(ctx, copiedBuffer("BAD_PREFACE", UTF_8));
verify(ctx).close();
}
@Test
public void serverReceivingValidClientPrefaceStringShouldContinueReadingFrames() throws Exception {
reset(observer);
reset(listener);
when(connection.isServer()).thenReturn(true);
handler = new DelegatingHttp2ConnectionHandler(connection, reader, writer, inboundFlow,
outboundFlow, observer);
outboundFlow, listener);
handler.channelRead(ctx, connectionPrefaceBuf());
verify(ctx, never()).close();
decode().onSettingsRead(ctx, new Http2Settings());
verify(observer).onSettingsRead(eq(ctx), eq(new Http2Settings()));
verify(listener).onSettingsRead(eq(ctx), eq(new Http2Settings()));
}
@Test
@ -257,7 +257,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
verify(inboundFlow).onDataRead(eq(ctx), eq(STREAM_ID), eq(dummyData()), eq(10), eq(true));
// Verify that the event was absorbed and not propagated to the oberver.
verify(observer, never()).onDataRead(eq(ctx), anyInt(), any(ByteBuf.class), anyInt(),
verify(listener, never()).onDataRead(eq(ctx), anyInt(), any(ByteBuf.class), anyInt(),
anyBoolean());
}
@ -266,7 +266,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
decode().onDataRead(ctx, STREAM_ID, dummyData(), 10, true);
verify(inboundFlow).onDataRead(eq(ctx), eq(STREAM_ID), eq(dummyData()), eq(10), eq(true));
verify(stream).closeRemoteSide();
verify(observer).onDataRead(eq(ctx), eq(STREAM_ID), eq(dummyData()), eq(10), eq(true));
verify(listener).onDataRead(eq(ctx), eq(STREAM_ID), eq(dummyData()), eq(10), eq(true));
}
@Test
@ -276,7 +276,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
verify(remote, never()).createStream(eq(STREAM_ID), eq(false));
// Verify that the event was absorbed and not propagated to the oberver.
verify(observer, never()).onHeadersRead(eq(ctx), anyInt(), any(Http2Headers.class),
verify(listener, never()).onHeadersRead(eq(ctx), anyInt(), any(Http2Headers.class),
anyInt(), anyBoolean());
verify(remote, never()).createStream(anyInt(), anyBoolean());
}
@ -286,7 +286,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
when(remote.createStream(eq(5), eq(false))).thenReturn(stream);
decode().onHeadersRead(ctx, 5, EMPTY_HEADERS, 0, false);
verify(remote).createStream(eq(5), eq(false));
verify(observer).onHeadersRead(eq(ctx), eq(5), eq(EMPTY_HEADERS), eq(0),
verify(listener).onHeadersRead(eq(ctx), eq(5), eq(EMPTY_HEADERS), eq(0),
eq(DEFAULT_PRIORITY_WEIGHT), eq(false), eq(0), eq(false));
}
@ -295,7 +295,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
when(remote.createStream(eq(5), eq(true))).thenReturn(stream);
decode().onHeadersRead(ctx, 5, EMPTY_HEADERS, 0, true);
verify(remote).createStream(eq(5), eq(true));
verify(observer).onHeadersRead(eq(ctx), eq(5), eq(EMPTY_HEADERS), eq(0),
verify(listener).onHeadersRead(eq(ctx), eq(5), eq(EMPTY_HEADERS), eq(0),
eq(DEFAULT_PRIORITY_WEIGHT), eq(false), eq(0), eq(true));
}
@ -304,7 +304,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
when(stream.state()).thenReturn(RESERVED_REMOTE);
decode().onHeadersRead(ctx, STREAM_ID, EMPTY_HEADERS, 0, false);
verify(stream).openForPush();
verify(observer).onHeadersRead(eq(ctx), eq(STREAM_ID), eq(EMPTY_HEADERS), eq(0),
verify(listener).onHeadersRead(eq(ctx), eq(STREAM_ID), eq(EMPTY_HEADERS), eq(0),
eq(DEFAULT_PRIORITY_WEIGHT), eq(false), eq(0), eq(false));
}
@ -314,7 +314,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
decode().onHeadersRead(ctx, STREAM_ID, EMPTY_HEADERS, 0, true);
verify(stream).openForPush();
verify(stream).close();
verify(observer).onHeadersRead(eq(ctx), eq(STREAM_ID), eq(EMPTY_HEADERS), eq(0),
verify(listener).onHeadersRead(eq(ctx), eq(STREAM_ID), eq(EMPTY_HEADERS), eq(0),
eq(DEFAULT_PRIORITY_WEIGHT), eq(false), eq(0), eq(true));
}
@ -323,7 +323,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
when(remote.isGoAwayReceived()).thenReturn(true);
decode().onPushPromiseRead(ctx, STREAM_ID, PUSH_STREAM_ID, EMPTY_HEADERS, 0);
verify(remote, never()).reservePushStream(anyInt(), any(Http2Stream.class));
verify(observer, never()).onPushPromiseRead(eq(ctx), anyInt(), anyInt(),
verify(listener, never()).onPushPromiseRead(eq(ctx), anyInt(), anyInt(),
any(Http2Headers.class), anyInt());
}
@ -331,7 +331,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
public void pushPromiseReadShouldSucceed() throws Exception {
decode().onPushPromiseRead(ctx, STREAM_ID, PUSH_STREAM_ID, EMPTY_HEADERS, 0);
verify(remote).reservePushStream(eq(PUSH_STREAM_ID), eq(stream));
verify(observer).onPushPromiseRead(eq(ctx), eq(STREAM_ID), eq(PUSH_STREAM_ID),
verify(listener).onPushPromiseRead(eq(ctx), eq(STREAM_ID), eq(PUSH_STREAM_ID),
eq(EMPTY_HEADERS), eq(0));
}
@ -340,14 +340,14 @@ public class DelegatingHttp2ConnectionHandlerTest {
when(remote.isGoAwayReceived()).thenReturn(true);
decode().onPriorityRead(ctx, STREAM_ID, 0, (short) 255, true);
verify(stream, never()).setPriority(anyInt(), anyShort(), anyBoolean());
verify(observer, never()).onPriorityRead(eq(ctx), anyInt(), anyInt(), anyShort(), anyBoolean());
verify(listener, never()).onPriorityRead(eq(ctx), anyInt(), anyInt(), anyShort(), anyBoolean());
}
@Test
public void priorityReadShouldSucceed() throws Exception {
decode().onPriorityRead(ctx, STREAM_ID, 0, (short) 255, true);
verify(stream).setPriority(eq(0), eq((short) 255), eq(true));
verify(observer).onPriorityRead(eq(ctx), eq(STREAM_ID), eq(0), eq((short) 255), eq(true));
verify(listener).onPriorityRead(eq(ctx), eq(STREAM_ID), eq(0), eq((short) 255), eq(true));
}
@Test
@ -355,7 +355,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
when(remote.isGoAwayReceived()).thenReturn(true);
decode().onWindowUpdateRead(ctx, STREAM_ID, 10);
verify(outboundFlow, never()).updateOutboundWindowSize(anyInt(), anyInt());
verify(observer, never()).onWindowUpdateRead(eq(ctx), anyInt(), anyInt());
verify(listener, never()).onWindowUpdateRead(eq(ctx), anyInt(), anyInt());
}
@Test(expected = Http2Exception.class)
@ -368,7 +368,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
public void windowUpdateReadShouldSucceed() throws Exception {
decode().onWindowUpdateRead(ctx, STREAM_ID, 10);
verify(outboundFlow).updateOutboundWindowSize(eq(STREAM_ID), eq(10));
verify(observer).onWindowUpdateRead(eq(ctx), eq(STREAM_ID), eq(10));
verify(listener).onWindowUpdateRead(eq(ctx), eq(STREAM_ID), eq(10));
}
@Test
@ -376,7 +376,7 @@ public class DelegatingHttp2ConnectionHandlerTest {
when(remote.isGoAwayReceived()).thenReturn(true);
decode().onRstStreamRead(ctx, STREAM_ID, PROTOCOL_ERROR.code());
verify(stream).close();
verify(observer).onRstStreamRead(eq(ctx), anyInt(), anyLong());
verify(listener).onRstStreamRead(eq(ctx), anyInt(), anyLong());
}
@Test(expected = Http2Exception.class)
@ -389,27 +389,27 @@ public class DelegatingHttp2ConnectionHandlerTest {
public void rstStreamReadShouldCloseStream() throws Exception {
decode().onRstStreamRead(ctx, STREAM_ID, PROTOCOL_ERROR.code());
verify(stream).close();
verify(observer).onRstStreamRead(eq(ctx), eq(STREAM_ID), eq((long) PROTOCOL_ERROR.code()));
verify(listener).onRstStreamRead(eq(ctx), eq(STREAM_ID), eq((long) PROTOCOL_ERROR.code()));
}
@Test
public void pingReadWithAckShouldNotifyObserver() throws Exception {
public void pingReadWithAckShouldNotifylistener() throws Exception {
decode().onPingAckRead(ctx, emptyPingBuf());
verify(observer).onPingAckRead(eq(ctx), eq(emptyPingBuf()));
verify(listener).onPingAckRead(eq(ctx), eq(emptyPingBuf()));
}
@Test
public void pingReadShouldReplyWithAck() throws Exception {
decode().onPingRead(ctx, emptyPingBuf());
verify(writer).writePing(eq(ctx), eq(true), eq(emptyPingBuf()), eq(promise));
verify(observer, never()).onPingAckRead(eq(ctx), any(ByteBuf.class));
verify(listener, never()).onPingAckRead(eq(ctx), any(ByteBuf.class));
}
@Test
public void settingsReadWithAckShouldNotifyObserver() throws Exception {
public void settingsReadWithAckShouldNotifylistener() throws Exception {
decode().onSettingsAckRead(ctx);
// Take into account the time this was called during setup().
verify(observer, times(2)).onSettingsAckRead(eq(ctx));
verify(listener, times(2)).onSettingsAckRead(eq(ctx));
}
@Test(expected = Http2Exception.class)
@ -435,14 +435,14 @@ public class DelegatingHttp2ConnectionHandlerTest {
verify(writer).maxHeaderTableSize(789L);
// Take into account the time this was called during setup().
verify(writer, times(2)).writeSettingsAck(eq(ctx), eq(promise));
verify(observer).onSettingsRead(eq(ctx), eq(settings));
verify(listener).onSettingsRead(eq(ctx), eq(settings));
}
@Test
public void goAwayShouldReadShouldUpdateConnectionState() throws Exception {
decode().onGoAwayRead(ctx, 1, 2L, EMPTY_BUFFER);
verify(local).goAwayReceived(1);
verify(observer).onGoAwayRead(eq(ctx), eq(1), eq(2L), eq(EMPTY_BUFFER));
verify(listener).onGoAwayRead(eq(ctx), eq(1), eq(2L), eq(EMPTY_BUFFER));
}
@Test
@ -608,13 +608,13 @@ public class DelegatingHttp2ConnectionHandlerTest {
}
/**
* Calls the decode method on the handler and gets back the captured internal observer
* Calls the decode method on the handler and gets back the captured internal listener
*/
private Http2FrameObserver decode() throws Exception {
ArgumentCaptor<Http2FrameObserver> internalObserver =
ArgumentCaptor.forClass(Http2FrameObserver.class);
doNothing().when(reader).readFrame(eq(ctx), any(ByteBuf.class), internalObserver.capture());
private Http2FrameListener decode() throws Exception {
ArgumentCaptor<Http2FrameListener> internallistener =
ArgumentCaptor.forClass(Http2FrameListener.class);
doNothing().when(reader).readFrame(eq(ctx), any(ByteBuf.class), internallistener.capture());
handler.decode(ctx, EMPTY_BUFFER, Collections.emptyList());
return internalObserver.getValue();
return internallistener.getValue();
}
}

View File

@ -62,10 +62,10 @@ import org.mockito.MockitoAnnotations;
public class DelegatingHttp2HttpConnectionHandlerTest {
@Mock
private Http2FrameObserver clientObserver;
private Http2FrameListener clientListener;
@Mock
private Http2FrameObserver serverObserver;
private Http2FrameListener serverListener;
private ServerBootstrap sb;
private Bootstrap cb;
@ -100,7 +100,7 @@ public class DelegatingHttp2HttpConnectionHandlerTest {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new DelegatingHttp2HttpConnectionHandler(false, clientObserver));
p.addLast(new DelegatingHttp2HttpConnectionHandler(false, clientListener));
p.addLast(ignoreSettingsHandler());
}
});
@ -142,9 +142,9 @@ public class DelegatingHttp2HttpConnectionHandlerTest {
writeFuture.awaitUninterruptibly(2, SECONDS);
assertTrue(writeFuture.isSuccess());
awaitRequests();
verify(serverObserver).onHeadersRead(any(ChannelHandlerContext.class), eq(5), eq(http2Headers), eq(0),
verify(serverListener).onHeadersRead(any(ChannelHandlerContext.class), eq(5), eq(http2Headers), eq(0),
anyShort(), anyBoolean(), eq(0), eq(true));
verify(serverObserver, never()).onDataRead(any(ChannelHandlerContext.class),
verify(serverListener, never()).onDataRead(any(ChannelHandlerContext.class),
anyInt(), any(ByteBuf.class), anyInt(), anyBoolean());
}
@ -170,9 +170,9 @@ public class DelegatingHttp2HttpConnectionHandlerTest {
writeFuture.awaitUninterruptibly(2, SECONDS);
assertTrue(writeFuture.isSuccess());
awaitRequests();
verify(serverObserver).onHeadersRead(any(ChannelHandlerContext.class), eq(3), eq(http2Headers), eq(0),
verify(serverListener).onHeadersRead(any(ChannelHandlerContext.class), eq(3), eq(http2Headers), eq(0),
anyShort(), anyBoolean(), eq(0), eq(false));
verify(serverObserver).onDataRead(any(ChannelHandlerContext.class),
verify(serverListener).onDataRead(any(ChannelHandlerContext.class),
eq(3), eq(Unpooled.copiedBuffer(text.getBytes())), eq(0), eq(true));
}
@ -192,20 +192,20 @@ public class DelegatingHttp2HttpConnectionHandlerTest {
* A decorator around the serverObserver that counts down the latch so that we can await the
* completion of the request.
*/
private final class FrameCountDown implements Http2FrameObserver {
private final class FrameCountDown implements Http2FrameListener {
@Override
public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding,
boolean endOfStream)
throws Http2Exception {
serverObserver.onDataRead(ctx, streamId, copy(data), padding, endOfStream);
serverListener.onDataRead(ctx, streamId, copy(data), padding, endOfStream);
requestLatch.countDown();
}
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
int padding, boolean endStream) throws Http2Exception {
serverObserver.onHeadersRead(ctx, streamId, headers, padding, endStream);
serverListener.onHeadersRead(ctx, streamId, headers, padding, endStream);
requestLatch.countDown();
}
@ -213,7 +213,7 @@ public class DelegatingHttp2HttpConnectionHandlerTest {
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
int streamDependency, short weight, boolean exclusive, int padding,
boolean endStream) throws Http2Exception {
serverObserver.onHeadersRead(ctx, streamId, headers, streamDependency, weight,
serverListener.onHeadersRead(ctx, streamId, headers, streamDependency, weight,
exclusive, padding, endStream);
requestLatch.countDown();
}
@ -221,66 +221,66 @@ public class DelegatingHttp2HttpConnectionHandlerTest {
@Override
public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency,
short weight, boolean exclusive) throws Http2Exception {
serverObserver.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
serverListener.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
requestLatch.countDown();
}
@Override
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode)
throws Http2Exception {
serverObserver.onRstStreamRead(ctx, streamId, errorCode);
serverListener.onRstStreamRead(ctx, streamId, errorCode);
requestLatch.countDown();
}
@Override
public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception {
serverObserver.onSettingsAckRead(ctx);
serverListener.onSettingsAckRead(ctx);
requestLatch.countDown();
}
@Override
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception {
serverObserver.onSettingsRead(ctx, settings);
serverListener.onSettingsRead(ctx, settings);
requestLatch.countDown();
}
@Override
public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
serverObserver.onPingRead(ctx, copy(data));
serverListener.onPingRead(ctx, copy(data));
requestLatch.countDown();
}
@Override
public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
serverObserver.onPingAckRead(ctx, copy(data));
serverListener.onPingAckRead(ctx, copy(data));
requestLatch.countDown();
}
@Override
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId,
int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
serverObserver.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding);
serverListener.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding);
requestLatch.countDown();
}
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData)
throws Http2Exception {
serverObserver.onGoAwayRead(ctx, lastStreamId, errorCode, copy(debugData));
serverListener.onGoAwayRead(ctx, lastStreamId, errorCode, copy(debugData));
requestLatch.countDown();
}
@Override
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId,
int windowSizeIncrement) throws Http2Exception {
serverObserver.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
serverListener.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
requestLatch.countDown();
}
@Override
public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int streamId,
Http2Flags flags, ByteBuf payload) {
serverObserver.onUnknownFrame(ctx, frameType, streamId, flags, payload);
serverListener.onUnknownFrame(ctx, frameType, streamId, flags, payload);
requestLatch.countDown();
}

View File

@ -49,10 +49,10 @@ import static org.mockito.Mockito.*;
public class Http2ConnectionRoundtripTest {
@Mock
private Http2FrameObserver clientObserver;
private Http2FrameListener clientListener;
@Mock
private Http2FrameObserver serverObserver;
private Http2FrameListener serverListener;
private DelegatingHttp2ConnectionHandler http2Client;
private ServerBootstrap sb;
@ -86,7 +86,7 @@ public class Http2ConnectionRoundtripTest {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new DelegatingHttp2ConnectionHandler(false, clientObserver));
p.addLast(new DelegatingHttp2ConnectionHandler(false, clientListener));
p.addLast(Http2CodecUtil.ignoreSettingsHandler());
}
});
@ -129,11 +129,11 @@ public class Http2ConnectionRoundtripTest {
});
// Wait for all frames to be received.
awaitRequests();
verify(serverObserver, times(NUM_STREAMS)).onHeadersRead(any(ChannelHandlerContext.class),
verify(serverListener, times(NUM_STREAMS)).onHeadersRead(any(ChannelHandlerContext.class),
anyInt(), eq(headers), eq(0), eq((short) 16), eq(false), eq(0), eq(false));
verify(serverObserver, times(NUM_STREAMS)).onPingRead(any(ChannelHandlerContext.class),
verify(serverListener, times(NUM_STREAMS)).onPingRead(any(ChannelHandlerContext.class),
eq(Unpooled.copiedBuffer(pingMsg.getBytes())));
verify(serverObserver, times(NUM_STREAMS)).onDataRead(any(ChannelHandlerContext.class),
verify(serverListener, times(NUM_STREAMS)).onDataRead(any(ChannelHandlerContext.class),
anyInt(), eq(Unpooled.copiedBuffer(text.getBytes())), eq(0), eq(true));
}
@ -153,20 +153,20 @@ public class Http2ConnectionRoundtripTest {
* A decorator around the serverObserver that counts down the latch so that we can await the
* completion of the request.
*/
private final class FrameCountDown implements Http2FrameObserver {
private final class FrameCountDown implements Http2FrameListener {
@Override
public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding,
boolean endOfStream)
throws Http2Exception {
serverObserver.onDataRead(ctx, streamId, copy(data), padding, endOfStream);
serverListener.onDataRead(ctx, streamId, copy(data), padding, endOfStream);
requestLatch.countDown();
}
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
int padding, boolean endStream) throws Http2Exception {
serverObserver.onHeadersRead(ctx, streamId, headers, padding, endStream);
serverListener.onHeadersRead(ctx, streamId, headers, padding, endStream);
requestLatch.countDown();
}
@ -174,7 +174,7 @@ public class Http2ConnectionRoundtripTest {
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
int streamDependency, short weight, boolean exclusive, int padding,
boolean endStream) throws Http2Exception {
serverObserver.onHeadersRead(ctx, streamId, headers, streamDependency, weight,
serverListener.onHeadersRead(ctx, streamId, headers, streamDependency, weight,
exclusive, padding, endStream);
requestLatch.countDown();
}
@ -182,66 +182,66 @@ public class Http2ConnectionRoundtripTest {
@Override
public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency,
short weight, boolean exclusive) throws Http2Exception {
serverObserver.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
serverListener.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
requestLatch.countDown();
}
@Override
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode)
throws Http2Exception {
serverObserver.onRstStreamRead(ctx, streamId, errorCode);
serverListener.onRstStreamRead(ctx, streamId, errorCode);
requestLatch.countDown();
}
@Override
public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception {
serverObserver.onSettingsAckRead(ctx);
serverListener.onSettingsAckRead(ctx);
requestLatch.countDown();
}
@Override
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception {
serverObserver.onSettingsRead(ctx, settings);
serverListener.onSettingsRead(ctx, settings);
requestLatch.countDown();
}
@Override
public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
serverObserver.onPingRead(ctx, copy(data));
serverListener.onPingRead(ctx, copy(data));
requestLatch.countDown();
}
@Override
public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
serverObserver.onPingAckRead(ctx, copy(data));
serverListener.onPingAckRead(ctx, copy(data));
requestLatch.countDown();
}
@Override
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId,
int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
serverObserver.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding);
serverListener.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding);
requestLatch.countDown();
}
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData)
throws Http2Exception {
serverObserver.onGoAwayRead(ctx, lastStreamId, errorCode, copy(debugData));
serverListener.onGoAwayRead(ctx, lastStreamId, errorCode, copy(debugData));
requestLatch.countDown();
}
@Override
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId,
int windowSizeIncrement) throws Http2Exception {
serverObserver.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
serverListener.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
requestLatch.countDown();
}
@Override
public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int streamId,
Http2Flags flags, ByteBuf payload) {
serverObserver.onUnknownFrame(ctx, frameType, streamId, flags, payload);
serverListener.onUnknownFrame(ctx, frameType, streamId, flags, payload);
requestLatch.countDown();
}

View File

@ -54,7 +54,7 @@ import static org.mockito.Mockito.*;
public class Http2FrameRoundtripTest {
@Mock
private Http2FrameObserver serverObserver;
private Http2FrameListener serverObserver;
private ArgumentCaptor<ByteBuf> dataCaptor;
private Http2FrameWriter frameWriter;
@ -308,10 +308,10 @@ public class Http2FrameRoundtripTest {
private final class FrameAdapter extends ByteToMessageDecoder {
private final Http2FrameObserver observer;
private final Http2FrameListener observer;
private final DefaultHttp2FrameReader reader;
FrameAdapter(Http2FrameObserver observer) {
FrameAdapter(Http2FrameListener observer) {
this.observer = observer;
reader = new DefaultHttp2FrameReader();
}
@ -319,7 +319,7 @@ public class Http2FrameRoundtripTest {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)
throws Exception {
reader.readFrame(ctx, in, new Http2FrameObserver() {
reader.readFrame(ctx, in, new Http2FrameListener() {
@Override
public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data,

View File

@ -69,10 +69,10 @@ import org.mockito.MockitoAnnotations;
public class InboundHttp2ToHttpAdapterTest {
@Mock
private HttpResponseListener serverObserver;
private HttpResponseListener serverListener;
@Mock
private HttpResponseListener clientObserver;
private HttpResponseListener clientListener;
private Http2FrameWriter frameWriter;
private ServerBootstrap sb;
@ -111,7 +111,7 @@ public class InboundHttp2ToHttpAdapterTest {
p.addLast("reader", new FrameAdapter(connection,
InboundHttp2ToHttpPriorityAdapter.newInstance(connection, maxContentLength),
new CountDownLatch(10)));
serverDelegator = new HttpResponseDelegator(serverObserver, serverLatch);
serverDelegator = new HttpResponseDelegator(serverListener, serverLatch);
p.addLast(serverDelegator);
serverConnectedChannel = ch;
}
@ -127,7 +127,7 @@ public class InboundHttp2ToHttpAdapterTest {
p.addLast("reader", new FrameAdapter(connection,
InboundHttp2ToHttpPriorityAdapter.newInstance(connection, maxContentLength),
new CountDownLatch(10)));
clientDelegator = new HttpResponseDelegator(clientObserver, clientLatch);
clientDelegator = new HttpResponseDelegator(clientListener, clientLatch);
p.addLast(clientDelegator);
}
});
@ -171,7 +171,7 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitRequests();
verify(serverObserver).messageReceived(eq(request));
verify(serverListener).messageReceived(eq(request));
}
@Test
@ -195,7 +195,7 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitRequests();
verify(serverObserver).messageReceived(eq(request));
verify(serverListener).messageReceived(eq(request));
request.release();
}
@ -223,7 +223,7 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitRequests();
verify(serverObserver).messageReceived(eq(request));
verify(serverListener).messageReceived(eq(request));
request.release();
}
@ -249,7 +249,7 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitRequests();
verify(serverObserver).messageReceived(eq(request));
verify(serverListener).messageReceived(eq(request));
request.release();
}
@ -283,7 +283,7 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitRequests();
verify(serverObserver).messageReceived(eq(request));
verify(serverListener).messageReceived(eq(request));
request.release();
}
@ -314,7 +314,7 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitRequests();
verify(serverObserver).messageReceived(eq(request));
verify(serverListener).messageReceived(eq(request));
request.release();
}
@ -355,7 +355,7 @@ public class InboundHttp2ToHttpAdapterTest {
});
awaitRequests();
ArgumentCaptor<HttpObject> httpObjectCaptor = ArgumentCaptor.forClass(HttpObject.class);
verify(serverObserver, times(2)).messageReceived(httpObjectCaptor.capture());
verify(serverListener, times(2)).messageReceived(httpObjectCaptor.capture());
List<HttpObject> capturedHttpObjects = httpObjectCaptor.getAllValues();
assertEquals(request, capturedHttpObjects.get(0));
assertEquals(request2, capturedHttpObjects.get(1));
@ -406,7 +406,7 @@ public class InboundHttp2ToHttpAdapterTest {
});
awaitRequests();
ArgumentCaptor<HttpObject> httpObjectCaptor = ArgumentCaptor.forClass(HttpObject.class);
verify(serverObserver, times(3)).messageReceived(httpObjectCaptor.capture());
verify(serverListener, times(3)).messageReceived(httpObjectCaptor.capture());
List<HttpObject> capturedHttpObjects = httpObjectCaptor.getAllValues();
assertEquals(request, capturedHttpObjects.get(0));
assertEquals(request2, capturedHttpObjects.get(1));
@ -450,7 +450,7 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitRequests();
verify(serverObserver).messageReceived(eq(request));
verify(serverListener).messageReceived(eq(request));
final Http2Headers http2Headers = new DefaultHttp2Headers.Builder().status("200").build();
final Http2Headers http2Headers2 = new DefaultHttp2Headers.Builder().status("201").scheme("https")
@ -467,7 +467,7 @@ public class InboundHttp2ToHttpAdapterTest {
});
awaitResponses();
ArgumentCaptor<HttpObject> httpObjectCaptor = ArgumentCaptor.forClass(HttpObject.class);
verify(clientObserver, times(2)).messageReceived(httpObjectCaptor.capture());
verify(clientListener, times(2)).messageReceived(httpObjectCaptor.capture());
List<HttpObject> capturedHttpObjects = httpObjectCaptor.getAllValues();
assertEquals(response, capturedHttpObjects.get(0));
assertEquals(response2, capturedHttpObjects.get(1));
@ -493,8 +493,8 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitRequests();
verify(serverObserver).messageReceived(eq(request));
reset(serverObserver);
verify(serverListener).messageReceived(eq(request));
reset(serverListener);
final FullHttpMessage response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE);
httpHeaders = response.headers();
@ -509,8 +509,8 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitResponses();
verify(clientObserver).messageReceived(eq(response));
reset(clientObserver);
verify(clientListener).messageReceived(eq(response));
reset(clientListener);
setServerLatch(1);
final String text = "a big payload";
@ -528,7 +528,7 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitRequests();
verify(serverObserver).messageReceived(eq(request2));
verify(serverListener).messageReceived(eq(request2));
request2.release();
setClientLatch(1);
@ -545,7 +545,7 @@ public class InboundHttp2ToHttpAdapterTest {
}
});
awaitResponses();
verify(clientObserver).messageReceived(eq(response2));
verify(clientListener).messageReceived(eq(response2));
}
private void setServerLatch(int count) {
@ -613,20 +613,20 @@ public class InboundHttp2ToHttpAdapterTest {
private final class FrameAdapter extends ByteToMessageDecoder {
private final Http2Connection connection;
private final Http2FrameObserver observer;
private final Http2FrameListener listener;
private final DefaultHttp2FrameReader reader;
private final CountDownLatch latch;
FrameAdapter(Http2Connection connection, Http2FrameObserver observer, CountDownLatch latch) {
FrameAdapter(Http2Connection connection, Http2FrameListener listener, CountDownLatch latch) {
this.connection = connection;
this.observer = observer;
this.listener = listener;
reader = new DefaultHttp2FrameReader();
this.latch = latch;
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
reader.readFrame(ctx, in, new Http2FrameObserver() {
reader.readFrame(ctx, in, new Http2FrameListener() {
public Http2Stream getOrCreateStream(int streamId, boolean halfClosed) throws Http2Exception {
Http2Stream stream = connection.stream(streamId);
if (stream == null) {
@ -649,7 +649,7 @@ public class InboundHttp2ToHttpAdapterTest {
@Override
public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding,
boolean endOfStream) throws Http2Exception {
observer.onDataRead(ctx, streamId, copy(data), padding, endOfStream);
listener.onDataRead(ctx, streamId, copy(data), padding, endOfStream);
// NOTE: Do not close the stream to allow the out of order messages to be processed
latch.countDown();
}
@ -658,7 +658,7 @@ public class InboundHttp2ToHttpAdapterTest {
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding,
boolean endStream) throws Http2Exception {
Http2Stream stream = getOrCreateStream(streamId, endStream);
observer.onHeadersRead(ctx, streamId, headers, padding, endStream);
listener.onHeadersRead(ctx, streamId, headers, padding, endStream);
if (endStream) {
closeStream(stream);
}
@ -671,7 +671,7 @@ public class InboundHttp2ToHttpAdapterTest {
throws Http2Exception {
Http2Stream stream = getOrCreateStream(streamId, endStream);
stream.setPriority(streamDependency, weight, exclusive);
observer.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive, padding,
listener.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive, padding,
endStream);
if (endStream) {
closeStream(stream);
@ -684,7 +684,7 @@ public class InboundHttp2ToHttpAdapterTest {
boolean exclusive) throws Http2Exception {
Http2Stream stream = getOrCreateStream(streamId, false);
stream.setPriority(streamDependency, weight, exclusive);
observer.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
listener.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
latch.countDown();
}
@ -692,32 +692,32 @@ public class InboundHttp2ToHttpAdapterTest {
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode)
throws Http2Exception {
Http2Stream stream = getOrCreateStream(streamId, false);
observer.onRstStreamRead(ctx, streamId, errorCode);
listener.onRstStreamRead(ctx, streamId, errorCode);
closeStream(stream);
latch.countDown();
}
@Override
public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception {
observer.onSettingsAckRead(ctx);
listener.onSettingsAckRead(ctx);
latch.countDown();
}
@Override
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception {
observer.onSettingsRead(ctx, settings);
listener.onSettingsRead(ctx, settings);
latch.countDown();
}
@Override
public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
observer.onPingRead(ctx, copy(data));
listener.onPingRead(ctx, copy(data));
latch.countDown();
}
@Override
public void onPingAckRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
observer.onPingAckRead(ctx, copy(data));
listener.onPingAckRead(ctx, copy(data));
latch.countDown();
}
@ -725,14 +725,14 @@ public class InboundHttp2ToHttpAdapterTest {
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId,
Http2Headers headers, int padding) throws Http2Exception {
getOrCreateStream(promisedStreamId, false);
observer.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding);
listener.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding);
latch.countDown();
}
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData)
throws Http2Exception {
observer.onGoAwayRead(ctx, lastStreamId, errorCode, copy(debugData));
listener.onGoAwayRead(ctx, lastStreamId, errorCode, copy(debugData));
latch.countDown();
}
@ -740,14 +740,14 @@ public class InboundHttp2ToHttpAdapterTest {
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement)
throws Http2Exception {
getOrCreateStream(streamId, false);
observer.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
listener.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
latch.countDown();
}
@Override
public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags,
ByteBuf payload) {
observer.onUnknownFrame(ctx, frameType, streamId, flags, payload);
listener.onUnknownFrame(ctx, frameType, streamId, flags, payload);
latch.countDown();
}
});