InstantiatingGrpcChannelProvider implements TransportChannelProvider { @Override @BetaApi("The surface for customizing pool size is not stable yet and may change in the future.") public TransportChannelProvider withPoolSize(int size) { Preconditions.checkState(acceptsPoolSize(), "pool size already set to %s", poolSize); return toBuilder().setPoolSize(size).build(); } private  InstantiatingGrpcChannelProvider(Builder builder); @Override boolean needsExecutor(); @Deprecated @Override TransportChannelProvider withExecutor(ScheduledExecutorService executor); @Override TransportChannelProvider withExecutor(Executor executor); @Override @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") boolean needsHeaders(); @Override @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") TransportChannelProvider withHeaders(Map<String, String> headers); @Override String getTransportName(); @Override boolean needsEndpoint(); @Override TransportChannelProvider withEndpoint(String endpoint); @Override @BetaApi("The surface for customizing pool size is not stable yet and may change in the future.") boolean acceptsPoolSize(); @Override @BetaApi("The surface for customizing pool size is not stable yet and may change in the future.") TransportChannelProvider withPoolSize(int size); @Override boolean needsCredentials(); @Override TransportChannelProvider withCredentials(Credentials credentials); @Override TransportChannel getTransportChannel(); String getEndpoint(); Duration getKeepAliveTime(); Duration getKeepAliveTimeout(); Boolean getKeepAliveWithoutCalls(); @BetaApi("The surface for maximum metadata size is not stable yet and may change in the future.") Integer getMaxInboundMetadataSize(); @Override boolean shouldAutoClose(); Builder toBuilder(); static Builder newBuilder();  }
@Test public void testWithPoolSize() throws IOException { ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1); executor.shutdown(); TransportChannelProvider provider = InstantiatingGrpcChannelProvider.newBuilder() .build() .withExecutor((Executor) executor) .withHeaders(Collections.<String, String>emptyMap()) .withEndpoint("localhost:8080"); assertThat(provider.acceptsPoolSize()).isTrue(); provider.getTransportChannel().shutdownNow(); provider = provider.withPoolSize(2); assertThat(provider.acceptsPoolSize()).isFalse(); provider.getTransportChannel().shutdownNow(); try { provider.withPoolSize(3); fail("acceptsPoolSize() returned false; we shouldn't be able to set it again"); } catch (IllegalStateException e) { } }