Skip to content

Commit

Permalink
core: remove last references to AbstractManagedChannelImplBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed Sep 11, 2020
1 parent 366ca40 commit 464f476
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.grpc.DecompressorRegistry;
import io.grpc.EquivalentAddressGroup;
import io.grpc.InternalChannelz;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.NameResolver;
import io.grpc.NameResolverRegistry;
Expand Down Expand Up @@ -507,18 +506,6 @@ protected String checkAuthority(String authority) {
return GrpcUtil.checkAuthority(authority);
}

@Override
public ManagedChannel build() {
return new ManagedChannelOrphanWrapper(new ManagedChannelImpl(
this,
buildTransportFactory(),
new ExponentialBackoffPolicy.Provider(),
SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR),
GrpcUtil.STOPWATCH_SUPPLIER,
getEffectiveInterceptors(),
TimeProvider.SYSTEM_TIME_PROVIDER));
}

// Temporarily disable retry when stats or tracing is enabled to avoid breakage, until we know
// what should be the desired behavior for retry + stats/tracing.
// TODO(zdapeng): FIX IT
Expand Down
49 changes: 26 additions & 23 deletions core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.grpc.Context;
import io.grpc.DecompressorRegistry;
import io.grpc.EquivalentAddressGroup;
import io.grpc.ForwardingChannelBuilder;
import io.grpc.InternalChannelz;
import io.grpc.InternalChannelz.ChannelStats;
import io.grpc.InternalChannelz.ChannelTrace;
Expand Down Expand Up @@ -72,6 +73,8 @@
import io.grpc.SynchronizationContext.ScheduledHandle;
import io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer;
import io.grpc.internal.ClientCallImpl.ClientStreamProvider;
import io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilderImpl;
import io.grpc.internal.ManagedChannelImplBuilder.FixedPortProvider;
import io.grpc.internal.ManagedChannelServiceConfig.MethodInfo;
import io.grpc.internal.RetriableStream.ChannelBufferMeter;
import io.grpc.internal.RetriableStream.Throttle;
Expand Down Expand Up @@ -574,7 +577,7 @@ ClientStream newSubstream(ClientStreamTracer.Factory tracerFactory, Metadata new
private final Rescheduler idleTimer;

ManagedChannelImpl(
AbstractManagedChannelImplBuilder<?> builder,
ManagedChannelImplBuilder builder,
ClientTransportFactory clientTransportFactory,
BackoffPolicy.Provider backoffPolicyProvider,
ObjectPool<? extends Executor> balancerRpcExecutorPool,
Expand Down Expand Up @@ -661,7 +664,7 @@ public void execute(Runnable command) {
} else {
checkArgument(
builder.idleTimeoutMillis
>= AbstractManagedChannelImplBuilder.IDLE_MODE_MIN_TIMEOUT_MILLIS,
>= ManagedChannelImplBuilder.IDLE_MODE_MIN_TIMEOUT_MILLIS,
"invalid idleTimeoutMillis %s", builder.idleTimeoutMillis);
this.idleTimeoutMillis = builder.idleTimeoutMillis;
}
Expand Down Expand Up @@ -1446,28 +1449,30 @@ public void run() {
@Override
public ManagedChannelBuilder<?> createResolvingOobChannelBuilder(String target) {
final class ResolvingOobChannelBuilder
extends AbstractManagedChannelImplBuilder<ResolvingOobChannelBuilder> {
int defaultPort = -1;
extends ForwardingChannelBuilder<ResolvingOobChannelBuilder> {
private final ManagedChannelImplBuilder managedChannelImplBuilder;

ResolvingOobChannelBuilder(String target) {
super(target);
final class ResolvingOobChannelTransportFactoryBuilder extends
ClientTransportFactoryBuilderImpl {}

managedChannelImplBuilder = new ManagedChannelImplBuilder(target,
new ResolvingOobChannelTransportFactoryBuilder(),
new FixedPortProvider(nameResolverArgs.getDefaultPort()));
managedChannelImplBuilder.executorPool = executorPool;
managedChannelImplBuilder.offloadExecutorPool = offloadExecutorHolder.pool;
}

@Override
public int getDefaultPort() {
return defaultPort;
}

@Override
protected ClientTransportFactory buildTransportFactory() {
throw new UnsupportedOperationException();
protected ManagedChannelBuilder<?> delegate() {
return managedChannelImplBuilder;
}

@Override
public ManagedChannel build() {
// TODO(creamsoup) prevent main channel to shutdown if oob channel is not terminated
return new ManagedChannelImpl(
this,
managedChannelImplBuilder,
transportFactory,
backoffPolicyProvider,
balancerRpcExecutorPool,
Expand All @@ -1479,17 +1484,15 @@ public ManagedChannel build() {

checkState(!terminated, "Channel is terminated");

ResolvingOobChannelBuilder builder = new ResolvingOobChannelBuilder(target);
builder.offloadExecutorPool = offloadExecutorHolder.pool;
builder.overrideAuthority(getAuthority());
@SuppressWarnings("deprecation")
ResolvingOobChannelBuilder unused = builder.nameResolverFactory(nameResolverFactory);
builder.executorPool = executorPool;
builder.maxTraceEvents = maxTraceEvents;
builder.proxyDetector = nameResolverArgs.getProxyDetector();
builder.defaultPort = nameResolverArgs.getDefaultPort();
builder.userAgent = userAgent;
return builder;
ResolvingOobChannelBuilder builder = new ResolvingOobChannelBuilder(target)
.nameResolverFactory(nameResolverFactory);

return builder
.overrideAuthority(getAuthority())
.maxTraceEvents(maxTraceEvents)
.proxyDetector(nameResolverArgs.getProxyDetector())
.userAgent(userAgent);
}

@Override
Expand Down
23 changes: 23 additions & 0 deletions core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.grpc.internal;

import com.google.common.base.Preconditions;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import java.net.SocketAddress;
import java.util.concurrent.Executor;
Expand All @@ -38,6 +39,16 @@ public interface ClientTransportFactoryBuilder {
ClientTransportFactory buildClientTransportFactory();
}

/**
* TODO(sergiitk): javadoc.
*/
public static class ClientTransportFactoryBuilderImpl implements ClientTransportFactoryBuilder {
@Override
public ClientTransportFactory buildClientTransportFactory() {
throw new UnsupportedOperationException();
}
}

/**
* 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
Expand Down Expand Up @@ -122,6 +133,18 @@ protected int getDefaultPort() {
return channelBuilderDefaultPortProvider.getDefaultPort();
}

@Override
public ManagedChannel build() {
return new ManagedChannelOrphanWrapper(new ManagedChannelImpl(
this,
buildTransportFactory(),
new ExponentialBackoffPolicy.Provider(),
SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR),
GrpcUtil.STOPWATCH_SUPPLIER,
getEffectiveInterceptors(),
TimeProvider.SYSTEM_TIME_PROVIDER));
}

/** Disable the check whether the authority is valid. */
public ManagedChannelImplBuilder disableCheckAuthority() {
authorityCheckerDisabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.grpc.DecompressorRegistry;
import io.grpc.MethodDescriptor;
import io.grpc.NameResolver;
import io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilderImpl;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
Expand All @@ -51,9 +52,9 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Unit tests for {@link AbstractManagedChannelImplBuilder}. */
/** Unit tests for {@link ManagedChannelImplBuilder}. */
@RunWith(JUnit4.class)
public class AbstractManagedChannelImplBuilderTest {
public class ManagedChannelImplBuilderTest2 {

@Rule
public final ExpectedException thrown = ExpectedException.none();
Expand All @@ -67,8 +68,10 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
}
};

private final Builder builder = new Builder("fake");
private final Builder directAddressBuilder = new Builder(new SocketAddress(){}, "fake");
private final ManagedChannelImplBuilder builder = new ManagedChannelImplBuilder("fake",
new ClientTransportFactoryBuilderImpl(), null);
private final ManagedChannelImplBuilder directAddressBuilder = new ManagedChannelImplBuilder(
new SocketAddress() {}, "fake", new ClientTransportFactoryBuilderImpl(), null);

@Test
public void executor_default() {
Expand Down Expand Up @@ -271,7 +274,7 @@ public void overrideAuthority_getNameResolverFactory() {
public void makeTargetStringForDirectAddress_scopedIpv6() throws Exception {
InetSocketAddress address = new InetSocketAddress("0:0:0:0:0:0:0:0%0", 10005);
assertEquals("/0:0:0:0:0:0:0:0%0:10005", address.toString());
String target = AbstractManagedChannelImplBuilder.makeTargetStringForDirectAddress(address);
String target = ManagedChannelImplBuilder.makeTargetStringForDirectAddress(address);
URI uri = new URI(target);
assertEquals("directaddress:////0:0:0:0:0:0:0:0%250:10005", target);
assertEquals(target, uri.toString());
Expand Down Expand Up @@ -322,13 +325,13 @@ public void getEffectiveInterceptors_disableBoth() {

@Test
public void idleTimeout() {
assertEquals(AbstractManagedChannelImplBuilder.IDLE_MODE_DEFAULT_TIMEOUT_MILLIS,
assertEquals(ManagedChannelImplBuilder.IDLE_MODE_DEFAULT_TIMEOUT_MILLIS,
builder.getIdleTimeoutMillis());

builder.idleTimeout(Long.MAX_VALUE, TimeUnit.DAYS);
assertEquals(ManagedChannelImpl.IDLE_TIMEOUT_MILLIS_DISABLE, builder.getIdleTimeoutMillis());

builder.idleTimeout(AbstractManagedChannelImplBuilder.IDLE_MODE_MAX_TIMEOUT_DAYS,
builder.idleTimeout(ManagedChannelImplBuilder.IDLE_MODE_MAX_TIMEOUT_DAYS,
TimeUnit.DAYS);
assertEquals(ManagedChannelImpl.IDLE_TIMEOUT_MILLIS_DISABLE, builder.getIdleTimeoutMillis());

Expand All @@ -340,7 +343,7 @@ public void idleTimeout() {
}

builder.idleTimeout(1, TimeUnit.NANOSECONDS);
assertEquals(AbstractManagedChannelImplBuilder.IDLE_MODE_MIN_TIMEOUT_MILLIS,
assertEquals(ManagedChannelImplBuilder.IDLE_MODE_MIN_TIMEOUT_MILLIS,
builder.getIdleTimeoutMillis());

builder.idleTimeout(30, TimeUnit.SECONDS);
Expand Down Expand Up @@ -464,19 +467,4 @@ public void disableNameResolverServiceConfig() {
builder.disableServiceConfigLookUp();
assertThat(builder.lookUpServiceConfig).isFalse();
}

static class Builder extends AbstractManagedChannelImplBuilder<Builder> {
Builder(String target) {
super(target);
}

Builder(SocketAddress directServerAddress, String authority) {
super(directServerAddress, authority);
}

@Override
protected ClientTransportFactory buildTransportFactory() {
throw new UnsupportedOperationException();
}
}
}

0 comments on commit 464f476

Please sign in to comment.