Skip to content

Commit

Permalink
Add a missing channel builder methods not copied in b687bdc
Browse files Browse the repository at this point in the history
  • Loading branch information
ejona86 committed Sep 3, 2015
1 parent b687bdc commit 6122daf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
17 changes: 16 additions & 1 deletion core/src/main/java/io/grpc/ManagedChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,25 @@ public abstract class ManagedChannelBuilder<T extends ManagedChannelBuilder<T>>
/**
* Adds interceptors that will be called before the channel performs its real work. This is
* functionally equivalent to using {@link ClientInterceptors#intercept(Channel, List)}, but while
* still having access to the original {@code ChannelImpl}.
* still having access to the original {@code ManagedChannel}.
*/
public abstract T intercept(List<ClientInterceptor> interceptors);

/**
* Adds interceptors that will be called before the channel performs its real work. This is
* functionally equivalent to using {@link ClientInterceptors#intercept(Channel,
* ClientInterceptor...)}, but while still having access to the original {@code ManagedChannel}.
*/
public abstract T intercept(ClientInterceptor... interceptors);

/**
* Provides a custom {@code User-Agent} for the application.
*
* <p>It's an optional parameter. If provided, the given agent will be prepended by the
* grpc {@code User-Agent}.
*/
public abstract T userAgent(String userAgent);

/**
* Builds a channel using the given parameters.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,19 @@ public abstract class AbstractManagedChannelImplBuilder
@Nullable
private String userAgent;

/**
* Provides a custom executor.
*
* <p>It's an optional parameter. If the user has not provided an executor when the channel is
* built, the builder will use a static cached thread pool.
*
* <p>The channel won't take ownership of the given executor. It's caller's responsibility to
* shut down the executor when it's desired.
*/
@Override
public final T executor(ExecutorService executor) {
this.executor = executor;
return thisT();
}

/**
* Adds interceptors that will be called before the channel performs its real work. This is
* functionally equivalent to using {@link io.grpc.ClientInterceptors#intercept(io.grpc.Channel,
* List)}, but while still having access to the original {@code ChannelImpl}.
*/
@Override
public final T intercept(List<ClientInterceptor> interceptors) {
this.interceptors.addAll(interceptors);
return thisT();
}

/**
* Adds interceptors that will be called before the channel performs its real work. This is
* functionally equivalent to using {@link io.grpc.ClientInterceptors#intercept(io.grpc.Channel,
* ClientInterceptor...)}, but while still having access to the original {@code ChannelImpl}.
*/
@Override
public final T intercept(ClientInterceptor... interceptors) {
return intercept(Arrays.asList(interceptors));
}
Expand All @@ -96,20 +80,13 @@ private T thisT() {
return thisT;
}

/**
* Provides a custom {@code User-Agent} for the application.
*
* <p>It's an optional parameter. If provided, the given agent will be prepended by the
* grpc {@code User-Agent}.
*/
@Override
public final T userAgent(String userAgent) {
this.userAgent = userAgent;
return thisT();
}

/**
* Builds a channel using the given parameters.
*/
@Override
public ManagedChannelImpl build() {
ClientTransportFactory transportFactory = buildTransportFactory();
return new ManagedChannelImpl(transportFactory, executor, userAgent, interceptors);
Expand Down

0 comments on commit 6122daf

Please sign in to comment.