Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
add maxInboundMessageSize settings (#264)
Browse files Browse the repository at this point in the history
Fixes #149.
  • Loading branch information
pongad authored Apr 13, 2017
1 parent a730b50 commit cd4f862
Showing 1 changed file with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Executor;
import javax.annotation.Nullable;

/**
* InstantiatingChannelProvider is a ChannelProvider which constructs a gRPC ManagedChannel with a
Expand Down Expand Up @@ -69,6 +70,7 @@ public final class InstantiatingChannelProvider implements ChannelProvider {
private final String clientLibVersion;
private final String generatorName;
private final String generatorVersion;
@Nullable private final Integer maxInboundMessageSize;

private InstantiatingChannelProvider(
ExecutorProvider executorProvider,
Expand All @@ -78,7 +80,8 @@ private InstantiatingChannelProvider(
String clientLibName,
String clientLibVersion,
String generatorName,
String generatorVersion) {
String generatorVersion,
Integer maxInboundMessageSize) {
this.executorProvider = executorProvider;
this.credentialsProvider = credentialsProvider;
this.serviceAddress = serviceAddress;
Expand All @@ -87,6 +90,7 @@ private InstantiatingChannelProvider(
this.clientLibVersion = clientLibVersion;
this.generatorName = generatorName;
this.generatorVersion = generatorVersion;
this.maxInboundMessageSize = maxInboundMessageSize;
}

@Override
Expand Down Expand Up @@ -117,10 +121,14 @@ private ManagedChannel createChannel(Executor executor) throws IOException {
interceptors.add(new ClientAuthInterceptor(credentialsProvider.getCredentials(), executor));
interceptors.add(new HeaderInterceptor(serviceHeader()));

return ManagedChannelBuilder.forAddress(serviceAddress, port)
.intercept(interceptors)
.executor(executor)
.build();
ManagedChannelBuilder builder =
ManagedChannelBuilder.forAddress(serviceAddress, port)
.intercept(interceptors)
.executor(executor);
if (maxInboundMessageSize != null) {
builder.maxInboundMessageSize(maxInboundMessageSize);
}
return builder.build();
}

/**
Expand Down Expand Up @@ -214,6 +222,7 @@ public static final class Builder {
private String clientLibVersion;
private String generatorName;
private String generatorVersion;
private Integer maxInboundMessageSize;

private Builder() {
generatorName = DEFAULT_GENERATOR_NAME;
Expand All @@ -228,6 +237,7 @@ private Builder(InstantiatingChannelProvider provider) {
this.clientLibVersion = provider.clientLibVersion;
this.generatorName = provider.generatorName;
this.generatorVersion = provider.generatorVersion;
this.maxInboundMessageSize = provider.maxInboundMessageSize;
}

/**
Expand Down Expand Up @@ -320,6 +330,17 @@ public String getGeneratorVersion() {
return generatorVersion;
}

/** The maximum message size allowed to be received on the channel. */
public Builder setMaxInboundMessageSize(Integer max) {
this.maxInboundMessageSize = max;
return this;
}

/** The maximum message size allowed to be received on the channel. */
public Integer getMaxInboundMessageSize() {
return maxInboundMessageSize;
}

public InstantiatingChannelProvider build() {
return new InstantiatingChannelProvider(
executorProvider,
Expand All @@ -329,7 +350,8 @@ public InstantiatingChannelProvider build() {
clientLibName,
clientLibVersion,
generatorName,
generatorVersion);
generatorVersion,
maxInboundMessageSize);
}
}
}

0 comments on commit cd4f862

Please sign in to comment.