mirror of https://github.com/grpc/grpc-java.git
core: InProcessChannelBuilder extends a public API class
This commit is contained in:
parent
a429b9767c
commit
b0f0ed080e
|
|
@ -21,11 +21,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import io.grpc.ChannelLogger;
|
import io.grpc.ChannelLogger;
|
||||||
import io.grpc.ExperimentalApi;
|
import io.grpc.ExperimentalApi;
|
||||||
|
import io.grpc.ForwardingChannelBuilder;
|
||||||
import io.grpc.Internal;
|
import io.grpc.Internal;
|
||||||
import io.grpc.internal.AbstractManagedChannelImplBuilder;
|
import io.grpc.ManagedChannelBuilder;
|
||||||
import io.grpc.internal.ClientTransportFactory;
|
import io.grpc.internal.ClientTransportFactory;
|
||||||
import io.grpc.internal.ConnectionClientTransport;
|
import io.grpc.internal.ConnectionClientTransport;
|
||||||
import io.grpc.internal.GrpcUtil;
|
import io.grpc.internal.GrpcUtil;
|
||||||
|
import io.grpc.internal.ManagedChannelImplBuilder;
|
||||||
|
import io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder;
|
||||||
import io.grpc.internal.SharedResourceHolder;
|
import io.grpc.internal.SharedResourceHolder;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
@ -42,7 +45,7 @@ import javax.annotation.Nullable;
|
||||||
*/
|
*/
|
||||||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1783")
|
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1783")
|
||||||
public final class InProcessChannelBuilder extends
|
public final class InProcessChannelBuilder extends
|
||||||
AbstractManagedChannelImplBuilder<InProcessChannelBuilder> {
|
ForwardingChannelBuilder<InProcessChannelBuilder> {
|
||||||
/**
|
/**
|
||||||
* Create a channel builder that will connect to the server with the given name.
|
* Create a channel builder that will connect to the server with the given name.
|
||||||
*
|
*
|
||||||
|
|
@ -67,18 +70,35 @@ public final class InProcessChannelBuilder extends
|
||||||
throw new UnsupportedOperationException("call forName() instead");
|
throw new UnsupportedOperationException("call forName() instead");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final ManagedChannelImplBuilder managedChannelImplBuilder;
|
||||||
private final String name;
|
private final String name;
|
||||||
private ScheduledExecutorService scheduledExecutorService;
|
private ScheduledExecutorService scheduledExecutorService;
|
||||||
private int maxInboundMetadataSize = Integer.MAX_VALUE;
|
private int maxInboundMetadataSize = Integer.MAX_VALUE;
|
||||||
private boolean transportIncludeStatusCause = false;
|
private boolean transportIncludeStatusCause = false;
|
||||||
|
|
||||||
private InProcessChannelBuilder(String name) {
|
private InProcessChannelBuilder(String name) {
|
||||||
super(new InProcessSocketAddress(name), "localhost");
|
|
||||||
this.name = checkNotNull(name, "name");
|
this.name = checkNotNull(name, "name");
|
||||||
|
|
||||||
|
final class InProcessChannelTransportFactoryBuilder implements ClientTransportFactoryBuilder {
|
||||||
|
@Override
|
||||||
|
public ClientTransportFactory buildClientTransportFactory() {
|
||||||
|
return buildTransportFactory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
managedChannelImplBuilder = new ManagedChannelImplBuilder(new InProcessSocketAddress(name),
|
||||||
|
"localhost", new InProcessChannelTransportFactoryBuilder(), null);
|
||||||
|
|
||||||
// In-process transport should not record its traffic to the stats module.
|
// In-process transport should not record its traffic to the stats module.
|
||||||
// https://github.com/grpc/grpc-java/issues/2284
|
// https://github.com/grpc/grpc-java/issues/2284
|
||||||
setStatsRecordStartedRpcs(false);
|
managedChannelImplBuilder.setStatsRecordStartedRpcs(false);
|
||||||
setStatsRecordFinishedRpcs(false);
|
managedChannelImplBuilder.setStatsRecordFinishedRpcs(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Internal
|
||||||
|
@Override
|
||||||
|
protected ManagedChannelBuilder<?> delegate() {
|
||||||
|
return managedChannelImplBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -177,13 +197,15 @@ public final class InProcessChannelBuilder extends
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
ClientTransportFactory buildTransportFactory() {
|
||||||
@Internal
|
|
||||||
protected ClientTransportFactory buildTransportFactory() {
|
|
||||||
return new InProcessClientTransportFactory(
|
return new InProcessClientTransportFactory(
|
||||||
name, scheduledExecutorService, maxInboundMetadataSize, transportIncludeStatusCause);
|
name, scheduledExecutorService, maxInboundMetadataSize, transportIncludeStatusCause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setStatsEnabled(boolean value) {
|
||||||
|
this.managedChannelImplBuilder.setStatsEnabled(value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates InProcess transports. Exposed for internal use, as it should be private.
|
* Creates InProcess transports. Exposed for internal use, as it should be private.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2020 The gRPC Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.grpc.inprocess;
|
||||||
|
|
||||||
|
import io.grpc.Internal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal {@link InProcessChannelBuilder} accessor. This is intended for usage internal to the
|
||||||
|
* gRPC team. If you *really* think you need to use this, contact the gRPC team first.
|
||||||
|
*/
|
||||||
|
@Internal
|
||||||
|
public final class InternalInProcessChannelBuilder {
|
||||||
|
|
||||||
|
public static void setStatsEnabled(InProcessChannelBuilder builder, boolean value) {
|
||||||
|
builder.setStatsEnabled(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private InternalInProcessChannelBuilder() {}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ package io.grpc.testing.integration;
|
||||||
|
|
||||||
import io.grpc.inprocess.InProcessChannelBuilder;
|
import io.grpc.inprocess.InProcessChannelBuilder;
|
||||||
import io.grpc.inprocess.InProcessServerBuilder;
|
import io.grpc.inprocess.InProcessServerBuilder;
|
||||||
|
import io.grpc.inprocess.InternalInProcessChannelBuilder;
|
||||||
import io.grpc.internal.AbstractServerImplBuilder;
|
import io.grpc.internal.AbstractServerImplBuilder;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
|
|
@ -38,7 +39,7 @@ public class InProcessTest extends AbstractInteropTest {
|
||||||
protected InProcessChannelBuilder createChannelBuilder() {
|
protected InProcessChannelBuilder createChannelBuilder() {
|
||||||
InProcessChannelBuilder builder = InProcessChannelBuilder.forName(SERVER_NAME);
|
InProcessChannelBuilder builder = InProcessChannelBuilder.forName(SERVER_NAME);
|
||||||
// Disable the default census stats interceptor, use testing interceptor instead.
|
// Disable the default census stats interceptor, use testing interceptor instead.
|
||||||
io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false);
|
InternalInProcessChannelBuilder.setStatsEnabled(builder, false);
|
||||||
return builder.intercept(createCensusStatsClientInterceptor());
|
return builder.intercept(createCensusStatsClientInterceptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue