Skip to content

Commit

Permalink
core: InProcessChannelBuilder extends a public API class
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed Aug 25, 2020
1 parent 86d1438 commit 972ae59
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
39 changes: 31 additions & 8 deletions core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java
Original file line number Diff line number Diff line change
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,36 @@ 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");
super();
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 +198,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
Original file line number Diff line number Diff line change
@@ -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() {}
}

0 comments on commit 972ae59

Please sign in to comment.