本文整理汇总了Java中io.grpc.stub.StreamObserver.onError方法的典型用法代码示例。如果您正苦于以下问题:Java StreamObserver.onError方法的具体用法?Java StreamObserver.onError怎么用?Java StreamObserver.onError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.stub.StreamObserver
的用法示例。
在下文中一共展示了StreamObserver.onError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: downloadProductImage
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void downloadProductImage(DownloadProductImageRequest request, StreamObserver<DataChunk> responseObserver) {
try {
BufferedInputStream imageStream = new BufferedInputStream(
productImageSeeker.seekProductImage(request.getProductId())
);
int bufferSize = 256 * 1024;// 256k
byte[] buffer = new byte[bufferSize];
int length;
while ((length = imageStream.read(buffer, 0, bufferSize)) != -1) {
responseObserver.onNext(
DataChunk.newBuilder().setData(ByteString.copyFrom(buffer, 0, length)).build()
);
}
responseObserver.onCompleted();
imageStream.close();
counter.labels("downloadProductImage", "success");
} catch (Exception e) {
counter.labels("downloadProductImage", "failed");
log.error("error on read product image", e);
responseObserver.onError(e);
}
}
示例2: execute
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void execute(
ExecuteRequest request, StreamObserver<Operation> responseObserver) {
Instance instance;
try {
instance = instances.get(request.getInstanceName());
} catch (InstanceNotFoundException ex) {
responseObserver.onError(BuildFarmInstances.toStatusException(ex));
return;
}
instance.execute(
request.getAction(),
request.getSkipCacheLookup(),
request.getTotalInputFileCount(),
request.getTotalInputFileBytes(),
(operation) -> {
responseObserver.onNext(operation);
responseObserver.onCompleted();
});
}
示例3: failPlease
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void failPlease(FailWithProbabilityOrSucceedEchoRequest request,
StreamObserver<EchoResponse> responseObserver) {
EchoRequest echoRequest = request.getEchoRequest();
int failProbability = request.getFailProbability();
Preconditions.checkArgument(failProbability >= 0 && failProbability <= 100,
"fail probability not [" + failProbability + "] not in range [0, 100] inclusive");
logger.info("fail please - p(" + failProbability + " / 100)" + " echo: " + echoRequest.getEcho()
+ " with " + "repetitions: " + echoRequest.getRepeatEcho() + " received at "
+ DATE_FORMAT.format(new Date(System.currentTimeMillis())));
int randomFail = RANDOM.nextInt(100);
if (randomFail < failProbability) {
Status status = Status.INTERNAL;
status = status.withCause(new FailPleaseException("Looks like you hit jackpot - we failed!"));
responseObserver.onError(status.asRuntimeException());
} else {
responseObserver.onNext(buildEchoResponseFromEchoRequest(echoRequest));
responseObserver.onCompleted();
}
}
示例4: updateActionResult
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void updateActionResult(
UpdateActionResultRequest request,
StreamObserver<ActionResult> responseObserver) {
Instance instance;
try {
instance = instances.get(request.getInstanceName());
} catch (InstanceNotFoundException ex) {
responseObserver.onError(BuildFarmInstances.toStatusException(ex));
return;
}
ActionResult actionResult = request.getActionResult();
instance.putActionResult(request.getActionDigest(), actionResult);
responseObserver.onNext(actionResult);
responseObserver.onCompleted();
}
示例5: publish
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void publish(@NonNull MSG_Facts request,
@NonNull StreamObserver<MSG_Empty> responseObserver) {
List<Fact> facts = request.getFactList().stream().map(converter::fromProto).collect(
Collectors.toList());
final int size = facts.size();
log.debug("publish {} fact{}", size, size > 1 ? "s" : "");
log.trace("publish {}", facts);
try {
log.trace("store publish {}", facts);
store.publish(facts);
log.trace("store publish done");
responseObserver.onNext(MSG_Empty.getDefaultInstance());
responseObserver.onCompleted();
} catch (Throwable e) {
log.error("Problem while publishing: ", e);
responseObserver.onError(new StatusRuntimeException(Status.INTERNAL.withDescription(e
.getMessage())));
}
}
示例6: invoke
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void invoke(byte[] msg, StreamObserver<byte[]> responseObserver) {
final RequestBody reqBody = RequestBody.create(OCTET_STREAM, msg);
final Request req = new Request.Builder().url(url).post(reqBody).build();
try {
try (Response resp = client.newCall(req).execute()) {
final ResponseBody respBody = resp.body();
if (respBody != null) {
responseObserver.onNext(respBody.bytes());
}
}
responseObserver.onCompleted();
} catch (IOException e) {
responseObserver.onError(e);
}
}
示例7: clientstream
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@RequestMapping("/clientstream")
public HelloReply clientstream(@RequestParam(value = "name", required = false) String name) {
HelloRequest request = new HelloRequest();
request.setName(name);
RpcContext.getContext().set("123", "123");
StreamObserver<com.quancheng.examples.model.hello.HelloRequest> requestObserver =
helloService.sayHelloClientStream(responseObserver());
try {
for (int i = 0; i < 10; i++) {
requestObserver.onNext(request);
}
} catch (Exception e) {
requestObserver.onError(e);
}
requestObserver.onCompleted();
return null;
}
示例8: poll
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void poll(
PollOperationRequest request,
StreamObserver<com.google.rpc.Status> responseObserver) {
Instance instance;
try {
instance = instances.getFromOperationName(
request.getOperationName());
} catch (InstanceNotFoundException ex) {
responseObserver.onError(BuildFarmInstances.toStatusException(ex));
return;
}
boolean ok = instance.pollOperation(
request.getOperationName(),
request.getStage());
Code code = ok ? Code.OK : Code.UNAVAILABLE;
responseObserver.onNext(com.google.rpc.Status.newBuilder()
.setCode(code.getNumber())
.build());
responseObserver.onCompleted();
}
示例9: oneToMany
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
/**
* Implements a unary -> stream call as {@link Mono} -> {@link Flux}, where the server responds with a
* stream of messages.
*/
public static <TRequest, TResponse> void oneToMany(
TRequest request, StreamObserver<TResponse> responseObserver,
Function<Mono<TRequest>, Flux<TResponse>> delegate) {
try {
Mono<TRequest> rxRequest = Mono.just(request);
Flux<TResponse> rxResponse = Preconditions.checkNotNull(delegate.apply(rxRequest));
rxResponse.subscribe(new ReactivePublisherBackpressureOnReadyHandler<>(
(ServerCallStreamObserver<TResponse>) responseObserver));
} catch (Throwable throwable) {
responseObserver.onError(prepareError(throwable));
}
}
示例10: searchProducts
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void searchProducts(SearchProductsRequest request, StreamObserver<SearchProductsResponse> responseObserver) {
try {
responseObserver.onNext(productDao.searchProducts(request));
responseObserver.onCompleted();
counter.labels("searchProducts", "success");
} catch (Exception e) {
log.error(" error on search product with request - {}", request, e);
responseObserver.onError(e);
counter.labels("searchProducts", "failed");
}
}
示例11: getStore
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
public void getStore(GetStoreRequest request, StreamObserver<GetStoreResponse> resp) {
try {
resp.onNext(getStoreResp.removeFirst().get());
resp.onCompleted();
} catch (Exception e) {
resp.onError(Status.INTERNAL.asRuntimeException());
}
}
示例12: onPlayerLogin
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void onPlayerLogin(PlayerLoginEvent event, StreamObserver<PlayerLoginEvent> observer) {
try {
getPluginManager().onPlayerLogin(event, observer);
} catch (ServiceNotConnectedException ex) {
log.error("Not connected:", ex);
observer.onError(ex);
}
}
示例13: onPlayerJoin
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void onPlayerJoin(PlayerJoinEvent event, StreamObserver<PlayerJoinEvent> observer) {
try {
getPluginManager().onPlayerJoin(event, observer);
} catch (ServiceNotConnectedException ex) {
log.error("Not connected:", ex);
observer.onError(ex);
}
}
示例14: getOperation
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void getOperation(
GetOperationRequest request,
StreamObserver<Operation> responseObserver) {
Instance instance;
try {
instance = instances.getFromOperationName(request.getName());
} catch (InstanceNotFoundException ex) {
responseObserver.onError(BuildFarmInstances.toStatusException(ex));
return;
}
responseObserver.onNext(instance.getOperation(request.getName()));
responseObserver.onCompleted();
}
示例15: listOperations
import io.grpc.stub.StreamObserver; //导入方法依赖的package包/类
@Override
public void listOperations(
ListOperationsRequest request,
StreamObserver<ListOperationsResponse> responseObserver) {
Instance instance;
try {
instance = instances.getFromOperationsCollectionName(
request.getName());
} catch (InstanceNotFoundException ex) {
responseObserver.onError(BuildFarmInstances.toStatusException(ex));
return;
}
int pageSize = request.getPageSize();
if (pageSize < 0) {
responseObserver.onError(new StatusException(Status.OUT_OF_RANGE));
return;
}
ImmutableList.Builder<Operation> operations =
new ImmutableList.Builder<Operation>();
String nextPageToken = instance.listOperations(
pageSize,
request.getPageToken(),
request.getFilter(),
operations);
responseObserver.onNext(ListOperationsResponse.newBuilder()
.addAllOperations(operations.build())
.setNextPageToken(nextPageToken)
.build());
responseObserver.onCompleted();
}