当前位置: 首页>>代码示例>>Java>>正文


Java ServerCallStreamObserver.setCompression方法代码示例

本文整理汇总了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);
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:9,代码来源:BlockingStreamObserver.java

示例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();
}
 
开发者ID:line,项目名称:armeria,代码行数:15,代码来源:GrpcServiceServerTest.java

示例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();
}
 
开发者ID:line,项目名称:armeria,代码行数:58,代码来源:TestServiceImpl.java

示例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();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:46,代码来源:TestServiceImpl.java


注:本文中的io.grpc.stub.ServerCallStreamObserver.setCompression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。