本文整理了Java中io.grpc.Status.getCause()
方法的一些代码示例,展示了Status.getCause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Status.getCause()
方法的具体详情如下:
包路径:io.grpc.Status
类名称:Status
方法名:getCause
[英]The underlying cause of an error. Note that the cause is not transmitted from server to client.
[中]错误的根本原因。请注意,原因不会从服务器传输到客户端。
代码示例来源:origin: line/armeria
static HttpHeaders statusToTrailers(ServiceRequestContext ctx, Status status, boolean headersSent) {
final HttpHeaders trailers;
if (headersSent) {
// Normal trailers.
trailers = new DefaultHttpHeaders();
} else {
// Trailers only response
trailers = new DefaultHttpHeaders(true, 3, true)
.status(HttpStatus.OK)
.set(HttpHeaderNames.CONTENT_TYPE, "application/grpc+proto");
}
trailers.add(GrpcHeaderNames.GRPC_STATUS, Integer.toString(status.getCode().value()));
if (status.getDescription() != null) {
trailers.add(GrpcHeaderNames.GRPC_MESSAGE, StatusMessageEscaper.escape(status.getDescription()));
}
if (ctx.server().config().verboseResponses() && status.getCause() != null) {
final ThrowableProto proto = GrpcStatus.serializeThrowable(status.getCause());
trailers.add(GrpcHeaderNames.ARMERIA_GRPC_THROWABLEPROTO_BIN,
Base64.getEncoder().encodeToString(proto.toByteArray()));
}
return trailers;
}
代码示例来源:origin: stephenh/mirror
private static String niceToString(Status status) {
// the default Status.toString has a stack trace in it, which is ugly
return MoreObjects
.toStringHelper(status)
.add("code", status.getCode().name())
.add("description", status.getDescription())
.add("cause", status.getCause() != null ? status.getCause().getMessage() : null)
.toString();
}
代码示例来源:origin: SonarSource/sonarlint-core
@Override
public void close(Status status, Metadata trailers) {
Status transformed = status;
if (transformed.getDescription() == null && transformed.getCause() != null) {
transformed = status.withDescription(status.getCause().getMessage());
}
super.close(transformed, trailers);
}
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
/** {@inheritDoc} */
@Override
public void onClose(Status status, Metadata trailers) {
if (status.getCause() instanceof StreamWaitTimeoutException
&& ((StreamWaitTimeoutException)status.getCause()).getState() == State.WAITING) {
handleTimeoutError(status);
return;
}
super.onClose(status, trailers);
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Constructs the exception with both a status and trailers.
*/
@ExperimentalApi
public StatusRuntimeException(Status status, @Nullable Metadata trailers) {
super(Status.formatThrowableMessage(status), status.getCause());
this.status = status;
this.trailers = trailers;
}
代码示例来源:origin: io.grpc/grpc-core
StatusRuntimeException(Status status, @Nullable Metadata trailers, boolean fillInStackTrace) {
super(Status.formatThrowableMessage(status), status.getCause());
this.status = status;
this.trailers = trailers;
this.fillInStackTrace = fillInStackTrace;
fillInStackTrace();
}
代码示例来源:origin: io.grpc/grpc-core
StatusException(Status status, @Nullable Metadata trailers, boolean fillInStackTrace) {
super(Status.formatThrowableMessage(status), status.getCause());
this.status = status;
this.trailers = trailers;
this.fillInStackTrace = fillInStackTrace;
fillInStackTrace();
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Constructs an exception with both a status and trailers.
*/
@ExperimentalApi
public StatusException(Status status, @Nullable Metadata trailers) {
super(Status.formatThrowableMessage(status), status.getCause());
this.status = status;
this.trailers = trailers;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
@Override
public void closed(final Status status) {
// For cancellations, promptly inform any users of the context that their work should be
// aborted. Otherwise, we can wait until pending work is done.
if (!status.isOk()) {
// The callExecutor might be busy doing user work. To avoid waiting, use an executor that
// is not serializing.
cancelExecutor.execute(new ContextCloser(context, status.getCause()));
}
final class Closed extends ContextRunnable {
Closed() {
super(context);
}
@Override
public void runInContext() {
getListener().closed(status);
}
}
callExecutor.execute(new Closed());
}
代码示例来源:origin: io.grpc/grpc-core
@Override
public void closed(final Status status) {
// For cancellations, promptly inform any users of the context that their work should be
// aborted. Otherwise, we can wait until pending work is done.
if (!status.isOk()) {
// The callExecutor might be busy doing user work. To avoid waiting, use an executor that
// is not serializing.
cancelExecutor.execute(new ContextCloser(context, status.getCause()));
}
final class Closed extends ContextRunnable {
Closed() {
super(context);
}
@Override
public void runInContext() {
getListener().closed(status);
}
}
callExecutor.execute(new Closed());
}
代码示例来源:origin: io.etcd/jetcd-common
private static EtcdException fromStatus(Status status) {
return newEtcdException(
ErrorCode.fromGrpcStatus(status),
status.getDescription(),
status.getCause()
);
}
}
代码示例来源:origin: etcd-io/jetcd
private static EtcdException fromStatus(Status status) {
return newEtcdException(
ErrorCode.fromGrpcStatus(status),
status.getDescription(),
status.getCause()
);
}
}
代码示例来源:origin: com.coreos/jetcd-common
private static EtcdException fromStatus(Status status) {
return newEtcdException(
ErrorCode.fromGrpcStatus(status),
status.getDescription(),
status.getCause()
);
}
}
代码示例来源:origin: com.linecorp.armeria/armeria-grpc
static HttpHeaders statusToTrailers(ServiceRequestContext ctx, Status status, boolean headersSent) {
final HttpHeaders trailers;
if (headersSent) {
// Normal trailers.
trailers = new DefaultHttpHeaders();
} else {
// Trailers only response
trailers = new DefaultHttpHeaders(true, 3, true)
.status(HttpStatus.OK)
.set(HttpHeaderNames.CONTENT_TYPE, "application/grpc+proto");
}
trailers.add(GrpcHeaderNames.GRPC_STATUS, Integer.toString(status.getCode().value()));
if (status.getDescription() != null) {
trailers.add(GrpcHeaderNames.GRPC_MESSAGE, StatusMessageEscaper.escape(status.getDescription()));
}
if (ctx.server().config().verboseResponses() && status.getCause() != null) {
final ThrowableProto proto = GrpcStatus.serializeThrowable(status.getCause());
trailers.add(GrpcHeaderNames.ARMERIA_GRPC_THROWABLEPROTO_BIN,
Base64.getEncoder().encodeToString(proto.toByteArray()));
}
return trailers;
}
代码示例来源:origin: io.grpc/grpc-core
/**
* Returns the {@link Status} of a cancelled context or {@code null} if the context
* is not cancelled.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1975")
public static Status statusFromCancelled(Context context) {
Preconditions.checkNotNull(context, "context must not be null");
if (!context.isCancelled()) {
return null;
}
Throwable cancellationCause = context.cancellationCause();
if (cancellationCause == null) {
return Status.CANCELLED.withDescription("io.grpc.Context was cancelled without error");
}
if (cancellationCause instanceof TimeoutException) {
return Status.DEADLINE_EXCEEDED
.withDescription(cancellationCause.getMessage())
.withCause(cancellationCause);
}
Status status = Status.fromThrowable(cancellationCause);
if (Status.Code.UNKNOWN.equals(status.getCode())
&& status.getCause() == cancellationCause) {
// If fromThrowable could not determine a status, then
// just return CANCELLED.
return Status.CANCELLED.withDescription("Context cancelled").withCause(cancellationCause);
}
return status.withCause(cancellationCause);
}
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
/**
* Special retry handling for watchdog timeouts, which uses its own fail counter.
*
* @return true if a retry has been scheduled
*/
private void handleTimeoutError(Status status) {
Preconditions.checkArgument(status.getCause() instanceof StreamWaitTimeoutException,
"status is not caused by a StreamWaitTimeoutException");
StreamWaitTimeoutException e = ((StreamWaitTimeoutException) status.getCause());
// Cancel the existing rpc.
rpcTimerContext.close();
failedCount++;
// Can this request be retried
int maxRetries = retryOptions.getMaxScanTimeoutRetries();
if (retryOptions.enableRetries() && ++timeoutRetryCount <= maxRetries) {
LOG.warn("The client could not get a response in %d ms. Retrying the scan.",
e.getWaitTimeMs());
resetStatusBasedBackoff();
performRetry(0);
} else {
LOG.warn("The client could not get a response after %d tries, giving up.",
timeoutRetryCount);
rpc.getRpcMetrics().markFailure();
finalizeStats(status);
setException(getExhaustedRetriesException(status));
}
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
status.getCause(), failedCount, status, channelId, trailers);
rpc.getRpcMetrics().markFailure();
finalizeStats(status);
status.getCause(), failedCount, status, channelId, trailers);
setException(getExhaustedRetriesException(status));
} else {
LOG.warn("Retrying failed call. Failure #%d, got: %s on channel %s.\nTrailers: %s",
status.getCause(), failedCount, status, channelId, trailers);
performRetry(nextBackOff);
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Returns the {@link Status} of a cancelled context or {@code null} if the context
* is not cancelled.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1975")
public static Status statusFromCancelled(Context context) {
Preconditions.checkNotNull(context, "context must not be null");
if (!context.isCancelled()) {
return null;
}
Throwable cancellationCause = context.cancellationCause();
if (cancellationCause == null) {
return Status.CANCELLED.withDescription("io.grpc.Context was cancelled without error");
}
if (cancellationCause instanceof TimeoutException) {
return Status.DEADLINE_EXCEEDED
.withDescription(cancellationCause.getMessage())
.withCause(cancellationCause);
}
Status status = Status.fromThrowable(cancellationCause);
if (Status.Code.UNKNOWN.equals(status.getCode())
&& status.getCause() == cancellationCause) {
// If fromThrowable could not determine a status, then
// just return CANCELLED.
return Status.CANCELLED.withDescription("Context cancelled").withCause(cancellationCause);
}
return status.withCause(cancellationCause);
}
}
内容来源于网络,如有侵权,请联系作者删除!