diff --git a/README.md b/README.md index 42daad2c34..5a935abc3b 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ The 'channel' layer is an abstraction over transport handling that is suitable f #### Client * [Channel - client side binding](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Channel.java) -* [Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Call.java) +* [Client Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientCall.java) * [Client Interceptor](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientInterceptor.java) #### Server diff --git a/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java b/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java index a9699ea77e..2af4b1be8e 100644 --- a/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java +++ b/auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java @@ -34,10 +34,10 @@ package io.grpc.auth; import com.google.auth.Credentials; import com.google.common.base.Preconditions; -import io.grpc.Call; import io.grpc.Channel; +import io.grpc.ClientCall; import io.grpc.ClientInterceptor; -import io.grpc.ClientInterceptors.CheckedForwardingCall; +import io.grpc.ClientInterceptors.CheckedForwardingClientCall; import io.grpc.Metadata; import io.grpc.MethodDescriptor; @@ -64,11 +64,11 @@ public class ClientAuthInterceptor implements ClientInterceptor { } @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall(MethodDescriptor method, Channel next) { // TODO(ejona86): If the call fails for Auth reasons, this does not properly propagate info that // would be in WWW-Authenticate, because it does not yet have access to the header. - return new CheckedForwardingCall(next.newCall(method)) { + return new CheckedForwardingClientCall(next.newCall(method)) { @Override protected void checkedStart(Listener responseListener, Metadata.Headers headers) throws Exception { diff --git a/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java b/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java index 7578f3fe1f..8fe7f84c82 100644 --- a/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java +++ b/auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java @@ -44,8 +44,8 @@ import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Multimaps; -import io.grpc.Call; import io.grpc.Channel; +import io.grpc.ClientCall; import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.Status; @@ -82,13 +82,13 @@ public class ClientAuthInterceptorTests { MethodDescriptor descriptor; @Mock - Call.Listener listener; + ClientCall.Listener listener; @Mock Channel channel; @Mock - Call call; + ClientCall call; ClientAuthInterceptor interceptor; @@ -109,7 +109,7 @@ public class ClientAuthInterceptorTests { values.put("Extra-Authorization", "token3"); values.put("Extra-Authorization", "token4"); when(credentials.getRequestMetadata()).thenReturn(Multimaps.asMap(values)); - Call interceptedCall = interceptor.interceptCall(descriptor, channel); + ClientCall interceptedCall = interceptor.interceptCall(descriptor, channel); Metadata.Headers headers = new Metadata.Headers(); interceptedCall.start(listener, headers); verify(call).start(listener, headers); @@ -125,7 +125,7 @@ public class ClientAuthInterceptorTests { @Test public void testCredentialsThrows() throws IOException { when(credentials.getRequestMetadata()).thenThrow(new IOException("Broken")); - Call interceptedCall = interceptor.interceptCall(descriptor, channel); + ClientCall interceptedCall = interceptor.interceptCall(descriptor, channel); Metadata.Headers headers = new Metadata.Headers(); interceptedCall.start(listener, headers); ArgumentCaptor statusCaptor = ArgumentCaptor.forClass(Status.class); @@ -146,7 +146,7 @@ public class ClientAuthInterceptorTests { } }; interceptor = new ClientAuthInterceptor(oAuth2Credentials, Executors.newSingleThreadExecutor()); - Call interceptedCall = interceptor.interceptCall(descriptor, channel); + ClientCall interceptedCall = interceptor.interceptCall(descriptor, channel); Metadata.Headers headers = new Metadata.Headers(); interceptedCall.start(listener, headers); verify(call).start(listener, headers); diff --git a/benchmarks/src/generated/main/io/grpc/testing/TestServiceGrpc.java b/benchmarks/src/generated/main/io/grpc/testing/TestServiceGrpc.java index 5cdb65b42b..bacb532208 100644 --- a/benchmarks/src/generated/main/io/grpc/testing/TestServiceGrpc.java +++ b/benchmarks/src/generated/main/io/grpc/testing/TestServiceGrpc.java @@ -1,13 +1,13 @@ package io.grpc.testing; -import static io.grpc.stub.Calls.createMethodDescriptor; -import static io.grpc.stub.Calls.asyncUnaryCall; -import static io.grpc.stub.Calls.asyncServerStreamingCall; -import static io.grpc.stub.Calls.asyncClientStreamingCall; -import static io.grpc.stub.Calls.duplexStreamingCall; -import static io.grpc.stub.Calls.blockingUnaryCall; -import static io.grpc.stub.Calls.blockingServerStreamingCall; -import static io.grpc.stub.Calls.unaryFutureCall; +import static io.grpc.stub.ClientCalls.createMethodDescriptor; +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.duplexStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.unaryFutureCall; import static io.grpc.stub.ServerCalls.createMethodDefinition; import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall; import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall; diff --git a/benchmarks/src/generated/main/io/grpc/testing/WorkerGrpc.java b/benchmarks/src/generated/main/io/grpc/testing/WorkerGrpc.java index 7d6e703d0f..c1ee87e5ac 100644 --- a/benchmarks/src/generated/main/io/grpc/testing/WorkerGrpc.java +++ b/benchmarks/src/generated/main/io/grpc/testing/WorkerGrpc.java @@ -1,13 +1,13 @@ package io.grpc.testing; -import static io.grpc.stub.Calls.createMethodDescriptor; -import static io.grpc.stub.Calls.asyncUnaryCall; -import static io.grpc.stub.Calls.asyncServerStreamingCall; -import static io.grpc.stub.Calls.asyncClientStreamingCall; -import static io.grpc.stub.Calls.duplexStreamingCall; -import static io.grpc.stub.Calls.blockingUnaryCall; -import static io.grpc.stub.Calls.blockingServerStreamingCall; -import static io.grpc.stub.Calls.unaryFutureCall; +import static io.grpc.stub.ClientCalls.createMethodDescriptor; +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.duplexStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.unaryFutureCall; import static io.grpc.stub.ServerCalls.createMethodDefinition; import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall; import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall; diff --git a/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/AbstractBenchmark.java b/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/AbstractBenchmark.java index 677e90f2a5..c816beb07e 100644 --- a/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/AbstractBenchmark.java +++ b/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/AbstractBenchmark.java @@ -2,8 +2,8 @@ package io.grpc.benchmarks.netty; import com.google.common.util.concurrent.MoreExecutors; -import io.grpc.Call; import io.grpc.ChannelImpl; +import io.grpc.ClientCall; import io.grpc.DeferredInputStream; import io.grpc.KnownLength; import io.grpc.Marshaller; @@ -15,7 +15,7 @@ import io.grpc.ServerCallHandler; import io.grpc.ServerImpl; import io.grpc.ServerServiceDefinition; import io.grpc.Status; -import io.grpc.stub.Calls; +import io.grpc.stub.ClientCalls; import io.grpc.stub.StreamObserver; import io.grpc.transport.netty.NegotiationType; import io.grpc.transport.netty.NettyChannelBuilder; @@ -326,7 +326,7 @@ public abstract class AbstractBenchmark { public void onCompleted() { if (!done.get()) { ByteBuf slice = request.slice(); - Calls.asyncUnaryCall(channel.newCall(unaryMethod), slice, this); + ClientCalls.asyncUnaryCall(channel.newCall(unaryMethod), slice, this); } } }; @@ -346,10 +346,10 @@ public abstract class AbstractBenchmark { final long counterDelta) { for (final ChannelImpl channel : channels) { for (int i = 0; i < callsPerChannel; i++) { - final Call streamingCall = channel.newCall(pingPongMethod); + final ClientCall streamingCall = channel.newCall(pingPongMethod); final AtomicReference> requestObserverRef = new AtomicReference>(); - StreamObserver requestObserver = Calls.duplexStreamingCall(streamingCall, + StreamObserver requestObserver = ClientCalls.duplexStreamingCall(streamingCall, new StreamObserver() { @Override public void onValue(ByteBuf value) { @@ -389,10 +389,10 @@ public abstract class AbstractBenchmark { final long counterDelta) { for (final ChannelImpl channel : channels) { for (int i = 0; i < callsPerChannel; i++) { - final Call streamingCall = channel.newCall(flowControlledStreaming); + final ClientCall streamingCall = channel.newCall(flowControlledStreaming); final AtomicReference> requestObserverRef = new AtomicReference>(); - StreamObserver requestObserver = Calls.duplexStreamingCall(streamingCall, + StreamObserver requestObserver = ClientCalls.duplexStreamingCall(streamingCall, new StreamObserver() { @Override public void onValue(ByteBuf value) { diff --git a/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/SingleThreadBlockingQpsBenchmark.java b/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/SingleThreadBlockingQpsBenchmark.java index b4982106de..6b155af718 100644 --- a/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/SingleThreadBlockingQpsBenchmark.java +++ b/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/SingleThreadBlockingQpsBenchmark.java @@ -1,6 +1,6 @@ package io.grpc.benchmarks.netty; -import io.grpc.stub.Calls; +import io.grpc.stub.ClientCalls; import io.netty.buffer.Unpooled; import org.openjdk.jmh.annotations.Benchmark; @@ -50,7 +50,7 @@ public class SingleThreadBlockingQpsBenchmark extends AbstractBenchmark { */ @Benchmark public void blockingUnary() throws Exception { - Calls.blockingUnaryCall(channels[0].newCall(unaryMethod), Unpooled.EMPTY_BUFFER); + ClientCalls.blockingUnaryCall(channels[0].newCall(unaryMethod), Unpooled.EMPTY_BUFFER); } /** diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp index 1700385f23..b8414bd225 100644 --- a/compiler/src/java_plugin/cpp/java_generator.cpp +++ b/compiler/src/java_plugin/cpp/java_generator.cpp @@ -618,21 +618,21 @@ static void PrintService(const ServiceDescriptor* service, void PrintImports(Printer* p, bool generate_nano) { p->Print( "import static " - "io.grpc.stub.Calls.createMethodDescriptor;\n" + "io.grpc.stub.ClientCalls.createMethodDescriptor;\n" "import static " - "io.grpc.stub.Calls.asyncUnaryCall;\n" + "io.grpc.stub.ClientCalls.asyncUnaryCall;\n" "import static " - "io.grpc.stub.Calls.asyncServerStreamingCall;\n" + "io.grpc.stub.ClientCalls.asyncServerStreamingCall;\n" "import static " - "io.grpc.stub.Calls.asyncClientStreamingCall;\n" + "io.grpc.stub.ClientCalls.asyncClientStreamingCall;\n" "import static " - "io.grpc.stub.Calls.duplexStreamingCall;\n" + "io.grpc.stub.ClientCalls.duplexStreamingCall;\n" "import static " - "io.grpc.stub.Calls.blockingUnaryCall;\n" + "io.grpc.stub.ClientCalls.blockingUnaryCall;\n" "import static " - "io.grpc.stub.Calls.blockingServerStreamingCall;\n" + "io.grpc.stub.ClientCalls.blockingServerStreamingCall;\n" "import static " - "io.grpc.stub.Calls.unaryFutureCall;\n" + "io.grpc.stub.ClientCalls.unaryFutureCall;\n" "import static " "io.grpc.stub.ServerCalls.createMethodDefinition;\n" "import static " diff --git a/compiler/src/test/golden/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt index 081ef00ccf..e2df739410 100644 --- a/compiler/src/test/golden/TestService.java.txt +++ b/compiler/src/test/golden/TestService.java.txt @@ -1,13 +1,13 @@ package io.grpc.testing.integration; -import static io.grpc.stub.Calls.createMethodDescriptor; -import static io.grpc.stub.Calls.asyncUnaryCall; -import static io.grpc.stub.Calls.asyncServerStreamingCall; -import static io.grpc.stub.Calls.asyncClientStreamingCall; -import static io.grpc.stub.Calls.duplexStreamingCall; -import static io.grpc.stub.Calls.blockingUnaryCall; -import static io.grpc.stub.Calls.blockingServerStreamingCall; -import static io.grpc.stub.Calls.unaryFutureCall; +import static io.grpc.stub.ClientCalls.createMethodDescriptor; +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.duplexStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.unaryFutureCall; import static io.grpc.stub.ServerCalls.createMethodDefinition; import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall; import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall; diff --git a/compiler/src/test/golden/TestServiceNano.java.txt b/compiler/src/test/golden/TestServiceNano.java.txt index 464e992b9e..8e280264f9 100644 --- a/compiler/src/test/golden/TestServiceNano.java.txt +++ b/compiler/src/test/golden/TestServiceNano.java.txt @@ -1,13 +1,13 @@ package io.grpc.testing.integration; -import static io.grpc.stub.Calls.createMethodDescriptor; -import static io.grpc.stub.Calls.asyncUnaryCall; -import static io.grpc.stub.Calls.asyncServerStreamingCall; -import static io.grpc.stub.Calls.asyncClientStreamingCall; -import static io.grpc.stub.Calls.duplexStreamingCall; -import static io.grpc.stub.Calls.blockingUnaryCall; -import static io.grpc.stub.Calls.blockingServerStreamingCall; -import static io.grpc.stub.Calls.unaryFutureCall; +import static io.grpc.stub.ClientCalls.createMethodDescriptor; +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.duplexStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.unaryFutureCall; import static io.grpc.stub.ServerCalls.createMethodDefinition; import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall; import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall; diff --git a/core/src/main/java/io/grpc/Channel.java b/core/src/main/java/io/grpc/Channel.java index af0e5ae793..01094a114d 100644 --- a/core/src/main/java/io/grpc/Channel.java +++ b/core/src/main/java/io/grpc/Channel.java @@ -35,8 +35,8 @@ import javax.annotation.concurrent.ThreadSafe; /** * A Channel provides an abstraction over the transport layer that is designed to be consumed - * by stub implementations. Channel and its associated types {@link Call} and - * {@link Call.Listener} exchange parsed request and response objects whereas the + * by stub implementations. Channel and its associated types {@link ClientCall} and + * {@link ClientCall.Listener} exchange parsed request and response objects whereas the * transport layer only works with serialized data. * *

Applications can add common cross-cutting behaviors to stubs by decorating Channel @@ -48,15 +48,15 @@ import javax.annotation.concurrent.ThreadSafe; public abstract class Channel { /** - * Create a {@link Call} to the remote operation specified by the given - * {@link MethodDescriptor}. The returned {@link Call} does not trigger any remote - * behavior until {@link Call#start(Call.Listener, Metadata.Headers)} is + * Create a {@link ClientCall} to the remote operation specified by the given + * {@link MethodDescriptor}. The returned {@link ClientCall} does not trigger any remote + * behavior until {@link ClientCall#start(ClientCall.Listener, Metadata.Headers)} is * invoked. * * @param methodDescriptor describes the name and parameter types of the operation to call. - * @return a {@link Call} bound to the specified method. + * @return a {@link ClientCall} bound to the specified method. * */ - public abstract Call newCall( + public abstract ClientCall newCall( MethodDescriptor methodDescriptor); } diff --git a/core/src/main/java/io/grpc/ChannelImpl.java b/core/src/main/java/io/grpc/ChannelImpl.java index 6726cc31cf..f734ec9511 100644 --- a/core/src/main/java/io/grpc/ChannelImpl.java +++ b/core/src/main/java/io/grpc/ChannelImpl.java @@ -67,8 +67,8 @@ public final class ChannelImpl extends Channel { @Override public void request(int numMessages) {} /** - * Always returns {@code false}, since this is only used when the startup of the {@link Call} - * fails (i.e. the {@link Call} is closed). + * Always returns {@code false}, since this is only used when the startup of the {@link + * ClientCall} fails (i.e. the {@link ClientCall} is closed). */ @Override public boolean isReady() { return false; @@ -179,7 +179,7 @@ public final class ChannelImpl extends Channel { * Creates a new outgoing call on the channel. */ @Override - public Call newCall(MethodDescriptor method) { + public ClientCall newCall(MethodDescriptor method) { return new CallImpl(method, new SerializingExecutor(executor)); } @@ -243,7 +243,7 @@ public final class ChannelImpl extends Channel { } } - private class CallImpl extends Call { + private class CallImpl extends ClientCall { private final MethodDescriptor method; private final SerializingExecutor callExecutor; private final boolean unaryRequest; diff --git a/core/src/main/java/io/grpc/Call.java b/core/src/main/java/io/grpc/ClientCall.java similarity index 90% rename from core/src/main/java/io/grpc/Call.java rename to core/src/main/java/io/grpc/ClientCall.java index 29ff35b1bc..6395e05f1b 100644 --- a/core/src/main/java/io/grpc/Call.java +++ b/core/src/main/java/io/grpc/ClientCall.java @@ -53,7 +53,7 @@ package io.grpc; * @param type of message sent one or more times to the server. * @param type of message received one or more times from the server. */ -public abstract class Call { +public abstract class ClientCall { /** * Callbacks for receiving metadata, response messages and completion status from the server. * @@ -80,10 +80,10 @@ public abstract class Call { public abstract void onPayload(T payload); /** - * The Call has been closed. No further sending or receiving can occur. If {@code status} is - * not equal to {@link Status#OK}, then the call failed. An additional block of trailer metadata - * may be received at the end of the call from the server. An empty {@link Metadata} object is - * passed if no trailers are received. + * The ClientCall has been closed. No further sending or receiving can occur. If {@code status} + * is not equal to {@link Status#OK}, then the call failed. An additional block of trailer + * metadata may be received at the end of the call from the server. An empty {@link Metadata} + * object is passed if no trailers are received. * * @param status the result of the remote call. * @param trailers metadata provided at call completion. @@ -91,10 +91,10 @@ public abstract class Call { public abstract void onClose(Status status, Metadata.Trailers trailers); /** - * This indicates that the Call is now capable of sending additional messages (via + * This indicates that the ClientCall is now capable of sending additional messages (via * {@link #sendPayload}) without requiring excessive buffering internally. This event is * just a suggestion and the application is free to ignore it, however doing so may - * result in excessive buffering within the Call. + * result in excessive buffering within the ClientCall. */ public void onReady() {} } @@ -125,7 +125,7 @@ public abstract class Call { public abstract void request(int numMessages); /** - * Prevent any further processing for this Call. No further messages may be sent or will be + * Prevent any further processing for this ClientCall. No further messages may be sent or will be * received. The server is informed of cancellations, but may not stop processing the call. * Cancellation is permitted even if previously {@code cancel()}ed or {@link #halfClose}d. */ diff --git a/core/src/main/java/io/grpc/ClientInterceptor.java b/core/src/main/java/io/grpc/ClientInterceptor.java index fb173afaf3..7d51f4d042 100644 --- a/core/src/main/java/io/grpc/ClientInterceptor.java +++ b/core/src/main/java/io/grpc/ClientInterceptor.java @@ -47,7 +47,7 @@ import javax.annotation.concurrent.ThreadSafe; @ThreadSafe public interface ClientInterceptor { /** - * Intercept {@link Call} creation by the {@code next} {@link Channel}. + * Intercept {@link ClientCall} creation by the {@code next} {@link Channel}. * *

Many variations of interception are possible. Complex implementations may return a wrapper * around the result of {@code next.newCall()}, whereas a simpler implementation may just modify @@ -57,7 +57,7 @@ public interface ClientInterceptor { * @param next the channel which is being intercepted. * @return the call object for the remote operation, never {@code null}. */ - Call interceptCall( + ClientCall interceptCall( MethodDescriptor method, Channel next); } diff --git a/core/src/main/java/io/grpc/ClientInterceptors.java b/core/src/main/java/io/grpc/ClientInterceptors.java index 4c4fc342ab..57b19c6f93 100644 --- a/core/src/main/java/io/grpc/ClientInterceptors.java +++ b/core/src/main/java/io/grpc/ClientInterceptors.java @@ -34,8 +34,8 @@ package io.grpc; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import io.grpc.ForwardingCall.SimpleForwardingCall; -import io.grpc.ForwardingCallListener.SimpleForwardingCallListener; +import io.grpc.ForwardingClientCall.SimpleForwardingClientCall; +import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; import java.util.Arrays; import java.util.Iterator; @@ -87,7 +87,7 @@ public class ClientInterceptors { } @Override - public Call newCall(MethodDescriptor method) { + public ClientCall newCall(MethodDescriptor method) { return new ProcessInterceptorChannel(channel, interceptors).newCall(method); } } @@ -102,7 +102,7 @@ public class ClientInterceptors { } @Override - public Call newCall(MethodDescriptor method) { + public ClientCall newCall(MethodDescriptor method) { if (interceptors != null && interceptors.hasNext()) { return interceptors.next().interceptCall(method, this); } else { @@ -116,18 +116,19 @@ public class ClientInterceptors { } /** - * A {@link Call} which forwards all of it's methods to another {@link Call}. + * A {@link ClientCall} which forwards all of it's methods to another {@link ClientCall}. * - * @deprecated Use {@link SimpleForwardingCall}. + * @deprecated Use {@link SimpleForwardingClientCall}. */ @Deprecated - public static class ForwardingCall extends SimpleForwardingCall { - public ForwardingCall(Call delegate) { + public static class ForwardingClientCall + extends SimpleForwardingClientCall { + public ForwardingClientCall(ClientCall delegate) { super(delegate); } } - private static final Call NOOP_CALL = new Call() { + private static final ClientCall NOOP_CALL = new ClientCall() { @Override public void start(Listener responseListener, Metadata.Headers headers) {} @@ -144,8 +145,8 @@ public class ClientInterceptors { public void sendPayload(Object payload) {} /** - * Always returns {@code false}, since this is only used when the startup of the {@link Call} - * fails (i.e. the {@link Call} is closed). + * Always returns {@code false}, since this is only used when the startup of the {@link + * ClientCall} fails (i.e. the {@link ClientCall} is closed). */ @Override public boolean isReady() { @@ -154,36 +155,38 @@ public class ClientInterceptors { }; /** - * A {@link io.grpc.ForwardingCall} that delivers exceptions from its start logic to the call - * listener. + * A {@link io.grpc.ForwardingClientCall} that delivers exceptions from its start logic to the + * call listener. * - *

{@link Call#start(Call.Listener, Metadata.Headers)} should not throw any exception other - * than those caused by misuse, e.g., {@link IllegalStateException}. {@code - * CheckedForwardingCall} provides {@code checkedStart()} in which throwing exceptions is allowed. + *

{@link ClientCall#start(ClientCall.Listener, Metadata.Headers)} should not throw any + * exception other than those caused by misuse, e.g., {@link IllegalStateException}. {@code + * CheckedForwardingClientCall} provides {@code checkedStart()} in which throwing exceptions is + * allowed. */ - public abstract static class CheckedForwardingCall - extends io.grpc.ForwardingCall { + public abstract static class CheckedForwardingClientCall + extends io.grpc.ForwardingClientCall { - private Call delegate; + private ClientCall delegate; /** * Subclasses implement the start logic here that would normally belong to {@code start()}. * *

Implementation should call {@code this.delegate().start()} in the normal path. Exceptions * may safely be thrown prior to calling {@code this.delegate().start()}. Such exceptions will - * be handled by {@code CheckedForwardingCall} and be delivered to {@code responseListener}. - * Exceptions must not be thrown after calling {@code this.delegate().start()}, as this - * can result in {@link Call.Listener#onClose} being called multiple times. + * be handled by {@code CheckedForwardingClientCall} and be delivered to {@code + * responseListener}. Exceptions must not be thrown after calling {@code + * this.delegate().start()}, as this can result in {@link ClientCall.Listener#onClose} being + * called multiple times. */ protected abstract void checkedStart(Listener responseListener, Metadata.Headers headers) throws Exception; - protected CheckedForwardingCall(Call delegate) { + protected CheckedForwardingClientCall(ClientCall delegate) { this.delegate = delegate; } @Override - protected final Call delegate() { + protected final ClientCall delegate() { return delegate; } @@ -198,22 +201,22 @@ public class ClientInterceptors { // IllegalStateException because delegate().start() was not called. We switch the delegate // to a NO-OP one to prevent the IllegalStateException. The user will finally get notified // about the error through the listener. - delegate = (Call) NOOP_CALL; + delegate = (ClientCall) NOOP_CALL; responseListener.onClose(Status.fromThrowable(e), new Metadata.Trailers()); } } } /** - * A {@link Call.Listener} which forwards all of its methods to another - * {@link Call.Listener}. + * A {@link ClientCall.Listener} which forwards all of its methods to another + * {@link ClientCall.Listener}. * - * @deprecated Use {@link SimpleForwardingCallListener}. + * @deprecated Use {@link SimpleForwardingClientCallListener}. */ @Deprecated - public static class ForwardingListener extends SimpleForwardingCallListener { + public static class ForwardingListener extends SimpleForwardingClientCallListener { - public ForwardingListener(Call.Listener delegate) { + public ForwardingListener(ClientCall.Listener delegate) { super(delegate); } } diff --git a/core/src/main/java/io/grpc/ForwardingCall.java b/core/src/main/java/io/grpc/ForwardingClientCall.java similarity index 75% rename from core/src/main/java/io/grpc/ForwardingCall.java rename to core/src/main/java/io/grpc/ForwardingClientCall.java index fe0e0e505c..39dbc8d0c8 100644 --- a/core/src/main/java/io/grpc/ForwardingCall.java +++ b/core/src/main/java/io/grpc/ForwardingClientCall.java @@ -32,13 +32,13 @@ package io.grpc; /** - * A {@link Call} which forwards all of it's methods to another {@link Call}. + * A {@link ClientCall} which forwards all of it's methods to another {@link ClientCall}. */ -public abstract class ForwardingCall extends Call { +public abstract class ForwardingClientCall extends ClientCall { /** - * Returns the delegated {@code Call}. + * Returns the delegated {@code ClientCall}. */ - protected abstract Call delegate(); + protected abstract ClientCall delegate(); @Override public void start(Listener responseListener, Metadata.Headers headers) { @@ -71,19 +71,19 @@ public abstract class ForwardingCall extends Call { } /** - * A simplified version of {@link ForwardingCall} where subclasses can pass in a {@link Call} as - * the delegate. + * A simplified version of {@link ForwardingClientCall} where subclasses can pass in a {@link + * ClientCall} as the delegate. */ - public abstract static class SimpleForwardingCall - extends ForwardingCall { - private final Call delegate; + public abstract static class SimpleForwardingClientCall + extends ForwardingClientCall { + private final ClientCall delegate; - protected SimpleForwardingCall(Call delegate) { + protected SimpleForwardingClientCall(ClientCall delegate) { this.delegate = delegate; } @Override - protected Call delegate() { + protected ClientCall delegate() { return delegate; } } diff --git a/core/src/main/java/io/grpc/ForwardingCallListener.java b/core/src/main/java/io/grpc/ForwardingClientCallListener.java similarity index 72% rename from core/src/main/java/io/grpc/ForwardingCallListener.java rename to core/src/main/java/io/grpc/ForwardingClientCallListener.java index 640bdae9f2..b7da41fd45 100644 --- a/core/src/main/java/io/grpc/ForwardingCallListener.java +++ b/core/src/main/java/io/grpc/ForwardingClientCallListener.java @@ -32,13 +32,14 @@ package io.grpc; /** - * A {@link Call.Listener} which forwards all of its methods to another {@link Call.Listener}. + * A {@link ClientCall.Listener} which forwards all of its methods to another {@link + * ClientCall.Listener}. */ -public abstract class ForwardingCallListener extends Call.Listener { +public abstract class ForwardingClientCallListener extends ClientCall.Listener { /** - * Returns the delegated {@code Call.Listener}. + * Returns the delegated {@code ClientCall.Listener}. */ - protected abstract Call.Listener delegate(); + protected abstract ClientCall.Listener delegate(); @Override public void onHeaders(Metadata.Headers headers) { @@ -61,20 +62,20 @@ public abstract class ForwardingCallListener extends Call.Listener } /** - * A simplified version of {@link ForwardingCallListener} where subclasses can pass in a {@link - * Call.Listener} as the delegate. + * A simplified version of {@link ForwardingClientCallListener} where subclasses can pass in a + * {@link ClientCall.Listener} as the delegate. */ - public abstract static class SimpleForwardingCallListener - extends ForwardingCallListener { + public abstract static class SimpleForwardingClientCallListener + extends ForwardingClientCallListener { - private final Call.Listener delegate; + private final ClientCall.Listener delegate; - protected SimpleForwardingCallListener(Call.Listener delegate) { + protected SimpleForwardingClientCallListener(ClientCall.Listener delegate) { this.delegate = delegate; } @Override - protected Call.Listener delegate() { + protected ClientCall.Listener delegate() { return delegate; } } diff --git a/core/src/main/java/io/grpc/MethodType.java b/core/src/main/java/io/grpc/MethodType.java index 0f08c1c086..e51ad421aa 100644 --- a/core/src/main/java/io/grpc/MethodType.java +++ b/core/src/main/java/io/grpc/MethodType.java @@ -63,8 +63,8 @@ public enum MethodType { /** * Returns {@code true} if the client will immediately send one request message to the server - * after calling {@link Call#start(io.grpc.Call.Listener, io.grpc.Metadata.Headers)} and then - * immediately half-close the stream by calling {@link io.grpc.Call#halfClose()}. + * after calling {@link ClientCall#start(io.grpc.ClientCall.Listener, io.grpc.Metadata.Headers)} + * and then immediately half-close the stream by calling {@link io.grpc.ClientCall#halfClose()}. */ public final boolean clientSendsOneMessage() { return this == UNARY || this == SERVER_STREAMING; diff --git a/core/src/test/java/io/grpc/ClientInterceptorsTest.java b/core/src/test/java/io/grpc/ClientInterceptorsTest.java index 4daecb1d6e..9c6203c93d 100644 --- a/core/src/test/java/io/grpc/ClientInterceptorsTest.java +++ b/core/src/test/java/io/grpc/ClientInterceptorsTest.java @@ -46,9 +46,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -import io.grpc.ClientInterceptors.CheckedForwardingCall; -import io.grpc.ForwardingCall.SimpleForwardingCall; -import io.grpc.ForwardingCallListener.SimpleForwardingCallListener; +import io.grpc.ClientInterceptors.CheckedForwardingClientCall; +import io.grpc.ForwardingClientCall.SimpleForwardingClientCall; +import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; import org.junit.Before; import org.junit.Test; @@ -73,7 +73,7 @@ public class ClientInterceptorsTest { private Channel channel; @Mock - private Call call; + private ClientCall call; @Mock private MethodDescriptor method; @@ -89,7 +89,8 @@ public class ClientInterceptorsTest { Answer checkStartCalled = new Answer() { @Override public Void answer(InvocationOnMock invocation) { - verify(call).start(Mockito.>any(), Mockito.any()); + verify(call).start(Mockito.>any(), + Mockito.any()); return null; } }; @@ -138,7 +139,8 @@ public class ClientInterceptorsTest { public void callNextTwice() { ClientInterceptor interceptor = new ClientInterceptor() { @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall( + MethodDescriptor method, Channel next) { next.newCall(method); return next.newCall(method); @@ -154,14 +156,15 @@ public class ClientInterceptorsTest { channel = new Channel() { @SuppressWarnings("unchecked") @Override - public Call newCall(MethodDescriptor method) { + public ClientCall newCall(MethodDescriptor method) { order.add("channel"); - return (Call) call; + return (ClientCall) call; } }; ClientInterceptor interceptor1 = new ClientInterceptor() { @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall( + MethodDescriptor method, Channel next) { order.add("i1"); return next.newCall(method); @@ -169,7 +172,8 @@ public class ClientInterceptorsTest { }; ClientInterceptor interceptor2 = new ClientInterceptor() { @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall( + MethodDescriptor method, Channel next) { order.add("i2"); return next.newCall(method); @@ -185,12 +189,13 @@ public class ClientInterceptorsTest { final Metadata.Key credKey = Metadata.Key.of("Cred", Metadata.ASCII_STRING_MARSHALLER); ClientInterceptor interceptor = new ClientInterceptor() { @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall( + MethodDescriptor method, Channel next) { - Call call = next.newCall(method); - return new SimpleForwardingCall(call) { + ClientCall call = next.newCall(method); + return new SimpleForwardingClientCall(call) { @Override - public void start(Call.Listener responseListener, Metadata.Headers headers) { + public void start(ClientCall.Listener responseListener, Metadata.Headers headers) { headers.put(credKey, "abcd"); super.start(responseListener, headers); } @@ -199,8 +204,8 @@ public class ClientInterceptorsTest { }; Channel intercepted = ClientInterceptors.intercept(channel, interceptor); @SuppressWarnings("unchecked") - Call.Listener listener = mock(Call.Listener.class); - Call interceptedCall = intercepted.newCall(method); + ClientCall.Listener listener = mock(ClientCall.Listener.class); + ClientCall interceptedCall = intercepted.newCall(method); // start() on the intercepted call will eventually reach the call created by the real channel interceptedCall.start(listener, new Metadata.Headers()); ArgumentCaptor captor = ArgumentCaptor.forClass(Metadata.Headers.class); @@ -215,13 +220,14 @@ public class ClientInterceptorsTest { final List examinedHeaders = new ArrayList(); ClientInterceptor interceptor = new ClientInterceptor() { @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall( + MethodDescriptor method, Channel next) { - Call call = next.newCall(method); - return new SimpleForwardingCall(call) { + ClientCall call = next.newCall(method); + return new SimpleForwardingClientCall(call) { @Override - public void start(Call.Listener responseListener, Metadata.Headers headers) { - super.start(new SimpleForwardingCallListener(responseListener) { + public void start(ClientCall.Listener responseListener, Metadata.Headers headers) { + super.start(new SimpleForwardingClientCallListener(responseListener) { @Override public void onHeaders(Metadata.Headers headers) { examinedHeaders.add(headers); @@ -234,11 +240,11 @@ public class ClientInterceptorsTest { }; Channel intercepted = ClientInterceptors.intercept(channel, interceptor); @SuppressWarnings("unchecked") - Call.Listener listener = mock(Call.Listener.class); - Call interceptedCall = intercepted.newCall(method); + ClientCall.Listener listener = mock(ClientCall.Listener.class); + ClientCall interceptedCall = intercepted.newCall(method); interceptedCall.start(listener, new Metadata.Headers()); // Capture the underlying call listener that will receive headers from the transport. - ArgumentCaptor> captor = ArgumentCaptor.forClass(null); + ArgumentCaptor> captor = ArgumentCaptor.forClass(null); verify(call).start(captor.capture(), Mockito.any()); Metadata.Headers inboundHeaders = new Metadata.Headers(); // Simulate that a headers arrives on the underlying call listener. @@ -250,17 +256,18 @@ public class ClientInterceptorsTest { public void normalCall() { ClientInterceptor interceptor = new ClientInterceptor() { @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall( + MethodDescriptor method, Channel next) { - Call call = next.newCall(method); - return new SimpleForwardingCall(call) { }; + ClientCall call = next.newCall(method); + return new SimpleForwardingClientCall(call) { }; } }; Channel intercepted = ClientInterceptors.intercept(channel, interceptor); - Call interceptedCall = intercepted.newCall(method); + ClientCall interceptedCall = intercepted.newCall(method); assertNotSame(call, interceptedCall); @SuppressWarnings("unchecked") - Call.Listener listener = mock(Call.Listener.class); + ClientCall.Listener listener = mock(ClientCall.Listener.class); Metadata.Headers headers = new Metadata.Headers(); interceptedCall.start(listener, headers); verify(call).start(same(listener), same(headers)); @@ -277,12 +284,13 @@ public class ClientInterceptorsTest { final Exception error = new Exception("emulated error"); ClientInterceptor interceptor = new ClientInterceptor() { @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall( + MethodDescriptor method, Channel next) { - Call call = next.newCall(method); - return new CheckedForwardingCall(call) { + ClientCall call = next.newCall(method); + return new CheckedForwardingClientCall(call) { @Override - protected void checkedStart(Call.Listener responseListener, + protected void checkedStart(ClientCall.Listener responseListener, Metadata.Headers headers) throws Exception { if (this instanceof Object) { throw error; @@ -294,8 +302,8 @@ public class ClientInterceptorsTest { }; Channel intercepted = ClientInterceptors.intercept(channel, interceptor); @SuppressWarnings("unchecked") - Call.Listener listener = mock(Call.Listener.class); - Call interceptedCall = intercepted.newCall(method); + ClientCall.Listener listener = mock(ClientCall.Listener.class); + ClientCall interceptedCall = intercepted.newCall(method); assertNotSame(call, interceptedCall); interceptedCall.start(listener, new Metadata.Headers()); interceptedCall.sendPayload("request"); @@ -309,7 +317,7 @@ public class ClientInterceptorsTest { private static class NoopInterceptor implements ClientInterceptor { @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall(MethodDescriptor method, Channel next) { return next.newCall(method); } diff --git a/examples/src/generated/main/io/grpc/examples/helloworld/GreeterGrpc.java b/examples/src/generated/main/io/grpc/examples/helloworld/GreeterGrpc.java index 2a0bf8872c..5caaea0d05 100644 --- a/examples/src/generated/main/io/grpc/examples/helloworld/GreeterGrpc.java +++ b/examples/src/generated/main/io/grpc/examples/helloworld/GreeterGrpc.java @@ -1,13 +1,13 @@ package io.grpc.examples.helloworld; -import static io.grpc.stub.Calls.createMethodDescriptor; -import static io.grpc.stub.Calls.asyncUnaryCall; -import static io.grpc.stub.Calls.asyncServerStreamingCall; -import static io.grpc.stub.Calls.asyncClientStreamingCall; -import static io.grpc.stub.Calls.duplexStreamingCall; -import static io.grpc.stub.Calls.blockingUnaryCall; -import static io.grpc.stub.Calls.blockingServerStreamingCall; -import static io.grpc.stub.Calls.unaryFutureCall; +import static io.grpc.stub.ClientCalls.createMethodDescriptor; +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.duplexStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.unaryFutureCall; import static io.grpc.stub.ServerCalls.createMethodDefinition; import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall; import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall; diff --git a/examples/src/generated/main/io/grpc/examples/routeguide/RouteGuideGrpc.java b/examples/src/generated/main/io/grpc/examples/routeguide/RouteGuideGrpc.java index 3d580ae42c..3acc7d3085 100644 --- a/examples/src/generated/main/io/grpc/examples/routeguide/RouteGuideGrpc.java +++ b/examples/src/generated/main/io/grpc/examples/routeguide/RouteGuideGrpc.java @@ -1,13 +1,13 @@ package io.grpc.examples.routeguide; -import static io.grpc.stub.Calls.createMethodDescriptor; -import static io.grpc.stub.Calls.asyncUnaryCall; -import static io.grpc.stub.Calls.asyncServerStreamingCall; -import static io.grpc.stub.Calls.asyncClientStreamingCall; -import static io.grpc.stub.Calls.duplexStreamingCall; -import static io.grpc.stub.Calls.blockingUnaryCall; -import static io.grpc.stub.Calls.blockingServerStreamingCall; -import static io.grpc.stub.Calls.unaryFutureCall; +import static io.grpc.stub.ClientCalls.createMethodDescriptor; +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.duplexStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.unaryFutureCall; import static io.grpc.stub.ServerCalls.createMethodDefinition; import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall; import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall; diff --git a/examples/src/main/java/io/grpc/examples/header/HeaderClientInterceptor.java b/examples/src/main/java/io/grpc/examples/header/HeaderClientInterceptor.java index f6f0a75a2e..e892e69d1b 100644 --- a/examples/src/main/java/io/grpc/examples/header/HeaderClientInterceptor.java +++ b/examples/src/main/java/io/grpc/examples/header/HeaderClientInterceptor.java @@ -31,11 +31,11 @@ package io.grpc.examples.header; -import io.grpc.Call; import io.grpc.Channel; +import io.grpc.ClientCall; import io.grpc.ClientInterceptor; -import io.grpc.ForwardingCall.SimpleForwardingCall; -import io.grpc.ForwardingCallListener.SimpleForwardingCallListener; +import io.grpc.ForwardingClientCall.SimpleForwardingClientCall; +import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; import io.grpc.Metadata; import io.grpc.MethodDescriptor; @@ -52,15 +52,15 @@ public class HeaderClientInterceptor implements ClientInterceptor { Metadata.Key.of("custom_client_header_key", Metadata.ASCII_STRING_MARSHALLER); @Override - public Call interceptCall(MethodDescriptor method, - Channel next) { - return new SimpleForwardingCall(next.newCall(method)) { + public ClientCall interceptCall(MethodDescriptor method, + Channel next) { + return new SimpleForwardingClientCall(next.newCall(method)) { @Override public void start(Listener responseListener, Metadata.Headers headers) { /* put custom header */ headers.put(customHeadKey, "customRequestValue"); - super.start(new SimpleForwardingCallListener(responseListener) { + super.start(new SimpleForwardingClientCallListener(responseListener) { @Override public void onHeaders(Metadata.Headers headers) { /** diff --git a/interop-testing/src/generated/main/io/grpc/testing/integration/TestServiceGrpc.java b/interop-testing/src/generated/main/io/grpc/testing/integration/TestServiceGrpc.java index fea6a48880..af4e136c92 100644 --- a/interop-testing/src/generated/main/io/grpc/testing/integration/TestServiceGrpc.java +++ b/interop-testing/src/generated/main/io/grpc/testing/integration/TestServiceGrpc.java @@ -1,13 +1,13 @@ package io.grpc.testing.integration; -import static io.grpc.stub.Calls.createMethodDescriptor; -import static io.grpc.stub.Calls.asyncUnaryCall; -import static io.grpc.stub.Calls.asyncServerStreamingCall; -import static io.grpc.stub.Calls.asyncClientStreamingCall; -import static io.grpc.stub.Calls.duplexStreamingCall; -import static io.grpc.stub.Calls.blockingUnaryCall; -import static io.grpc.stub.Calls.blockingServerStreamingCall; -import static io.grpc.stub.Calls.unaryFutureCall; +import static io.grpc.stub.ClientCalls.createMethodDescriptor; +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.duplexStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.unaryFutureCall; import static io.grpc.stub.ServerCalls.createMethodDefinition; import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall; import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall; diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java index 123cd80a1e..ee5094fe56 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java @@ -49,8 +49,8 @@ import com.google.protobuf.ByteString; import com.google.protobuf.EmptyProtos.Empty; import io.grpc.AbstractServerBuilder; -import io.grpc.Call; import io.grpc.ChannelImpl; +import io.grpc.ClientCall; import io.grpc.Metadata; import io.grpc.ServerImpl; import io.grpc.ServerInterceptors; @@ -435,9 +435,9 @@ public abstract class AbstractTransportTest { long start = System.nanoTime(); final ArrayBlockingQueue queue = new ArrayBlockingQueue(10); - Call call = + ClientCall call = channel.newCall(TestServiceGrpc.CONFIG.streamingOutputCall); - call.start(new Call.Listener() { + call.start(new ClientCall.Listener() { @Override public void onHeaders(Metadata.Headers headers) {} diff --git a/interop-testing/src/test/java/io/grpc/stub/StubConfigTest.java b/interop-testing/src/test/java/io/grpc/stub/StubConfigTest.java index e1d769cafb..4fc8748278 100644 --- a/interop-testing/src/test/java/io/grpc/stub/StubConfigTest.java +++ b/interop-testing/src/test/java/io/grpc/stub/StubConfigTest.java @@ -33,8 +33,8 @@ package io.grpc.stub; import static org.junit.Assert.assertEquals; -import io.grpc.Call; import io.grpc.Channel; +import io.grpc.ClientCall; import io.grpc.MethodDescriptor; import io.grpc.testing.integration.TestServiceGrpc; @@ -72,7 +72,7 @@ public class StubConfigTest { private static class FakeChannel extends Channel { @Override - public Call newCall(MethodDescriptor method) { + public ClientCall newCall(MethodDescriptor method) { return null; } } diff --git a/stub/src/main/java/io/grpc/stub/Calls.java b/stub/src/main/java/io/grpc/stub/ClientCalls.java similarity index 88% rename from stub/src/main/java/io/grpc/stub/Calls.java rename to stub/src/main/java/io/grpc/stub/ClientCalls.java index eddedf9b6d..558c80abdd 100644 --- a/stub/src/main/java/io/grpc/stub/Calls.java +++ b/stub/src/main/java/io/grpc/stub/ClientCalls.java @@ -38,7 +38,7 @@ import com.google.common.util.concurrent.ExecutionError; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.UncheckedExecutionException; -import io.grpc.Call; +import io.grpc.ClientCall; import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.Status; @@ -58,7 +58,7 @@ import javax.annotation.Nullable; * between utilities in this class and the potential signatures in a generated stub class so * that the runtime can vary behavior without requiring regeneration of the stub. */ -public class Calls { +public class ClientCalls { /** * Creates a {@link MethodDescriptor} for a given method. @@ -80,7 +80,7 @@ public class Calls { * @return a future for the single response message. */ public static ListenableFuture unaryFutureCall( - Call call, + ClientCall call, ReqT param) { GrpcFuture responseFuture = new GrpcFuture(call); asyncServerStreamingCall(call, param, new UnaryStreamToFuture(responseFuture)); @@ -124,7 +124,7 @@ public class Calls { * Executes a unary call and blocks on the response. * @return the single response message. */ - public static RespT blockingUnaryCall(Call call, ReqT param) { + public static RespT blockingUnaryCall(ClientCall call, ReqT param) { try { return getUnchecked(unaryFutureCall(call, param)); } catch (Throwable t) { @@ -137,7 +137,7 @@ public class Calls { * Executes a unary call with a response {@link StreamObserver}. */ public static void asyncUnaryCall( - Call call, + ClientCall call, ReqT param, StreamObserver observer) { asyncServerStreamingCall(call, param, observer); @@ -150,7 +150,7 @@ public class Calls { */ // TODO(louiscryan): Not clear if we want to use this idiom for 'simple' stubs. public static Iterator blockingServerStreamingCall( - Call call, ReqT param) { + ClientCall call, ReqT param) { BlockingResponseStream result = new BlockingResponseStream(call); asyncServerStreamingCall(call, param, result.listener()); return result; @@ -160,7 +160,7 @@ public class Calls { * Executes a server-streaming call with a response {@link StreamObserver}. */ public static void asyncServerStreamingCall( - Call call, + ClientCall call, ReqT param, StreamObserver responseObserver) { asyncServerStreamingCall(call, param, @@ -168,9 +168,9 @@ public class Calls { } private static void asyncServerStreamingCall( - Call call, + ClientCall call, ReqT param, - Call.Listener responseListener) { + ClientCall.Listener responseListener) { call.start(responseListener, new Metadata.Headers()); call.request(1); try { @@ -187,7 +187,7 @@ public class Calls { * @return the single response value. */ public static RespT blockingClientStreamingCall( - Call call, + ClientCall call, Iterator clientStream) { GrpcFuture responseFuture = new GrpcFuture(call); call.start(new UnaryStreamToFuture(responseFuture), new Metadata.Headers()); @@ -213,7 +213,7 @@ public class Calls { * @return request stream observer. */ public static StreamObserver asyncClientStreamingCall( - Call call, + ClientCall call, StreamObserver responseObserver) { return duplexStreamingCall(call, responseObserver); } @@ -222,7 +222,7 @@ public class Calls { * Executes a duplex-streaming call. * @return request stream observer. */ - public static StreamObserver duplexStreamingCall(Call call, + public static StreamObserver duplexStreamingCall(ClientCall call, StreamObserver responseObserver) { call.start(new StreamObserverToCallListenerAdapter(call, responseObserver), new Metadata.Headers()); @@ -231,9 +231,9 @@ public class Calls { } private static class CallToStreamObserverAdapter implements StreamObserver { - private final Call call; + private final ClientCall call; - public CallToStreamObserverAdapter(Call call) { + public CallToStreamObserverAdapter(ClientCall call) { this.call = call; } @@ -254,12 +254,13 @@ public class Calls { } } - private static class StreamObserverToCallListenerAdapter extends Call.Listener { - private final Call call; + private static class StreamObserverToCallListenerAdapter + extends ClientCall.Listener { + private final ClientCall call; private final StreamObserver observer; public StreamObserverToCallListenerAdapter( - Call call, StreamObserver observer) { + ClientCall call, StreamObserver observer) { this.call = call; this.observer = observer; } @@ -289,7 +290,7 @@ public class Calls { /** * Complete a GrpcFuture using {@link StreamObserver} events. */ - private static class UnaryStreamToFuture extends Call.Listener { + private static class UnaryStreamToFuture extends ClientCall.Listener { private final GrpcFuture responseFuture; private RespT value; @@ -327,9 +328,9 @@ public class Calls { } private static class GrpcFuture extends AbstractFuture { - private final Call call; + private final ClientCall call; - GrpcFuture(Call call) { + GrpcFuture(ClientCall call) { this.call = call; } @@ -350,26 +351,26 @@ public class Calls { } /** - * Convert events on a {@link io.grpc.Call.Listener} into a blocking + * Convert events on a {@link io.grpc.ClientCall.Listener} into a blocking * {@link Iterator}. * - *

The class is not thread-safe, but it does permit {@link Call.Listener} calls in a separate - * thread from {@code Iterator} calls. + *

The class is not thread-safe, but it does permit {@link ClientCall.Listener} calls in a + * separate thread from {@code Iterator} calls. */ - // TODO(ejona86): determine how to allow Call.cancel() in case of application error. + // TODO(ejona86): determine how to allow ClientCall.cancel() in case of application error. private static class BlockingResponseStream implements Iterator { // Due to flow control, only needs to hold up to 2 items: 1 for value, 1 for close. private final BlockingQueue buffer = new ArrayBlockingQueue(2); - private final Call.Listener listener = new QueuingListener(); - private final Call call; + private final ClientCall.Listener listener = new QueuingListener(); + private final ClientCall call; // Only accessed when iterating. private Object last; - private BlockingResponseStream(Call call) { + private BlockingResponseStream(ClientCall call) { this.call = call; } - Call.Listener listener() { + ClientCall.Listener listener() { return listener; } @@ -409,7 +410,7 @@ public class Calls { throw new UnsupportedOperationException(); } - private class QueuingListener extends Call.Listener { + private class QueuingListener extends ClientCall.Listener { private boolean done = false; @Override @@ -418,13 +419,13 @@ public class Calls { @Override public void onPayload(T value) { - Preconditions.checkState(!done, "Call already closed"); + Preconditions.checkState(!done, "ClientCall already closed"); buffer.add(value); } @Override public void onClose(Status status, Metadata.Trailers trailers) { - Preconditions.checkState(!done, "Call already closed"); + Preconditions.checkState(!done, "ClientCall already closed"); if (status.isOk()) { buffer.add(BlockingResponseStream.this); } else { diff --git a/stub/src/main/java/io/grpc/stub/MetadataUtils.java b/stub/src/main/java/io/grpc/stub/MetadataUtils.java index d6a9341fda..5dff9bc32d 100644 --- a/stub/src/main/java/io/grpc/stub/MetadataUtils.java +++ b/stub/src/main/java/io/grpc/stub/MetadataUtils.java @@ -31,11 +31,11 @@ package io.grpc.stub; -import io.grpc.Call; import io.grpc.Channel; +import io.grpc.ClientCall; import io.grpc.ClientInterceptor; -import io.grpc.ForwardingCall.SimpleForwardingCall; -import io.grpc.ForwardingCallListener.SimpleForwardingCallListener; +import io.grpc.ForwardingClientCall.SimpleForwardingClientCall; +import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.Status; @@ -71,9 +71,10 @@ public class MetadataUtils { public static ClientInterceptor newAttachHeadersInterceptor(final Metadata.Headers extraHeaders) { return new ClientInterceptor() { @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall( + MethodDescriptor method, Channel next) { - return new SimpleForwardingCall(next.newCall(method)) { + return new SimpleForwardingClientCall(next.newCall(method)) { @Override public void start(Listener responseListener, Metadata.Headers headers) { headers.merge(extraHeaders); @@ -113,14 +114,15 @@ public class MetadataUtils { final AtomicReference trailersCapture) { return new ClientInterceptor() { @Override - public Call interceptCall(MethodDescriptor method, + public ClientCall interceptCall( + MethodDescriptor method, Channel next) { - return new SimpleForwardingCall(next.newCall(method)) { + return new SimpleForwardingClientCall(next.newCall(method)) { @Override public void start(Listener responseListener, Metadata.Headers headers) { headersCapture.set(null); trailersCapture.set(null); - super.start(new SimpleForwardingCallListener(responseListener) { + super.start(new SimpleForwardingClientCallListener(responseListener) { @Override public void onHeaders(Metadata.Headers headers) { headersCapture.set(headers); diff --git a/stub/src/test/java/io/grpc/stub/CallsTest.java b/stub/src/test/java/io/grpc/stub/ClientCallsTest.java similarity index 80% rename from stub/src/test/java/io/grpc/stub/CallsTest.java rename to stub/src/test/java/io/grpc/stub/ClientCallsTest.java index fbc3ef22d7..5366a5cb4c 100644 --- a/stub/src/test/java/io/grpc/stub/CallsTest.java +++ b/stub/src/test/java/io/grpc/stub/ClientCallsTest.java @@ -38,7 +38,7 @@ import static org.mockito.Mockito.verify; import com.google.common.util.concurrent.ListenableFuture; -import io.grpc.Call; +import io.grpc.ClientCall; import io.grpc.Metadata; import io.grpc.Status; @@ -54,12 +54,12 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; /** - * Unit tests for {@link Calls}. + * Unit tests for {@link ClientCalls}. */ @RunWith(JUnit4.class) -public class CallsTest { +public class ClientCallsTest { - @Mock private Call call; + @Mock private ClientCall call; @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -67,10 +67,10 @@ public class CallsTest { @Test public void unaryFutureCallSuccess() throws Exception { Integer req = 2; - ListenableFuture future = Calls.unaryFutureCall(call, req); - ArgumentCaptor> listenerCaptor = ArgumentCaptor.forClass(null); + ListenableFuture future = ClientCalls.unaryFutureCall(call, req); + ArgumentCaptor> listenerCaptor = ArgumentCaptor.forClass(null); verify(call).start(listenerCaptor.capture(), any(Metadata.Headers.class)); - Call.Listener listener = listenerCaptor.getValue(); + ClientCall.Listener listener = listenerCaptor.getValue(); verify(call).sendPayload(req); verify(call).halfClose(); listener.onPayload("bar"); @@ -80,10 +80,10 @@ public class CallsTest { @Test public void unaryFutureCallFailed() throws Exception { Integer req = 2; - ListenableFuture future = Calls.unaryFutureCall(call, req); - ArgumentCaptor> listenerCaptor = ArgumentCaptor.forClass(null); + ListenableFuture future = ClientCalls.unaryFutureCall(call, req); + ArgumentCaptor> listenerCaptor = ArgumentCaptor.forClass(null); verify(call).start(listenerCaptor.capture(), any(Metadata.Headers.class)); - Call.Listener listener = listenerCaptor.getValue(); + ClientCall.Listener listener = listenerCaptor.getValue(); listener.onClose(Status.INVALID_ARGUMENT, new Metadata.Trailers()); try { future.get(); @@ -96,10 +96,10 @@ public class CallsTest { @Test public void unaryFutureCallCancelled() throws Exception { Integer req = 2; - ListenableFuture future = Calls.unaryFutureCall(call, req); - ArgumentCaptor> listenerCaptor = ArgumentCaptor.forClass(null); + ListenableFuture future = ClientCalls.unaryFutureCall(call, req); + ArgumentCaptor> listenerCaptor = ArgumentCaptor.forClass(null); verify(call).start(listenerCaptor.capture(), any(Metadata.Headers.class)); - Call.Listener listener = listenerCaptor.getValue(); + ClientCall.Listener listener = listenerCaptor.getValue(); future.cancel(true); verify(call).cancel(); listener.onPayload("bar");