Skip to content

Commit 9cd0e1a

Browse files
committed
core, interop: InProcessChannelBuilder extends a public API class
1 parent 8c2b44e commit 9cd0e1a

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed

core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java

+30-8
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121

2222
import io.grpc.ChannelLogger;
2323
import io.grpc.ExperimentalApi;
24+
import io.grpc.ForwardingChannelBuilder;
2425
import io.grpc.Internal;
25-
import io.grpc.internal.AbstractManagedChannelImplBuilder;
26+
import io.grpc.ManagedChannelBuilder;
2627
import io.grpc.internal.ClientTransportFactory;
2728
import io.grpc.internal.ConnectionClientTransport;
2829
import io.grpc.internal.GrpcUtil;
30+
import io.grpc.internal.ManagedChannelImplBuilder;
31+
import io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder;
2932
import io.grpc.internal.SharedResourceHolder;
3033
import java.net.SocketAddress;
3134
import java.util.concurrent.ScheduledExecutorService;
@@ -42,7 +45,7 @@
4245
*/
4346
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1783")
4447
public final class InProcessChannelBuilder extends
45-
AbstractManagedChannelImplBuilder<InProcessChannelBuilder> {
48+
ForwardingChannelBuilder<InProcessChannelBuilder> {
4649
/**
4750
* Create a channel builder that will connect to the server with the given name.
4851
*
@@ -67,18 +70,35 @@ public static InProcessChannelBuilder forAddress(String name, int port) {
6770
throw new UnsupportedOperationException("call forName() instead");
6871
}
6972

73+
private final ManagedChannelImplBuilder managedChannelImplBuilder;
7074
private final String name;
7175
private ScheduledExecutorService scheduledExecutorService;
7276
private int maxInboundMetadataSize = Integer.MAX_VALUE;
7377
private boolean transportIncludeStatusCause = false;
7478

7579
private InProcessChannelBuilder(String name) {
76-
super(new InProcessSocketAddress(name), "localhost");
7780
this.name = checkNotNull(name, "name");
81+
82+
final class InProcessChannelTransportFactoryBuilder implements ClientTransportFactoryBuilder {
83+
@Override
84+
public ClientTransportFactory buildClientTransportFactory() {
85+
return buildTransportFactory();
86+
}
87+
}
88+
89+
managedChannelImplBuilder = new ManagedChannelImplBuilder(new InProcessSocketAddress(name),
90+
"localhost", new InProcessChannelTransportFactoryBuilder(), null);
91+
7892
// In-process transport should not record its traffic to the stats module.
7993
// https://github.com/grpc/grpc-java/issues/2284
80-
setStatsRecordStartedRpcs(false);
81-
setStatsRecordFinishedRpcs(false);
94+
managedChannelImplBuilder.setStatsRecordStartedRpcs(false);
95+
managedChannelImplBuilder.setStatsRecordFinishedRpcs(false);
96+
}
97+
98+
@Internal
99+
@Override
100+
protected ManagedChannelBuilder<?> delegate() {
101+
return managedChannelImplBuilder;
82102
}
83103

84104
@Override
@@ -177,13 +197,15 @@ public InProcessChannelBuilder propagateCauseWithStatus(boolean enable) {
177197
return this;
178198
}
179199

180-
@Override
181-
@Internal
182-
protected ClientTransportFactory buildTransportFactory() {
200+
ClientTransportFactory buildTransportFactory() {
183201
return new InProcessClientTransportFactory(
184202
name, scheduledExecutorService, maxInboundMetadataSize, transportIncludeStatusCause);
185203
}
186204

205+
void setStatsEnabled(boolean value) {
206+
this.managedChannelImplBuilder.setStatsEnabled(value);
207+
}
208+
187209
/**
188210
* Creates InProcess transports. Exposed for internal use, as it should be private.
189211
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2020 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.inprocess;
18+
19+
import io.grpc.Internal;
20+
21+
/**
22+
* Internal {@link InProcessChannelBuilder} accessor. This is intended for usage internal to the
23+
* gRPC team. If you *really* think you need to use this, contact the gRPC team first.
24+
*/
25+
@Internal
26+
public final class InternalInProcessChannelBuilder {
27+
28+
public static void setStatsEnabled(InProcessChannelBuilder builder, boolean value) {
29+
builder.setStatsEnabled(value);
30+
}
31+
32+
private InternalInProcessChannelBuilder() {}
33+
}

interop-testing/src/test/java/io/grpc/testing/integration/InProcessTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.grpc.inprocess.InProcessChannelBuilder;
2020
import io.grpc.inprocess.InProcessServerBuilder;
21+
import io.grpc.inprocess.InternalInProcessChannelBuilder;
2122
import io.grpc.internal.AbstractServerImplBuilder;
2223
import org.junit.runner.RunWith;
2324
import org.junit.runners.JUnit4;
@@ -38,7 +39,7 @@ protected AbstractServerImplBuilder<?> getServerBuilder() {
3839
protected InProcessChannelBuilder createChannelBuilder() {
3940
InProcessChannelBuilder builder = InProcessChannelBuilder.forName(SERVER_NAME);
4041
// Disable the default census stats interceptor, use testing interceptor instead.
41-
io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false);
42+
InternalInProcessChannelBuilder.setStatsEnabled(builder, false);
4243
return builder.intercept(createCensusStatsClientInterceptor());
4344
}
4445

0 commit comments

Comments
 (0)