Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ public static ManagedChannelBuilder<?> forTarget(String target) {
String authorityOverride;


private ProxyDetector proxyDetector = ProxyDetector.DEFAULT_INSTANCE;

LoadBalancer.Factory loadBalancerFactory = DEFAULT_LOAD_BALANCER_FACTORY;

boolean fullStreamDecompression;
Expand Down Expand Up @@ -338,7 +336,7 @@ public ManagedChannel build() {
SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR),
GrpcUtil.STOPWATCH_SUPPLIER,
getEffectiveInterceptors(),
proxyDetector);
GrpcUtil.getProxyDetector());
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DnsNameResolver newNameResolver(URI targetUri, Attributes params) {
"the path component (%s) of the target (%s) must start with '/'", targetPath, targetUri);
String name = targetPath.substring(1);
return new DnsNameResolver(targetUri.getAuthority(), name, params, GrpcUtil.TIMER_SERVICE,
GrpcUtil.SHARED_CHANNEL_EXECUTOR, ProxyDetector.DEFAULT_INSTANCE);
GrpcUtil.SHARED_CHANNEL_EXECUTOR, GrpcUtil.getProxyDetector());
} else {
return null;
}
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/java/io/grpc/internal/GrpcUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -225,6 +226,33 @@ public byte[] parseAsciiString(byte[] serialized) {
*/
public static final long SERVER_KEEPALIVE_TIME_NANOS_DISABLED = Long.MAX_VALUE;

/**
* The default proxy detector.
*/
public static final ProxyDetector DEFAULT_PROXY_DETECTOR = new ProxyDetectorImpl();

/**
* A proxy detector that always claims no proxy is needed.
*/
public static final ProxyDetector NOOP_PROXY_DETECTOR = new ProxyDetector() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional:

this only appears to be used in tests. You might consider pulling this out into its own static class, putting the instance inside of it, and referencing it from tests like that.

Then the regular code won't have to initialize this anonymous class in prod code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer true because GAE+jdk7 will use this noop detector.

@Nullable
@Override
public ProxyParameters proxyFor(SocketAddress targetServerAddress) {
return null;
}
};

/**
* Returns a proxy detector appropriate for the current environment.
*/
public static ProxyDetector getProxyDetector() {
if (IS_RESTRICTED_APPENGINE) {
return NOOP_PROXY_DETECTOR;
} else {
return DEFAULT_PROXY_DETECTOR;
}
}

/**
* Maps HTTP error response status codes to transport codes, as defined in <a
* href="https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md">
Expand Down
11 changes: 0 additions & 11 deletions core/src/main/java/io/grpc/internal/ProxyDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@
* {@link java.net.SocketAddress}.
*/
public interface ProxyDetector {
ProxyDetector DEFAULT_INSTANCE = new ProxyDetectorImpl();

/** A proxy detector that always claims no proxy is needed, for unit test convenience. */
ProxyDetector NOOP_INSTANCE = new ProxyDetector() {
@Nullable
@Override
public ProxyParameters proxyFor(SocketAddress targetServerAddress) {
return null;
}
};

/**
* Given a target address, returns which proxy address should be used. If no proxy should be
* used, then return value will be null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void close(ExecutorService instance) {
private ArgumentCaptor<Status> statusCaptor;

private DnsNameResolver newResolver(String name, int port) {
return newResolver(name, port, mockResolver, ProxyDetector.NOOP_INSTANCE);
return newResolver(name, port, mockResolver, GrpcUtil.NOOP_PROXY_DETECTOR);
}

private DnsNameResolver newResolver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ public void resetConnectBackoff_noopOnIdleTransport() throws Exception {
}

private void createInternalSubchannel(SocketAddress ... addrs) {
createInternalSubChannelWithProxy(ProxyDetector.NOOP_INSTANCE, addrs);
createInternalSubChannelWithProxy(GrpcUtil.NOOP_PROXY_DETECTOR, addrs);
}

private void createInternalSubChannelWithProxy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Builder extends AbstractManagedChannelImplBuilder<Builder> {
builder, mockTransportFactory, new FakeBackoffPolicyProvider(),
oobExecutorPool, timer.getStopwatchSupplier(),
Collections.<ClientInterceptor>emptyList(),
ProxyDetector.NOOP_INSTANCE);
GrpcUtil.NOOP_PROXY_DETECTOR);
newTransports = TestUtils.captureTransports(mockTransportFactory);

for (int i = 0; i < 2; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class Builder extends AbstractManagedChannelImplBuilder<Builder> {
checkState(channel == null);
channel = new ManagedChannelImpl(
builder, mockTransportFactory, new FakeBackoffPolicyProvider(),
oobExecutorPool, timer.getStopwatchSupplier(), interceptors, ProxyDetector.NOOP_INSTANCE);
oobExecutorPool, timer.getStopwatchSupplier(), interceptors, GrpcUtil.NOOP_PROXY_DETECTOR);

if (requestConnection) {
// Force-exit the initial idle-mode
Expand Down