Skip to content

Commit 3d96c6a

Browse files
committed
Inline AbstractManagedChannelImplBuilder: move properties
1 parent cd5b9f1 commit 3d96c6a

File tree

2 files changed

+123
-171
lines changed

2 files changed

+123
-171
lines changed

core/src/main/java/io/grpc/internal/AbstractManagedChannelImplBuilder.java

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,7 @@
1616

1717
package io.grpc.internal;
1818

19-
import com.google.common.annotations.VisibleForTesting;
20-
import io.grpc.BinaryLog;
21-
import io.grpc.ClientInterceptor;
22-
import io.grpc.CompressorRegistry;
23-
import io.grpc.DecompressorRegistry;
24-
import io.grpc.InternalChannelz;
2519
import io.grpc.ManagedChannelBuilder;
26-
import io.grpc.NameResolver;
27-
import io.grpc.NameResolverRegistry;
28-
import io.grpc.ProxyDetector;
29-
import java.util.ArrayList;
30-
import java.util.List;
31-
import java.util.Map;
32-
import java.util.concurrent.Executor;
33-
import java.util.concurrent.TimeUnit;
34-
import javax.annotation.Nullable;
3520

3621
/**
3722
* Abstract base class for channel builders.
@@ -47,91 +32,4 @@ public static ManagedChannelBuilder<?> forAddress(String name, int port) {
4732
public static ManagedChannelBuilder<?> forTarget(String target) {
4833
throw new UnsupportedOperationException("Subclass failed to hide static factory");
4934
}
50-
51-
/**
52-
* An idle timeout larger than this would disable idle mode.
53-
*/
54-
@VisibleForTesting
55-
static final long IDLE_MODE_MAX_TIMEOUT_DAYS = 30;
56-
57-
/**
58-
* The default idle timeout.
59-
*/
60-
@VisibleForTesting
61-
static final long IDLE_MODE_DEFAULT_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(30);
62-
63-
/**
64-
* An idle timeout smaller than this would be capped to it.
65-
*/
66-
static final long IDLE_MODE_MIN_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(1);
67-
68-
protected static final ObjectPool<? extends Executor> DEFAULT_EXECUTOR_POOL =
69-
SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR);
70-
71-
protected static final DecompressorRegistry DEFAULT_DECOMPRESSOR_REGISTRY =
72-
DecompressorRegistry.getDefaultInstance();
73-
74-
protected static final CompressorRegistry DEFAULT_COMPRESSOR_REGISTRY =
75-
CompressorRegistry.getDefaultInstance();
76-
77-
private static final long DEFAULT_RETRY_BUFFER_SIZE_IN_BYTES = 1L << 24; // 16M
78-
private static final long DEFAULT_PER_RPC_BUFFER_LIMIT_IN_BYTES = 1L << 20; // 1M
79-
80-
ObjectPool<? extends Executor> executorPool = DEFAULT_EXECUTOR_POOL;
81-
82-
ObjectPool<? extends Executor> offloadExecutorPool = DEFAULT_EXECUTOR_POOL;
83-
84-
protected final List<ClientInterceptor> interceptors = new ArrayList<>();
85-
final NameResolverRegistry nameResolverRegistry = NameResolverRegistry.getDefaultRegistry();
86-
87-
// Access via getter, which may perform authority override as needed
88-
protected NameResolver.Factory nameResolverFactory = nameResolverRegistry.asFactory();
89-
90-
@Nullable
91-
String userAgent;
92-
93-
@VisibleForTesting
94-
@Nullable
95-
String authorityOverride;
96-
97-
String defaultLbPolicy = GrpcUtil.DEFAULT_LB_POLICY;
98-
99-
boolean fullStreamDecompression;
100-
101-
DecompressorRegistry decompressorRegistry = DEFAULT_DECOMPRESSOR_REGISTRY;
102-
103-
CompressorRegistry compressorRegistry = DEFAULT_COMPRESSOR_REGISTRY;
104-
105-
long idleTimeoutMillis = IDLE_MODE_DEFAULT_TIMEOUT_MILLIS;
106-
107-
int maxRetryAttempts = 5;
108-
int maxHedgedAttempts = 5;
109-
long retryBufferSize = DEFAULT_RETRY_BUFFER_SIZE_IN_BYTES;
110-
long perRpcBufferLimit = DEFAULT_PER_RPC_BUFFER_LIMIT_IN_BYTES;
111-
boolean retryEnabled = false; // TODO(zdapeng): default to true
112-
// Temporarily disable retry when stats or tracing is enabled to avoid breakage, until we know
113-
// what should be the desired behavior for retry + stats/tracing.
114-
// TODO(zdapeng): delete me
115-
boolean temporarilyDisableRetry;
116-
117-
InternalChannelz channelz = InternalChannelz.instance();
118-
int maxTraceEvents;
119-
120-
@Nullable
121-
Map<String, ?> defaultServiceConfig;
122-
boolean lookUpServiceConfig = true;
123-
124-
protected int maxInboundMessageSize = GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
125-
126-
@Nullable
127-
BinaryLog binlog;
128-
129-
@Nullable
130-
ProxyDetector proxyDetector;
131-
132-
protected boolean statsEnabled = true;
133-
protected boolean recordStartedRpcs = true;
134-
protected boolean recordFinishedRpcs = true;
135-
protected boolean recordRealTimeMetrics = false;
136-
protected boolean tracingEnabled = true;
13735
}

core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java

Lines changed: 123 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import io.grpc.CompressorRegistry;
2626
import io.grpc.DecompressorRegistry;
2727
import io.grpc.EquivalentAddressGroup;
28+
import io.grpc.InternalChannelz;
2829
import io.grpc.ManagedChannel;
2930
import io.grpc.ManagedChannelBuilder;
3031
import io.grpc.NameResolver;
32+
import io.grpc.NameResolverRegistry;
3133
import io.grpc.ProxyDetector;
3234
import java.lang.reflect.InvocationTargetException;
3335
import java.lang.reflect.Method;
@@ -51,77 +53,80 @@
5153
*/
5254
public final class ManagedChannelImplBuilder
5355
extends AbstractManagedChannelImplBuilder<ManagedChannelImplBuilder> {
56+
private static final Logger log = Logger.getLogger(ManagedChannelImplBuilder.class.getName());
57+
private static final String DIRECT_ADDRESS_SCHEME = "directaddress";
58+
private static final long DEFAULT_RETRY_BUFFER_SIZE_IN_BYTES = 1L << 24; // 16M
59+
private static final long DEFAULT_PER_RPC_BUFFER_LIMIT_IN_BYTES = 1L << 20; // 1Ms
5460

55-
/**
56-
* An interface for Transport implementors to provide the {@link ClientTransportFactory}
57-
* appropriate for the channel.
58-
*/
59-
public interface ClientTransportFactoryBuilder {
60-
ClientTransportFactory buildClientTransportFactory();
61-
}
62-
63-
/**
64-
* TODO(sergiitk): javadoc.
65-
*/
66-
public static class ClientTransportFactoryBuilderImpl implements ClientTransportFactoryBuilder {
67-
@Override
68-
public ClientTransportFactory buildClientTransportFactory() {
69-
throw new UnsupportedOperationException();
70-
}
71-
}
72-
73-
/**
74-
* An interface for Transport implementors to provide a default port to {@link
75-
* io.grpc.NameResolver} for use in cases where the target string doesn't include a port. The
76-
* default implementation returns {@link GrpcUtil#DEFAULT_PORT_SSL}.
77-
*/
78-
public interface ChannelBuilderDefaultPortProvider {
79-
int getDefaultPort();
80-
}
81-
82-
/**
83-
* Default implementation of {@link ChannelBuilderDefaultPortProvider} that returns a fixed port.
84-
*/
85-
public static final class FixedPortProvider implements ChannelBuilderDefaultPortProvider {
86-
private final int port;
61+
private static final ObjectPool<? extends Executor> DEFAULT_EXECUTOR_POOL =
62+
SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR);
63+
private static final DecompressorRegistry DEFAULT_DECOMPRESSOR_REGISTRY =
64+
DecompressorRegistry.getDefaultInstance();
65+
private static final CompressorRegistry DEFAULT_COMPRESSOR_REGISTRY =
66+
CompressorRegistry.getDefaultInstance();
8767

88-
public FixedPortProvider(int port) {
89-
this.port = port;
90-
}
9168

92-
@Override
93-
public int getDefaultPort() {
94-
return port;
95-
}
96-
}
69+
/** An idle timeout smaller than this would be capped to it. */
70+
static final long IDLE_MODE_MIN_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(1);
9771

98-
private static final class ManagedChannelDefaultPortProvider implements
99-
ChannelBuilderDefaultPortProvider {
100-
@Override
101-
public int getDefaultPort() {
102-
return GrpcUtil.DEFAULT_PORT_SSL;
103-
}
104-
}
72+
/** An idle timeout larger than this would disable idle mode. */
73+
@VisibleForTesting static final long IDLE_MODE_MAX_TIMEOUT_DAYS = 30;
10574

106-
private static final String DIRECT_ADDRESS_SCHEME = "directaddress";
107-
private static final Logger log = Logger.getLogger(ManagedChannelImplBuilder.class.getName());
75+
/** The default idle timeout. */
76+
@VisibleForTesting
77+
static final long IDLE_MODE_DEFAULT_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(30);
10878

10979
final String target;
11080
@Nullable
11181
private final SocketAddress directServerAddress;
11282
private final ClientTransportFactoryBuilder clientTransportFactoryBuilder;
11383
private final ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider;
84+
private final List<ClientInterceptor> interceptors = new ArrayList<>();
85+
86+
@VisibleForTesting
87+
@Nullable
88+
String authorityOverride;
11489
private boolean authorityCheckerDisabled;
90+
private boolean statsEnabled = true;
91+
private boolean recordStartedRpcs = true;
92+
private boolean recordFinishedRpcs = true;
93+
private boolean recordRealTimeMetrics = false;
94+
private boolean tracingEnabled = true;
11595

116-
public static ManagedChannelBuilder<?> forAddress(String name, int port) {
117-
throw new UnsupportedOperationException(
118-
"ClientTransportFactoryBuilder is required, use a constructor");
119-
}
96+
ObjectPool<? extends Executor> executorPool = DEFAULT_EXECUTOR_POOL;
97+
ObjectPool<? extends Executor> offloadExecutorPool = DEFAULT_EXECUTOR_POOL;
12098

121-
public static ManagedChannelBuilder<?> forTarget(String target) {
122-
throw new UnsupportedOperationException(
123-
"ClientTransportFactoryBuilder is required, use a constructor");
124-
}
99+
DecompressorRegistry decompressorRegistry = DEFAULT_DECOMPRESSOR_REGISTRY;
100+
CompressorRegistry compressorRegistry = DEFAULT_COMPRESSOR_REGISTRY;
101+
102+
final NameResolverRegistry nameResolverRegistry = NameResolverRegistry.getDefaultRegistry();
103+
// Access via getter, which may perform authority override as needed
104+
NameResolver.Factory nameResolverFactory = nameResolverRegistry.asFactory();
105+
106+
int maxRetryAttempts = 5;
107+
int maxHedgedAttempts = 5;
108+
long retryBufferSize = DEFAULT_RETRY_BUFFER_SIZE_IN_BYTES;
109+
long perRpcBufferLimit = DEFAULT_PER_RPC_BUFFER_LIMIT_IN_BYTES;
110+
boolean retryEnabled = false; // TODO(zdapeng): default to true
111+
112+
long idleTimeoutMillis = IDLE_MODE_DEFAULT_TIMEOUT_MILLIS;
113+
@Nullable
114+
String userAgent;
115+
String defaultLbPolicy = GrpcUtil.DEFAULT_LB_POLICY;
116+
boolean fullStreamDecompression;
117+
// Temporarily disable retry when stats or tracing is enabled to avoid breakage, until we know
118+
// what should be the desired behavior for retry + stats/tracing.
119+
// TODO(zdapeng): delete me
120+
boolean temporarilyDisableRetry;
121+
int maxTraceEvents;
122+
InternalChannelz channelz = InternalChannelz.instance();
123+
@Nullable
124+
Map<String, ?> defaultServiceConfig;
125+
boolean lookUpServiceConfig = true;
126+
@Nullable
127+
BinaryLog binlog;
128+
@Nullable
129+
ProxyDetector proxyDetector;
125130

126131
/**
127132
* Creates a new managed channel builder with a target string, which can be either a valid {@link
@@ -319,18 +324,6 @@ public ManagedChannelImplBuilder idleTimeout(long value, TimeUnit unit) {
319324
return this;
320325
}
321326

322-
/**
323-
* Sets the maximum message size allowed for a single gRPC frame. If an inbound messages larger
324-
* than this limit is received it will not be processed and the RPC will fail with
325-
* RESOURCE_EXHAUSTED.
326-
*/
327-
@Override
328-
public ManagedChannelImplBuilder maxInboundMessageSize(int max) {
329-
Preconditions.checkArgument(max >= 0, "negative max");
330-
maxInboundMessageSize = max;
331-
return this;
332-
}
333-
334327
@Override
335328
public ManagedChannelImplBuilder maxRetryAttempts(int maxRetryAttempts) {
336329
this.maxRetryAttempts = maxRetryAttempts;
@@ -621,6 +614,67 @@ final List<ClientInterceptor> getEffectiveInterceptors() {
621614
return effectiveInterceptors;
622615
}
623616

617+
public static ManagedChannelBuilder<?> forAddress(String name, int port) {
618+
throw new UnsupportedOperationException(
619+
"ClientTransportFactoryBuilder is required, use a constructor");
620+
}
621+
622+
public static ManagedChannelBuilder<?> forTarget(String target) {
623+
throw new UnsupportedOperationException(
624+
"ClientTransportFactoryBuilder is required, use a constructor");
625+
}
626+
627+
/**
628+
* An interface for Transport implementors to provide the {@link ClientTransportFactory}
629+
* appropriate for the channel.
630+
*/
631+
public interface ClientTransportFactoryBuilder {
632+
ClientTransportFactory buildClientTransportFactory();
633+
}
634+
635+
/**
636+
* TODO(sergiitk): javadoc.
637+
*/
638+
public static class ClientTransportFactoryBuilderImpl implements ClientTransportFactoryBuilder {
639+
@Override
640+
public ClientTransportFactory buildClientTransportFactory() {
641+
throw new UnsupportedOperationException();
642+
}
643+
}
644+
645+
/**
646+
* An interface for Transport implementors to provide a default port to {@link
647+
* io.grpc.NameResolver} for use in cases where the target string doesn't include a port. The
648+
* default implementation returns {@link GrpcUtil#DEFAULT_PORT_SSL}.
649+
*/
650+
public interface ChannelBuilderDefaultPortProvider {
651+
int getDefaultPort();
652+
}
653+
654+
/**
655+
* Default implementation of {@link ChannelBuilderDefaultPortProvider} that returns a fixed port.
656+
*/
657+
public static final class FixedPortProvider implements ChannelBuilderDefaultPortProvider {
658+
private final int port;
659+
660+
public FixedPortProvider(int port) {
661+
this.port = port;
662+
}
663+
664+
@Override
665+
public int getDefaultPort() {
666+
return port;
667+
}
668+
}
669+
670+
private static final class ManagedChannelDefaultPortProvider implements
671+
ChannelBuilderDefaultPortProvider {
672+
@Override
673+
public int getDefaultPort() {
674+
return GrpcUtil.DEFAULT_PORT_SSL;
675+
}
676+
}
677+
624678
private static class DirectAddressNameResolverFactory extends NameResolver.Factory {
625679
final SocketAddress address;
626680
final String authority;

0 commit comments

Comments
 (0)