mirror of https://github.com/grpc/grpc-java.git
Move decompressor setting down into the AbstractStream
This commit is contained in:
parent
f7f57b79c9
commit
46c18ea237
|
|
@ -32,7 +32,6 @@
|
||||||
package io.grpc.inprocess;
|
package io.grpc.inprocess;
|
||||||
|
|
||||||
import io.grpc.Compressor;
|
import io.grpc.Compressor;
|
||||||
import io.grpc.Decompressor;
|
|
||||||
import io.grpc.DecompressorRegistry;
|
import io.grpc.DecompressorRegistry;
|
||||||
import io.grpc.Metadata;
|
import io.grpc.Metadata;
|
||||||
import io.grpc.MethodDescriptor;
|
import io.grpc.MethodDescriptor;
|
||||||
|
|
@ -221,12 +220,6 @@ class InProcessTransport implements ServerTransport, ClientTransport {
|
||||||
// intentional nop
|
// intentional nop
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDecompressor(Decompressor d) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDecompressor(String messageEncoding) {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDecompressionRegistry(DecompressorRegistry registry) {}
|
public void setDecompressionRegistry(DecompressorRegistry registry) {}
|
||||||
|
|
||||||
|
|
@ -446,16 +439,6 @@ class InProcessTransport implements ServerTransport, ClientTransport {
|
||||||
// nop
|
// nop
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDecompressor(Decompressor d) {
|
|
||||||
// nop
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDecompressor(String messageEncoding) {
|
|
||||||
// nop
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDecompressionRegistry(DecompressorRegistry registry) {}
|
public void setDecompressionRegistry(DecompressorRegistry registry) {}
|
||||||
}
|
}
|
||||||
|
|
@ -487,16 +470,6 @@ class InProcessTransport implements ServerTransport, ClientTransport {
|
||||||
// very much a nop
|
// very much a nop
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDecompressor(Decompressor d) {
|
|
||||||
// nop
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDecompressor(String messageEncoding) {
|
|
||||||
// nop
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDecompressionRegistry(DecompressorRegistry registry) {}
|
public void setDecompressionRegistry(DecompressorRegistry registry) {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -293,8 +293,7 @@ public abstract class AbstractStream<IdT> implements Stream {
|
||||||
* after the message encoding header is provided by the remote host, but before any messages are
|
* after the message encoding header is provided by the remote host, but before any messages are
|
||||||
* received.
|
* received.
|
||||||
*/
|
*/
|
||||||
@Override
|
protected final void setDecompressor(Decompressor d) {
|
||||||
public final void setDecompressor(Decompressor d) {
|
|
||||||
deframer.setDecompressor(d);
|
deframer.setDecompressor(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,7 +304,6 @@ public abstract class AbstractStream<IdT> implements Stream {
|
||||||
* @param messageEncoding the name of the encoding provided by the remote host
|
* @param messageEncoding the name of the encoding provided by the remote host
|
||||||
* @throws IllegalArgumentException if the provided message encoding cannot be found.
|
* @throws IllegalArgumentException if the provided message encoding cannot be found.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public final void setDecompressor(String messageEncoding) {
|
public final void setDecompressor(String messageEncoding) {
|
||||||
Decompressor d = decompressorRegistry.lookupDecompressor(messageEncoding);
|
Decompressor d = decompressorRegistry.lookupDecompressor(messageEncoding);
|
||||||
checkArgument(d != null,
|
checkArgument(d != null,
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ import io.grpc.CallOptions;
|
||||||
import io.grpc.ClientCall;
|
import io.grpc.ClientCall;
|
||||||
import io.grpc.Codec;
|
import io.grpc.Codec;
|
||||||
import io.grpc.Compressor;
|
import io.grpc.Compressor;
|
||||||
import io.grpc.Decompressor;
|
|
||||||
import io.grpc.DecompressorRegistry;
|
import io.grpc.DecompressorRegistry;
|
||||||
import io.grpc.Metadata;
|
import io.grpc.Metadata;
|
||||||
import io.grpc.MethodDescriptor;
|
import io.grpc.MethodDescriptor;
|
||||||
|
|
@ -371,12 +370,6 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDecompressor(Decompressor d) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDecompressor(String messageEncoding) {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDecompressionRegistry(DecompressorRegistry registry) {}
|
public void setDecompressionRegistry(DecompressorRegistry registry) {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -325,19 +325,6 @@ public final class ServerImpl extends io.grpc.Server {
|
||||||
private <ReqT, RespT> ServerStreamListener startCall(ServerStream stream, String fullMethodName,
|
private <ReqT, RespT> ServerStreamListener startCall(ServerStream stream, String fullMethodName,
|
||||||
ServerMethodDefinition<ReqT, RespT> methodDef, Future<?> timeout,
|
ServerMethodDefinition<ReqT, RespT> methodDef, Future<?> timeout,
|
||||||
Metadata headers) {
|
Metadata headers) {
|
||||||
|
|
||||||
String messageEncoding = headers.get(GrpcUtil.MESSAGE_ENCODING_KEY);
|
|
||||||
if (messageEncoding != null) {
|
|
||||||
try {
|
|
||||||
stream.setDecompressor(messageEncoding);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw Status.INVALID_ARGUMENT
|
|
||||||
.withDescription("Unable to decompress message with encoding: " + messageEncoding)
|
|
||||||
.withCause(e)
|
|
||||||
.asRuntimeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(ejona86): should we update fullMethodName to have the canonical path of the method?
|
// TODO(ejona86): should we update fullMethodName to have the canonical path of the method?
|
||||||
ServerCallImpl<ReqT, RespT> call = new ServerCallImpl<ReqT, RespT>(
|
ServerCallImpl<ReqT, RespT> call = new ServerCallImpl<ReqT, RespT>(
|
||||||
stream, methodDef.getMethodDescriptor());
|
stream, methodDef.getMethodDescriptor());
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@
|
||||||
package io.grpc.internal;
|
package io.grpc.internal;
|
||||||
|
|
||||||
import io.grpc.Compressor;
|
import io.grpc.Compressor;
|
||||||
import io.grpc.Decompressor;
|
|
||||||
import io.grpc.DecompressorRegistry;
|
import io.grpc.DecompressorRegistry;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
@ -86,22 +85,6 @@ public interface Stream {
|
||||||
*/
|
*/
|
||||||
void setCompressor(Compressor c);
|
void setCompressor(Compressor c);
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the decompressor for this stream. This may be called at most once. Typically this is set
|
|
||||||
* after the message encoding header is provided by the remote host, but before any messages are
|
|
||||||
* received.
|
|
||||||
*/
|
|
||||||
void setDecompressor(Decompressor d);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Looks up the decompressor by its message encoding name, and sets it for this stream.
|
|
||||||
* Decompressors are registered with {@link io.grpc.DecompressorRegistry#register}.
|
|
||||||
*
|
|
||||||
* @param messageEncoding the name of the encoding provided by the remote host
|
|
||||||
* @throws IllegalArgumentException if the provided message encoding cannot be found.
|
|
||||||
*/
|
|
||||||
void setDecompressor(String messageEncoding);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the decompressor registry to use when resolving {@link #setDecompressor(String)}. If
|
* Sets the decompressor registry to use when resolving {@link #setDecompressor(String)}. If
|
||||||
* unset, the default DecompressorRegistry will be used.
|
* unset, the default DecompressorRegistry will be used.
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,19 @@ class NettyServerHandler extends Http2ConnectionHandler {
|
||||||
NettyServerStream stream = new NettyServerStream(ctx.channel(), http2Stream, this,
|
NettyServerStream stream = new NettyServerStream(ctx.channel(), http2Stream, this,
|
||||||
maxMessageSize);
|
maxMessageSize);
|
||||||
Metadata metadata = Utils.convertHeaders(headers);
|
Metadata metadata = Utils.convertHeaders(headers);
|
||||||
|
|
||||||
|
String messageEncoding = metadata.get(GrpcUtil.MESSAGE_ENCODING_KEY);
|
||||||
|
if (messageEncoding != null) {
|
||||||
|
try {
|
||||||
|
stream.setDecompressor(messageEncoding);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw Status.INVALID_ARGUMENT
|
||||||
|
.withDescription("Unable to decompress message with encoding: " + messageEncoding)
|
||||||
|
.withCause(e)
|
||||||
|
.asRuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ServerStreamListener listener =
|
ServerStreamListener listener =
|
||||||
transportListener.streamCreated(stream, method, metadata);
|
transportListener.streamCreated(stream, method, metadata);
|
||||||
stream.setListener(listener);
|
stream.setListener(listener);
|
||||||
|
|
|
||||||
|
|
@ -128,8 +128,4 @@ class NettyServerStream extends AbstractServerStream<Integer> {
|
||||||
public void cancel(Status status) {
|
public void cancel(Status status) {
|
||||||
writeQueue.enqueue(new CancelServerStreamCommand(this, status), true);
|
writeQueue.enqueue(new CancelServerStreamCommand(this, status), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void useDecompressor(String messageEncoding) {
|
|
||||||
setDecompressor(messageEncoding);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue