Fix javadoc, and remove deprecated classes

This commit is contained in:
Carl Mastrangelo 2015-08-06 11:21:14 -07:00
parent 7faeab6b45
commit b7822e8f88
3 changed files with 30 additions and 53 deletions

View File

@ -324,17 +324,17 @@ public final class Status {
*/ */
public static Status fromThrowable(Throwable t) { public static Status fromThrowable(Throwable t) {
for (Throwable cause : Throwables.getCausalChain(t)) { for (Throwable cause : Throwables.getCausalChain(t)) {
if (cause instanceof OperationException) { if (cause instanceof StatusException) {
return ((Status.OperationException) cause).getStatus(); return ((StatusException) cause).getStatus();
} else if (cause instanceof OperationRuntimeException) { } else if (cause instanceof StatusRuntimeException) {
return ((Status.OperationRuntimeException) cause).getStatus(); return ((StatusRuntimeException) cause).getStatus();
} }
} }
// Couldn't find a cause with a Status // Couldn't find a cause with a Status
return UNKNOWN.withCause(t); return UNKNOWN.withCause(t);
} }
private static String formatThrowableMessage(Status status) { static String formatThrowableMessage(Status status) {
if (status.description == null) { if (status.description == null) {
return status.code.toString(); return status.code.toString();
} else { } else {
@ -421,7 +421,7 @@ public final class Status {
} }
/** /**
* Convert this {@link Status} to a {@link RuntimeException}. Use {@code #fromThrowable} * Convert this {@link Status} to a {@link RuntimeException}. Use {@link #fromThrowable}
* to recover this {@link Status} instance when the returned exception is in the causal chain. * to recover this {@link Status} instance when the returned exception is in the causal chain.
*/ */
public StatusRuntimeException asRuntimeException() { public StatusRuntimeException asRuntimeException() {
@ -429,7 +429,7 @@ public final class Status {
} }
/** /**
* Convert this {@link Status} to an {@link Exception}. Use {@code #fromThrowable} * Convert this {@link Status} to an {@link Exception}. Use {@link #fromThrowable}
* to recover this {@link Status} instance when the returned exception is in the causal chain. * to recover this {@link Status} instance when the returned exception is in the causal chain.
*/ */
public StatusException asException() { public StatusException asException() {
@ -448,46 +448,6 @@ public final class Status {
.toString(); .toString();
} }
/**
* Exception thrown by implementations while managing an operation.
*
* @deprecated Use {@link StatusException} instead
*/
@Deprecated
public static class OperationException extends Exception {
private static final long serialVersionUID = -660954903976144640L;
private final Status status;
public OperationException(Status status) {
super(formatThrowableMessage(status), status.getCause());
this.status = status;
}
public Status getStatus() {
return status;
}
}
/**
* Runtime exception thrown by implementations while managing an operation.
*
* @deprecated Use {@link StatusRuntimeException} instead
*/
@Deprecated
public static class OperationRuntimeException extends RuntimeException {
private static final long serialVersionUID = 1950934672280720624L;
private final Status status;
public OperationRuntimeException(Status status) {
super(formatThrowableMessage(status), status.getCause());
this.status = status;
}
public Status getStatus() {
return status;
}
}
private static class StatusCodeMarshaller implements Metadata.AsciiMarshaller<Status> { private static class StatusCodeMarshaller implements Metadata.AsciiMarshaller<Status> {
@Override @Override
public String toAsciiString(Status status) { public String toAsciiString(Status status) {

View File

@ -31,14 +31,23 @@
package io.grpc; package io.grpc;
import static io.grpc.Status.formatThrowableMessage;
/** /**
* {@link Status} in Exception form, for propagating Status information via exceptions. * {@link Status} in Exception form, for propagating Status information via exceptions.
* *
* @see StatusRuntimeException * @see StatusRuntimeException
*/ */
@SuppressWarnings("deprecation") public class StatusException extends Exception {
public class StatusException extends Status.OperationException { private static final long serialVersionUID = -660954903976144640L;
private final Status status;
public StatusException(Status status) { public StatusException(Status status) {
super(status); super(formatThrowableMessage(status), status.getCause());
this.status = status;
}
public Status getStatus() {
return status;
} }
} }

View File

@ -36,9 +36,17 @@ package io.grpc;
* *
* @see StatusException * @see StatusException
*/ */
@SuppressWarnings("deprecation") public class StatusRuntimeException extends RuntimeException {
public class StatusRuntimeException extends Status.OperationRuntimeException {
private static final long serialVersionUID = 1950934672280720624L;
private final Status status;
public StatusRuntimeException(Status status) { public StatusRuntimeException(Status status) {
super(status); super(Status.formatThrowableMessage(status), status.getCause());
this.status = status;
}
public Status getStatus() {
return status;
} }
} }