mirror of https://github.com/grpc/grpc-java.git
core: ClientCallImpl start should not be called after cancel
Added checkState for this condition.
This commit is contained in:
parent
b8b5f5e046
commit
65530bb71b
|
|
@ -28,7 +28,6 @@ import static io.grpc.internal.GrpcUtil.TIMEOUT_KEY;
|
||||||
import static java.lang.Math.max;
|
import static java.lang.Math.max;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import io.grpc.Attributes;
|
import io.grpc.Attributes;
|
||||||
import io.grpc.CallOptions;
|
import io.grpc.CallOptions;
|
||||||
import io.grpc.ClientCall;
|
import io.grpc.ClientCall;
|
||||||
|
|
@ -146,6 +145,7 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
||||||
@Override
|
@Override
|
||||||
public void start(final Listener<RespT> observer, Metadata headers) {
|
public void start(final Listener<RespT> observer, Metadata headers) {
|
||||||
checkState(stream == null, "Already started");
|
checkState(stream == null, "Already started");
|
||||||
|
checkState(!cancelCalled, "call was cancelled");
|
||||||
checkNotNull(observer, "observer");
|
checkNotNull(observer, "observer");
|
||||||
checkNotNull(headers, "headers");
|
checkNotNull(headers, "headers");
|
||||||
|
|
||||||
|
|
@ -336,7 +336,7 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void request(int numMessages) {
|
public void request(int numMessages) {
|
||||||
Preconditions.checkState(stream != null, "Not started");
|
checkState(stream != null, "Not started");
|
||||||
checkArgument(numMessages >= 0, "Number requested must be non-negative");
|
checkArgument(numMessages >= 0, "Number requested must be non-negative");
|
||||||
stream.request(numMessages);
|
stream.request(numMessages);
|
||||||
}
|
}
|
||||||
|
|
@ -371,18 +371,18 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void halfClose() {
|
public void halfClose() {
|
||||||
Preconditions.checkState(stream != null, "Not started");
|
checkState(stream != null, "Not started");
|
||||||
Preconditions.checkState(!cancelCalled, "call was cancelled");
|
checkState(!cancelCalled, "call was cancelled");
|
||||||
Preconditions.checkState(!halfCloseCalled, "call already half-closed");
|
checkState(!halfCloseCalled, "call already half-closed");
|
||||||
halfCloseCalled = true;
|
halfCloseCalled = true;
|
||||||
stream.halfClose();
|
stream.halfClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(ReqT message) {
|
public void sendMessage(ReqT message) {
|
||||||
Preconditions.checkState(stream != null, "Not started");
|
checkState(stream != null, "Not started");
|
||||||
Preconditions.checkState(!cancelCalled, "call was cancelled");
|
checkState(!cancelCalled, "call was cancelled");
|
||||||
Preconditions.checkState(!halfCloseCalled, "call was half-closed");
|
checkState(!halfCloseCalled, "call was half-closed");
|
||||||
try {
|
try {
|
||||||
// TODO(notcarl): Find out if messageIs needs to be closed.
|
// TODO(notcarl): Find out if messageIs needs to be closed.
|
||||||
InputStream messageIs = method.streamRequest(message);
|
InputStream messageIs = method.streamRequest(message);
|
||||||
|
|
@ -427,7 +427,7 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
|
|
||||||
public ClientStreamListenerImpl(Listener<RespT> observer) {
|
public ClientStreamListenerImpl(Listener<RespT> observer) {
|
||||||
this.observer = Preconditions.checkNotNull(observer, "observer");
|
this.observer = checkNotNull(observer, "observer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue