本文整理汇总了Java中io.grpc.stub.ServerCallStreamObserver.setCompression方法的典型用法代码示例。如果您正苦于以下问题:Java ServerCallStreamObserver.setCompression方法的具体用法?Java ServerCallStreamObserver.setCompression怎么用?Java ServerCallStreamObserver.setCompression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.stub.ServerCallStreamObserver
的用法示例。
在下文中一共展示了ServerCallStreamObserver.setCompression方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BlockingStreamObserver
import io.grpc.stub.ServerCallStreamObserver; //导入方法依赖的package包/类
BlockingStreamObserver(String id, ServerCallStreamObserver<T> delegate) {
this.id = id;
this.delegate = delegate;
this.delegate.setOnReadyHandler(this::wakeup);
this.delegate.setOnCancelHandler(this::wakeup);
delegate.setCompression("gzip");
delegate.setMessageCompression(true);
}
示例2: staticUnaryCallSetsMessageCompression
import io.grpc.stub.ServerCallStreamObserver; //导入方法依赖的package包/类
@Override
public void staticUnaryCallSetsMessageCompression(SimpleRequest request,
StreamObserver<SimpleResponse> responseObserver) {
if (!request.equals(REQUEST_MESSAGE)) {
responseObserver.onError(new IllegalArgumentException("Unexpected request: " + request));
return;
}
ServerCallStreamObserver<SimpleResponse> callObserver =
(ServerCallStreamObserver<SimpleResponse>) responseObserver;
callObserver.setCompression("gzip");
callObserver.setMessageCompression(true);
responseObserver.onNext(RESPONSE_MESSAGE);
responseObserver.onCompleted();
}
示例3: unaryCall
import io.grpc.stub.ServerCallStreamObserver; //导入方法依赖的package包/类
/**
* Immediately responds with a payload of the type and size specified in the request.
*/
@Override
public void unaryCall(SimpleRequest req, StreamObserver<SimpleResponse> responseObserver) {
ServerCallStreamObserver<SimpleResponse> obs =
(ServerCallStreamObserver<SimpleResponse>) responseObserver;
SimpleResponse.Builder responseBuilder = SimpleResponse.newBuilder();
try {
switch (req.getResponseCompression()) {
case DEFLATE:
// fallthrough, just use gzip
case GZIP:
obs.setCompression("gzip");
break;
case NONE:
obs.setCompression("identity");
break;
case UNRECOGNIZED:
// fallthrough
default:
obs.onError(Status.INVALID_ARGUMENT
.withDescription("Unknown: " + req.getResponseCompression())
.asRuntimeException());
return;
}
} catch (IllegalArgumentException e) {
obs.onError(Status.UNIMPLEMENTED
.withDescription("compression not supported.")
.withCause(e)
.asRuntimeException());
return;
}
if (req.getResponseSize() != 0) {
boolean compressable = compressableResponse(req.getResponseType());
ByteString dataBuffer = compressable ? compressableBuffer : uncompressableBuffer;
// For consistency with the c++ TestServiceImpl, use a random offset for unary calls.
// TODO(wonderfly): whether or not this is a good approach needs further discussion.
int offset = random.nextInt(
compressable ? compressableBuffer.size() : uncompressableBuffer.size());
ByteString payload = generatePayload(dataBuffer, offset, req.getResponseSize());
responseBuilder.getPayloadBuilder()
.setType(compressable ? PayloadType.COMPRESSABLE : PayloadType.UNCOMPRESSABLE)
.setBody(payload);
}
if (req.hasResponseStatus()) {
obs.onError(Status.fromCodeValue(req.getResponseStatus().getCode())
.withDescription(req.getResponseStatus().getMessage())
.asRuntimeException());
return;
}
responseObserver.onNext(responseBuilder.build());
responseObserver.onCompleted();
}
示例4: unaryCall
import io.grpc.stub.ServerCallStreamObserver; //导入方法依赖的package包/类
/**
* Immediately responds with a payload of the type and size specified in the request.
*/
@Override
public void unaryCall(SimpleRequest req, StreamObserver<SimpleResponse> responseObserver) {
ServerCallStreamObserver<SimpleResponse> obs =
(ServerCallStreamObserver<SimpleResponse>) responseObserver;
SimpleResponse.Builder responseBuilder = SimpleResponse.newBuilder();
try {
if (req.hasResponseCompressed() && req.getResponseCompressed().getValue()) {
obs.setCompression("gzip");
} else {
obs.setCompression("identity");
}
} catch (IllegalArgumentException e) {
obs.onError(Status.UNIMPLEMENTED
.withDescription("compression not supported.")
.withCause(e)
.asRuntimeException());
return;
}
if (req.getResponseSize() != 0) {
boolean compressable = compressableResponse(req.getResponseType());
ByteString dataBuffer = compressable ? compressableBuffer : uncompressableBuffer;
// For consistency with the c++ TestServiceImpl, use a random offset for unary calls.
// TODO(wonderfly): whether or not this is a good approach needs further discussion.
int offset = random.nextInt(
compressable ? compressableBuffer.size() : uncompressableBuffer.size());
ByteString payload = generatePayload(dataBuffer, offset, req.getResponseSize());
responseBuilder.getPayloadBuilder()
.setType(compressable ? PayloadType.COMPRESSABLE : PayloadType.UNCOMPRESSABLE)
.setBody(payload);
}
if (req.hasResponseStatus()) {
obs.onError(Status.fromCodeValue(req.getResponseStatus().getCode())
.withDescription(req.getResponseStatus().getMessage())
.asRuntimeException());
return;
}
responseObserver.onNext(responseBuilder.build());
responseObserver.onCompleted();
}