Skip to content

Commit

Permalink
Prevent construction of container classes and reduce API
Browse files Browse the repository at this point in the history
  • Loading branch information
ejona86 committed Sep 10, 2015
1 parent e969a90 commit be0d7e9
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion auth/src/main/java/io/grpc/auth/ClientAuthInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* <p> Uses the new and simplified Google auth library:
* https://github.com/google/google-auth-library-java
*/
public class ClientAuthInterceptor implements ClientInterceptor {
public final class ClientAuthInterceptor implements ClientInterceptor {

private final Credentials credentials;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc {

private TestServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.TestService";

// Static method descriptors that strictly reflect the proto.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class WorkerGrpc {

private WorkerGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.Worker";

// Static method descriptors that strictly reflect the proto.
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/java_plugin/cpp/java_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ static void PrintService(const ServiceDescriptor* service,
"@$Generated$(\"by gRPC proto compiler\")\n"
"public class $service_class_name$ {\n\n");
p->Indent();
p->Print(
*vars,
"private $service_class_name$() {}\n\n");

p->Print(
*vars,
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/test/golden/TestService.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
@javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc {

private TestServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.TestService";

// Static method descriptors that strictly reflect the proto.
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/test/golden/TestServiceNano.java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import java.io.IOException;
@javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc {

private TestServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.TestService";

// Static method descriptors that strictly reflect the proto.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class GreeterGrpc {

private GreeterGrpc() {}

public static final String SERVICE_NAME = "helloworld.Greeter";

// Static method descriptors that strictly reflect the proto.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class RouteGuideGrpc {

private RouteGuideGrpc() {}

public static final String SERVICE_NAME = "routeguide.RouteGuide";

// Static method descriptors that strictly reflect the proto.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class ReconnectServiceGrpc {

private ReconnectServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.ReconnectService";

// Static method descriptors that strictly reflect the proto.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class TestServiceGrpc {

private TestServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.TestService";

// Static method descriptors that strictly reflect the proto.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@javax.annotation.Generated("by gRPC proto compiler")
public class UnimplementedServiceGrpc {

private UnimplementedServiceGrpc() {}

public static final String SERVICE_NAME = "grpc.testing.UnimplementedService";

// Static method descriptors that strictly reflect the proto.
Expand Down
2 changes: 2 additions & 0 deletions stub/src/main/java/io/grpc/stub/ClientCalls.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
* that the runtime can vary behavior without requiring regeneration of the stub.
*/
public class ClientCalls {
// Prevent instantiation
private ClientCalls() {}

/**
* Executes a unary call with a response {@link StreamObserver}.
Expand Down
15 changes: 9 additions & 6 deletions stub/src/main/java/io/grpc/stub/MetadataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.grpc.Channel;
import io.grpc.ClientCall;
import io.grpc.ClientInterceptor;
import io.grpc.ExperimentalApi;
import io.grpc.ForwardingClientCall.SimpleForwardingClientCall;
import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener;
import io.grpc.Metadata;
Expand All @@ -47,6 +48,8 @@
* Utility functions for binding and receiving headers.
*/
public class MetadataUtils {
// Prevent instantiation
private MetadataUtils() {}

/**
* Attaches a set of request headers to a stub.
Expand All @@ -55,11 +58,11 @@ public class MetadataUtils {
* @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.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public static <T extends AbstractStub> T attachHeaders(
@ExperimentalApi
public static <T extends AbstractStub<T>> T attachHeaders(
T stub,
final Metadata extraHeaders) {
return (T) stub.withInterceptors(newAttachHeadersInterceptor(extraHeaders));
return stub.withInterceptors(newAttachHeadersInterceptor(extraHeaders));
}

/**
Expand Down Expand Up @@ -94,12 +97,12 @@ public void start(Listener<RespT> responseListener, Metadata headers) {
* @param trailersCapture to record the last received trailers
* @return an implementation of the stub with {@code extraHeaders} bound to each call.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public static <T extends AbstractStub> T captureMetadata(
@ExperimentalApi
public static <T extends AbstractStub<T>> T captureMetadata(
T stub,
AtomicReference<Metadata> headersCapture,
AtomicReference<Metadata> trailersCapture) {
return (T) stub.withInterceptors(
return stub.withInterceptors(
newCaptureMetadataInterceptor(headersCapture, trailersCapture));
}

Expand Down

0 comments on commit be0d7e9

Please sign in to comment.