Skip to content

Commit

Permalink
core, interop: InProcessChannelBuilder extends a public API class
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed Sep 2, 2020
1 parent 8c2b44e commit 9cd0e1a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
38 changes: 30 additions & 8 deletions core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java
Expand Up @@ -21,11 +21,14 @@

import io.grpc.ChannelLogger;
import io.grpc.ExperimentalApi;
import io.grpc.ForwardingChannelBuilder;
import io.grpc.Internal;
import io.grpc.internal.AbstractManagedChannelImplBuilder;
import io.grpc.ManagedChannelBuilder;
import io.grpc.internal.ClientTransportFactory;
import io.grpc.internal.ConnectionClientTransport;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.ManagedChannelImplBuilder;
import io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder;
import io.grpc.internal.SharedResourceHolder;
import java.net.SocketAddress;
import java.util.concurrent.ScheduledExecutorService;
Expand All @@ -42,7 +45,7 @@
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1783")
public final class InProcessChannelBuilder extends
AbstractManagedChannelImplBuilder<InProcessChannelBuilder> {
ForwardingChannelBuilder<InProcessChannelBuilder> {
/**
* Create a channel builder that will connect to the server with the given name.
*
Expand All @@ -67,18 +70,35 @@ public static InProcessChannelBuilder forAddress(String name, int port) {
throw new UnsupportedOperationException("call forName() instead");
}

private final ManagedChannelImplBuilder managedChannelImplBuilder;
private final String name;
private ScheduledExecutorService scheduledExecutorService;
private int maxInboundMetadataSize = Integer.MAX_VALUE;
private boolean transportIncludeStatusCause = false;

private InProcessChannelBuilder(String name) {
super(new InProcessSocketAddress(name), "localhost");
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.
// https://github.com/grpc/grpc-java/issues/2284
setStatsRecordStartedRpcs(false);
setStatsRecordFinishedRpcs(false);
managedChannelImplBuilder.setStatsRecordStartedRpcs(false);
managedChannelImplBuilder.setStatsRecordFinishedRpcs(false);
}

@Internal
@Override
protected ManagedChannelBuilder<?> delegate() {
return managedChannelImplBuilder;
}

@Override
Expand Down Expand Up @@ -177,13 +197,15 @@ public InProcessChannelBuilder propagateCauseWithStatus(boolean enable) {
return this;
}

@Override
@Internal
protected ClientTransportFactory buildTransportFactory() {
ClientTransportFactory buildTransportFactory() {
return new InProcessClientTransportFactory(
name, scheduledExecutorService, maxInboundMetadataSize, transportIncludeStatusCause);
}

void setStatsEnabled(boolean value) {
this.managedChannelImplBuilder.setStatsEnabled(value);
}

/**
* Creates InProcess transports. Exposed for internal use, as it should be private.
*/
Expand Down
@@ -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() {}
}
Expand Up @@ -18,6 +18,7 @@

import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.inprocess.InternalInProcessChannelBuilder;
import io.grpc.internal.AbstractServerImplBuilder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -38,7 +39,7 @@ protected AbstractServerImplBuilder<?> getServerBuilder() {
protected InProcessChannelBuilder createChannelBuilder() {
InProcessChannelBuilder builder = InProcessChannelBuilder.forName(SERVER_NAME);
// 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());
}

Expand Down

0 comments on commit 9cd0e1a

Please sign in to comment.