Prevent construction of container classes and reduce API

This commit is contained in:
Eric Anderson 2015-09-10 09:47:17 -07:00
parent e969a900a0
commit be0d7e911a
13 changed files with 33 additions and 7 deletions

View File

@ -58,7 +58,7 @@ import java.util.concurrent.Executor;
* <p> Uses the new and simplified Google auth library: * <p> Uses the new and simplified Google auth library:
* https://github.com/google/google-auth-library-java * https://github.com/google/google-auth-library-java
*/ */
public class ClientAuthInterceptor implements ClientInterceptor { public final class ClientAuthInterceptor implements ClientInterceptor {
private final Credentials credentials; private final Credentials credentials;

View File

@ -16,6 +16,8 @@ import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
@javax.annotation.Generated("by gRPC proto compiler") @javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc { public class TestServiceGrpc {
private TestServiceGrpc() {}
public static final String SERVICE_NAME = "grpc.testing.TestService"; public static final String SERVICE_NAME = "grpc.testing.TestService";
// Static method descriptors that strictly reflect the proto. // Static method descriptors that strictly reflect the proto.

View File

@ -16,6 +16,8 @@ import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
@javax.annotation.Generated("by gRPC proto compiler") @javax.annotation.Generated("by gRPC proto compiler")
public class WorkerGrpc { public class WorkerGrpc {
private WorkerGrpc() {}
public static final String SERVICE_NAME = "grpc.testing.Worker"; public static final String SERVICE_NAME = "grpc.testing.Worker";
// Static method descriptors that strictly reflect the proto. // Static method descriptors that strictly reflect the proto.

View File

@ -511,6 +511,9 @@ static void PrintService(const ServiceDescriptor* service,
"@$Generated$(\"by gRPC proto compiler\")\n" "@$Generated$(\"by gRPC proto compiler\")\n"
"public class $service_class_name$ {\n\n"); "public class $service_class_name$ {\n\n");
p->Indent(); p->Indent();
p->Print(
*vars,
"private $service_class_name$() {}\n\n");
p->Print( p->Print(
*vars, *vars,

View File

@ -16,6 +16,8 @@ import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
@javax.annotation.Generated("by gRPC proto compiler") @javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc { public class TestServiceGrpc {
private TestServiceGrpc() {}
public static final String SERVICE_NAME = "grpc.testing.TestService"; public static final String SERVICE_NAME = "grpc.testing.TestService";
// Static method descriptors that strictly reflect the proto. // Static method descriptors that strictly reflect the proto.

View File

@ -18,6 +18,8 @@ import java.io.IOException;
@javax.annotation.Generated("by gRPC proto compiler") @javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc { public class TestServiceGrpc {
private TestServiceGrpc() {}
public static final String SERVICE_NAME = "grpc.testing.TestService"; public static final String SERVICE_NAME = "grpc.testing.TestService";
// Static method descriptors that strictly reflect the proto. // Static method descriptors that strictly reflect the proto.

View File

@ -16,6 +16,8 @@ import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
@javax.annotation.Generated("by gRPC proto compiler") @javax.annotation.Generated("by gRPC proto compiler")
public class GreeterGrpc { public class GreeterGrpc {
private GreeterGrpc() {}
public static final String SERVICE_NAME = "helloworld.Greeter"; public static final String SERVICE_NAME = "helloworld.Greeter";
// Static method descriptors that strictly reflect the proto. // Static method descriptors that strictly reflect the proto.

View File

@ -16,6 +16,8 @@ import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
@javax.annotation.Generated("by gRPC proto compiler") @javax.annotation.Generated("by gRPC proto compiler")
public class RouteGuideGrpc { public class RouteGuideGrpc {
private RouteGuideGrpc() {}
public static final String SERVICE_NAME = "routeguide.RouteGuide"; public static final String SERVICE_NAME = "routeguide.RouteGuide";
// Static method descriptors that strictly reflect the proto. // Static method descriptors that strictly reflect the proto.

View File

@ -16,6 +16,8 @@ import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
@javax.annotation.Generated("by gRPC proto compiler") @javax.annotation.Generated("by gRPC proto compiler")
public class ReconnectServiceGrpc { public class ReconnectServiceGrpc {
private ReconnectServiceGrpc() {}
public static final String SERVICE_NAME = "grpc.testing.ReconnectService"; public static final String SERVICE_NAME = "grpc.testing.ReconnectService";
// Static method descriptors that strictly reflect the proto. // Static method descriptors that strictly reflect the proto.

View File

@ -16,6 +16,8 @@ import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
@javax.annotation.Generated("by gRPC proto compiler") @javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc { public class TestServiceGrpc {
private TestServiceGrpc() {}
public static final String SERVICE_NAME = "grpc.testing.TestService"; public static final String SERVICE_NAME = "grpc.testing.TestService";
// Static method descriptors that strictly reflect the proto. // Static method descriptors that strictly reflect the proto.

View File

@ -16,6 +16,8 @@ import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
@javax.annotation.Generated("by gRPC proto compiler") @javax.annotation.Generated("by gRPC proto compiler")
public class UnimplementedServiceGrpc { public class UnimplementedServiceGrpc {
private UnimplementedServiceGrpc() {}
public static final String SERVICE_NAME = "grpc.testing.UnimplementedService"; public static final String SERVICE_NAME = "grpc.testing.UnimplementedService";
// Static method descriptors that strictly reflect the proto. // Static method descriptors that strictly reflect the proto.

View File

@ -55,6 +55,8 @@ import javax.annotation.Nullable;
* that the runtime can vary behavior without requiring regeneration of the stub. * that the runtime can vary behavior without requiring regeneration of the stub.
*/ */
public class ClientCalls { public class ClientCalls {
// Prevent instantiation
private ClientCalls() {}
/** /**
* Executes a unary call with a response {@link StreamObserver}. * Executes a unary call with a response {@link StreamObserver}.

View File

@ -35,6 +35,7 @@ import io.grpc.CallOptions;
import io.grpc.Channel; import io.grpc.Channel;
import io.grpc.ClientCall; import io.grpc.ClientCall;
import io.grpc.ClientInterceptor; import io.grpc.ClientInterceptor;
import io.grpc.ExperimentalApi;
import io.grpc.ForwardingClientCall.SimpleForwardingClientCall; import io.grpc.ForwardingClientCall.SimpleForwardingClientCall;
import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener;
import io.grpc.Metadata; import io.grpc.Metadata;
@ -47,6 +48,8 @@ import java.util.concurrent.atomic.AtomicReference;
* Utility functions for binding and receiving headers. * Utility functions for binding and receiving headers.
*/ */
public class MetadataUtils { public class MetadataUtils {
// Prevent instantiation
private MetadataUtils() {}
/** /**
* Attaches a set of request headers to a stub. * Attaches a set of request headers to a stub.
@ -55,11 +58,11 @@ public class MetadataUtils {
* @param extraHeaders the headers to be passed by each call on the returned stub. * @param extraHeaders the headers to be passed by each call on the returned stub.
* @return an implementation of the stub with {@code extraHeaders} bound to each call. * @return an implementation of the stub with {@code extraHeaders} bound to each call.
*/ */
@SuppressWarnings({"unchecked", "rawtypes"}) @ExperimentalApi
public static <T extends AbstractStub> T attachHeaders( public static <T extends AbstractStub<T>> T attachHeaders(
T stub, T stub,
final Metadata extraHeaders) { final Metadata extraHeaders) {
return (T) stub.withInterceptors(newAttachHeadersInterceptor(extraHeaders)); return stub.withInterceptors(newAttachHeadersInterceptor(extraHeaders));
} }
/** /**
@ -94,12 +97,12 @@ public class MetadataUtils {
* @param trailersCapture to record the last received trailers * @param trailersCapture to record the last received trailers
* @return an implementation of the stub with {@code extraHeaders} bound to each call. * @return an implementation of the stub with {@code extraHeaders} bound to each call.
*/ */
@SuppressWarnings({"unchecked", "rawtypes"}) @ExperimentalApi
public static <T extends AbstractStub> T captureMetadata( public static <T extends AbstractStub<T>> T captureMetadata(
T stub, T stub,
AtomicReference<Metadata> headersCapture, AtomicReference<Metadata> headersCapture,
AtomicReference<Metadata> trailersCapture) { AtomicReference<Metadata> trailersCapture) {
return (T) stub.withInterceptors( return stub.withInterceptors(
newCaptureMetadataInterceptor(headersCapture, trailersCapture)); newCaptureMetadataInterceptor(headersCapture, trailersCapture));
} }