21
21
22
22
import io .grpc .ChannelLogger ;
23
23
import io .grpc .ExperimentalApi ;
24
+ import io .grpc .ForwardingChannelBuilder ;
24
25
import io .grpc .Internal ;
25
- import io .grpc .internal . AbstractManagedChannelImplBuilder ;
26
+ import io .grpc .ManagedChannelBuilder ;
26
27
import io .grpc .internal .ClientTransportFactory ;
27
28
import io .grpc .internal .ConnectionClientTransport ;
28
29
import io .grpc .internal .GrpcUtil ;
30
+ import io .grpc .internal .ManagedChannelImplBuilder ;
31
+ import io .grpc .internal .ManagedChannelImplBuilder .ClientTransportFactoryBuilder ;
29
32
import io .grpc .internal .SharedResourceHolder ;
30
33
import java .net .SocketAddress ;
31
34
import java .util .concurrent .ScheduledExecutorService ;
42
45
*/
43
46
@ ExperimentalApi ("https://github.com/grpc/grpc-java/issues/1783" )
44
47
public final class InProcessChannelBuilder extends
45
- AbstractManagedChannelImplBuilder <InProcessChannelBuilder > {
48
+ ForwardingChannelBuilder <InProcessChannelBuilder > {
46
49
/**
47
50
* Create a channel builder that will connect to the server with the given name.
48
51
*
@@ -67,18 +70,35 @@ public static InProcessChannelBuilder forAddress(String name, int port) {
67
70
throw new UnsupportedOperationException ("call forName() instead" );
68
71
}
69
72
73
+ private final ManagedChannelImplBuilder managedChannelImplBuilder ;
70
74
private final String name ;
71
75
private ScheduledExecutorService scheduledExecutorService ;
72
76
private int maxInboundMetadataSize = Integer .MAX_VALUE ;
73
77
private boolean transportIncludeStatusCause = false ;
74
78
75
79
private InProcessChannelBuilder (String name ) {
76
- super (new InProcessSocketAddress (name ), "localhost" );
77
80
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
+
78
92
// In-process transport should not record its traffic to the stats module.
79
93
// 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 ;
82
102
}
83
103
84
104
@ Override
@@ -177,13 +197,15 @@ public InProcessChannelBuilder propagateCauseWithStatus(boolean enable) {
177
197
return this ;
178
198
}
179
199
180
- @ Override
181
- @ Internal
182
- protected ClientTransportFactory buildTransportFactory () {
200
+ ClientTransportFactory buildTransportFactory () {
183
201
return new InProcessClientTransportFactory (
184
202
name , scheduledExecutorService , maxInboundMetadataSize , transportIncludeStatusCause );
185
203
}
186
204
205
+ void setStatsEnabled (boolean value ) {
206
+ this .managedChannelImplBuilder .setStatsEnabled (value );
207
+ }
208
+
187
209
/**
188
210
* Creates InProcess transports. Exposed for internal use, as it should be private.
189
211
*/
0 commit comments