Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 7211 WIP #1

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
cecbd5e
WIP
sergiitk Aug 13, 2020
efef650
Figure out default port
sergiitk Aug 14, 2020
897e5f5
fix maxInboundMessageSize()
sergiitk Aug 14, 2020
795a821
Java 7 support
sergiitk Aug 14, 2020
9c4deec
Minor format
sergiitk Aug 14, 2020
bf4af5a
Use interface to pass buildTransportFactory()
sergiitk Aug 14, 2020
bf9a2a8
Save notes
sergiitk Aug 17, 2020
e60db3e
Fix lint, make build pass
sergiitk Aug 17, 2020
6446288
Inject buildTransportFactory via ClientTransportFactoryFactory interface
sergiitk Aug 17, 2020
d15baa5
Rename ClientTransportFactoryFactory to ClientTransportFactoryBuilder
sergiitk Aug 17, 2020
2fb795d
Move SimpleForwardingChannelBuilder into ForwardingChannelBuilder
sergiitk Aug 17, 2020
93806b3
Refactor maxInboundMessageSize()
sergiitk Aug 17, 2020
bf45ded
Make transportTracerFactory protected to keep compatibility with Abst…
sergiitk Aug 17, 2020
4c9193d
Implement optional ChannelBuilderDefaultPortProvider
sergiitk Aug 18, 2020
4362cce
OkHttpChannelBuilder passes getDefaultPort()
sergiitk Aug 18, 2020
f293baf
Comment to todo
sergiitk Aug 18, 2020
fd0da1a
Start working on NettyChannelBuilder
sergiitk Aug 18, 2020
825379d
Netty: update SocketAddress constructor
sergiitk Aug 18, 2020
60a7d0a
Remove unsused import
sergiitk Aug 18, 2020
f98e673
Comments from 1:1 w/Eric
sergiitk Aug 18, 2020
7a5ea93
Organize todos
sergiitk Aug 18, 2020
54cc1b3
Make channelBuilderDefaultPortProvider required
sergiitk Aug 18, 2020
18cc303
Add Preconditions.checkNotNull
sergiitk Aug 18, 2020
7b99c97
Temp Revert NettyChannelBuilder
sergiitk Aug 18, 2020
0b87ee9
Make buildTransportFactory() package-private, reimplement maxInboundM…
sergiitk Aug 18, 2020
006792b
Hide getDefaultPort()
sergiitk Aug 18, 2020
9eda883
Make getDefaultPort() package-private for testing
sergiitk Aug 18, 2020
41c5afb
disableCheckAuthority() instead of overriding checkAuthority()
sergiitk Aug 19, 2020
5f105ca
Start NettyChannelBuilder refactoring
sergiitk Aug 19, 2020
a35d786
Fix getOffloadExecutorPool reference in NettyChannelBuilder
sergiitk Aug 19, 2020
ec8d851
Replace checkAuthority and overrideAuthorityChecker with disableCheck…
sergiitk Aug 19, 2020
a1c9156
NettyChannelBuilder builds!
sergiitk Aug 19, 2020
97956b9
Fix ManagedChannelImplBuilder lint
sergiitk Aug 19, 2020
4ffddbb
Minor
sergiitk Aug 19, 2020
dc88442
Remove comments relevant to the server-side refactoring
sergiitk Aug 20, 2020
66ac3a4
NettyChannelBuilder: Add test for enableCheckAuthority()
sergiitk Aug 20, 2020
5277dbc
Bring back NettyChannelBuilder.overrideAuthorityChecker(), but mark f…
sergiitk Aug 20, 2020
964ef77
Refactor InProcessChannelBuilder!
sergiitk Aug 20, 2020
f20a75b
m
sergiitk Aug 20, 2020
df9ee31
ManagedChannelImplBuilder unit test WIP
sergiitk Aug 20, 2020
540d5dd
Figuring out unit testing
sergiitk Aug 21, 2020
a7abed1
Shared builder, test buildTransportFactory()
sergiitk Aug 21, 2020
6fb2f42
Finish ManagedChannelImplBuilderTest tests
sergiitk Aug 21, 2020
d8b9c52
Fix ManagedChannelImplBuilderTest style
sergiitk Aug 21, 2020
097a6fb
Replace TestingAccessor.setStatsEnabled()
sergiitk Aug 21, 2020
e1419fc
Fix channelBuilderHidesMethod_for*() tests
sergiitk Aug 21, 2020
c8f5595
Suppress deprecation - full build works!
sergiitk Aug 21, 2020
52e0060
Refactor CronetChannelBuilder
sergiitk Aug 24, 2020
6d3a5e1
Get rid of SimpleForwardingChannelBuilder to preserve delegate private
sergiitk Aug 24, 2020
51d04cd
Replace AbstractManagedChannelImplBuilder in ServiceConfigErrorHandli…
sergiitk Aug 24, 2020
5ab7d1b
m
sergiitk Aug 24, 2020
927b43d
Replace AbstractManagedChannelImplBuilder in ManagedChannelImplTest
sergiitk Aug 24, 2020
398fb92
Replace AbstractManagedChannelImplBuilder in ManagedChannelImplIdlene…
sergiitk Aug 24, 2020
92effa9
Finish javadocs
sergiitk Aug 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.protobuf.ByteString;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Server;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
Expand All @@ -30,7 +31,6 @@
import io.grpc.benchmarks.qps.AsyncServer;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.internal.AbstractManagedChannelImplBuilder;
import io.grpc.internal.AbstractServerImplBuilder;
import io.grpc.netty.NegotiationType;
import io.grpc.netty.NettyChannelBuilder;
Expand Down Expand Up @@ -81,7 +81,7 @@ public enum Transport {
@Setup
public void setUp() throws Exception {
AbstractServerImplBuilder<?> serverBuilder;
AbstractManagedChannelImplBuilder<?> channelBuilder;
ManagedChannelBuilder<?> channelBuilder;
switch (transport) {
case INPROCESS:
{
Expand Down
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() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import javax.annotation.Nullable;

/**
* The base class for channel builders.
* Abstract base class for channel builders.
*
* @param <T> The concrete type of this builder.
*/
Expand Down
181 changes: 181 additions & 0 deletions core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* 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.internal;

import com.google.common.base.Preconditions;
import io.grpc.ManagedChannelBuilder;
import java.net.SocketAddress;
import java.util.concurrent.Executor;
import javax.annotation.Nullable;

/**
* The base class for channel builders.
*/
public final class ManagedChannelImplBuilder
extends AbstractManagedChannelImplBuilder<ManagedChannelImplBuilder> {

private boolean authorityCheckerDisabled;
@Deprecated
@Nullable
private OverrideAuthorityChecker authorityChecker;

/**
* An interface for Transport implementors to provide the {@link ClientTransportFactory}
* appropriate for the channel.
*/
public interface ClientTransportFactoryBuilder {
ClientTransportFactory buildClientTransportFactory();
}

/**
* An interface for Transport implementors to provide a default port to {@link
* io.grpc.NameResolver} for use in cases where the target string doesn't include a port. The
* default implementation returns {@link GrpcUtil#DEFAULT_PORT_SSL}.
*/
public interface ChannelBuilderDefaultPortProvider {
int getDefaultPort();
}

private class ManagedChannelDefaultPortProvider implements ChannelBuilderDefaultPortProvider {
@Override
public int getDefaultPort() {
return ManagedChannelImplBuilder.super.getDefaultPort();
}
}

private final ClientTransportFactoryBuilder clientTransportFactoryBuilder;
private final ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider;

/**
* Creates a new managed channel builder with a target string, which can be either a valid {@link
* io.grpc.NameResolver}-compliant URI, or an authority string. Transport implementors must
* provide client transport factory builder, and may set custom channel default port provider.
*/
public ManagedChannelImplBuilder(String target,
ClientTransportFactoryBuilder clientTransportFactoryBuilder,
@Nullable ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider) {
super(target);
this.clientTransportFactoryBuilder = Preconditions.checkNotNull(clientTransportFactoryBuilder,
"clientTransportFactoryBuilder cannot be null");

if (channelBuilderDefaultPortProvider != null) {
this.channelBuilderDefaultPortProvider = channelBuilderDefaultPortProvider;
} else {
this.channelBuilderDefaultPortProvider = new ManagedChannelDefaultPortProvider();
}
}

/**
* Creates a new managed channel builder with the given server address, authority string of the
* channel. Transport implementors must provide client transport factory builder, and may set
* custom channel default port provider.
*/
public ManagedChannelImplBuilder(SocketAddress directServerAddress, String authority,
ClientTransportFactoryBuilder clientTransportFactoryBuilder,
@Nullable ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider) {
super(directServerAddress, authority);
this.clientTransportFactoryBuilder = Preconditions.checkNotNull(clientTransportFactoryBuilder,
"clientTransportFactoryBuilder cannot be null");

if (channelBuilderDefaultPortProvider != null) {
this.channelBuilderDefaultPortProvider = channelBuilderDefaultPortProvider;
} else {
this.channelBuilderDefaultPortProvider = new ManagedChannelDefaultPortProvider();
}
}

@Override
protected ClientTransportFactory buildTransportFactory() {
return clientTransportFactoryBuilder.buildClientTransportFactory();
}

@Override
protected int getDefaultPort() {
return channelBuilderDefaultPortProvider.getDefaultPort();
}

/** Disable the check whether the authority is valid. */
public ManagedChannelImplBuilder disableCheckAuthority() {
authorityCheckerDisabled = true;
return this;
}

/** Enable previously disabled authority check. */
public ManagedChannelImplBuilder enableCheckAuthority() {
authorityCheckerDisabled = false;
return this;
}

@Deprecated
public interface OverrideAuthorityChecker {
String checkAuthority(String authority);
}

@Deprecated
public void overrideAuthorityChecker(@Nullable OverrideAuthorityChecker authorityChecker) {
this.authorityChecker = authorityChecker;
}

@Override
protected String checkAuthority(String authority) {
if (authorityCheckerDisabled) {
return authority;
}
if (authorityChecker != null) {
return authorityChecker.checkAuthority(authority);
}
return super.checkAuthority(authority);
}

@Override
public void setStatsEnabled(boolean value) {
super.setStatsEnabled(value);
}

@Override
public void setStatsRecordStartedRpcs(boolean value) {
super.setStatsRecordStartedRpcs(value);
}

@Override
public void setStatsRecordFinishedRpcs(boolean value) {
super.setStatsRecordFinishedRpcs(value);
}

@Override
public void setStatsRecordRealTimeMetrics(boolean value) {
super.setStatsRecordRealTimeMetrics(value);
}

@Override
public void setTracingEnabled(boolean value) {
super.setTracingEnabled(value);
}

@Override
public ObjectPool<? extends Executor> getOffloadExecutorPool() {
return super.getOffloadExecutorPool();
}

public static ManagedChannelBuilder<?> forAddress(String name, int port) {
throw new UnsupportedOperationException("ClientTransportFactoryBuilder is required");
}

public static ManagedChannelBuilder<?> forTarget(String target) {
throw new UnsupportedOperationException("ClientTransportFactoryBuilder is required");
}
}
Loading