Update GRPC to work with latest Netty version.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=71285057
diff --git a/core/src/main/java/com/google/net/stubby/http2/netty/Http2Codec.java b/core/src/main/java/com/google/net/stubby/http2/netty/Http2Codec.java
index b8826a8..925adb7 100644
--- a/core/src/main/java/com/google/net/stubby/http2/netty/Http2Codec.java
+++ b/core/src/main/java/com/google/net/stubby/http2/netty/Http2Codec.java
@@ -12,24 +12,19 @@
import com.google.net.stubby.transport.MessageFramer;
import com.google.net.stubby.transport.Transport.Code;
-import java.util.Map;
-
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http2.AbstractHttp2ConnectionHandler;
import io.netty.handler.codec.http2.DefaultHttp2Connection;
-import io.netty.handler.codec.http2.DefaultHttp2FrameReader;
-import io.netty.handler.codec.http2.DefaultHttp2FrameWriter;
-import io.netty.handler.codec.http2.DefaultHttp2InboundFlowController;
-import io.netty.handler.codec.http2.DefaultHttp2OutboundFlowController;
import io.netty.handler.codec.http2.Http2Connection;
import io.netty.handler.codec.http2.Http2Error;
import io.netty.handler.codec.http2.Http2Exception;
import io.netty.handler.codec.http2.Http2Headers;
import io.netty.handler.codec.http2.Http2Settings;
+import java.util.Map;
+
/**
* Codec used by clients and servers to interpret HTTP2 frames in the context of an ongoing
* request-response dialog
@@ -37,7 +32,6 @@
public class Http2Codec extends AbstractHttp2ConnectionHandler {
public static final int PADDING = 0;
- private final boolean client;
private final RequestRegistry requestRegistry;
private final Session session;
private Http2Codec.Http2Writer http2Writer;
@@ -46,27 +40,23 @@
* Constructor used by servers, takes a session which will receive operation events.
*/
public Http2Codec(Session session, RequestRegistry requestRegistry) {
- this(new DefaultHttp2Connection(true, false), false, session, requestRegistry);
+ this(new DefaultHttp2Connection(true), session, requestRegistry);
}
/**
* Constructor used by clients to send operations to a remote server
*/
public Http2Codec(RequestRegistry requestRegistry) {
- this(new DefaultHttp2Connection(false, false), true, null, requestRegistry);
+ this(new DefaultHttp2Connection(false), null, requestRegistry);
}
/**
* Constructor used by servers, takes a session which will receive operation events.
*/
- private Http2Codec(Http2Connection connection, boolean client,
+ private Http2Codec(Http2Connection connection,
Session session,
RequestRegistry requestRegistry) {
- super(connection, new DefaultHttp2FrameReader(),
- new SuppressCompressionSettingsWriter(), new DefaultHttp2InboundFlowController(connection),
- new DefaultHttp2OutboundFlowController(connection));
- // TODO(user): Use connection.isServer when not private in base class
- this.client = client;
+ super(connection);
this.session = session;
this.requestRegistry = requestRegistry;
}
@@ -82,14 +72,14 @@
@Override
public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding,
- boolean endOfStream, boolean endOfSegment, boolean compressed)
+ boolean endOfStream, boolean endOfSegment)
throws Http2Exception {
Request request = requestRegistry.lookup(streamId);
if (request == null) {
// Stream may have been terminated already or this is just plain spurious
throw Http2Exception.format(Http2Error.STREAM_CLOSED, "Stream does not exist");
}
- Operation operation = client ? request.getResponse() : request;
+ Operation operation = isClient() ? request.getResponse() : request;
try {
ByteBufDeframer deframer = getOrCreateDeframer(operation, ctx);
deframer.deframe(data, operation);
@@ -112,7 +102,7 @@
boolean endStream, boolean endSegment) throws Http2Exception {
Request operation = requestRegistry.lookup(streamId);
if (operation == null) {
- if (client) {
+ if (isClient()) {
// For clients an operation must already exist in the registry
throw Http2Exception.format(Http2Error.REFUSED_STREAM, "Stream does not exist");
} else {
@@ -124,7 +114,7 @@
}
}
if (endStream) {
- finish(client ? operation.getResponse() : operation);
+ finish(isClient() ? operation.getResponse() : operation);
}
}
@@ -183,15 +173,8 @@
// TODO
}
- @Override
- public void onAltSvcRead(ChannelHandlerContext ctx, int streamId, long maxAge, int port,
- ByteBuf protocolId, String host, String origin) throws Http2Exception {
- // TODO
- }
-
- @Override
- public void onBlockedRead(ChannelHandlerContext ctx, int streamId) throws Http2Exception {
- // TODO
+ private boolean isClient() {
+ return !connection().isServer();
}
/**
@@ -274,28 +257,6 @@
}
}
- // TODO(user): Remove this once fixes are done in netty too
- private static class SuppressCompressionSettingsWriter extends DefaultHttp2FrameWriter {
- @Override
- public ChannelFuture writeSettings(ChannelHandlerContext ctx, ChannelPromise promise,
- Http2Settings settings) {
- Http2Settings newSettings = new Http2Settings();
- if (settings.hasInitialWindowSize()) {
- newSettings.initialWindowSize(settings.initialWindowSize());
- }
- if (settings.hasMaxConcurrentStreams()) {
- newSettings.maxConcurrentStreams(settings.maxConcurrentStreams());
- }
- if (settings.hasMaxHeaderTableSize()) {
- newSettings.maxHeaderTableSize(settings.maxHeaderTableSize());
- }
- if (settings.hasPushEnabled()) {
- newSettings.pushEnabled(settings.pushEnabled());
- }
- return super.writeSettings(ctx, promise, newSettings);
- }
- }
-
public class Http2Writer {
private final ChannelHandlerContext ctx;