diff --git a/api/src/main/java/io/grpc/ForwardingServerBuilder.java b/api/src/main/java/io/grpc/ForwardingServerBuilder.java index 8ea355de6e9..0be219bfdb3 100644 --- a/api/src/main/java/io/grpc/ForwardingServerBuilder.java +++ b/api/src/main/java/io/grpc/ForwardingServerBuilder.java @@ -133,6 +133,48 @@ public T handshakeTimeout(long timeout, TimeUnit unit) { return thisT(); } + @Override + public T keepAliveTime(long keepAliveTime, TimeUnit timeUnit) { + delegate().keepAliveTime(keepAliveTime, timeUnit); + return thisT(); + } + + @Override + public T keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit) { + delegate().keepAliveTimeout(keepAliveTimeout, timeUnit); + return thisT(); + } + + @Override + public T maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit) { + delegate().maxConnectionIdle(maxConnectionIdle, timeUnit); + return thisT(); + } + + @Override + public T maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit) { + delegate().maxConnectionAge(maxConnectionAge, timeUnit); + return thisT(); + } + + @Override + public T maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit) { + delegate().maxConnectionAgeGrace(maxConnectionAgeGrace, timeUnit); + return thisT(); + } + + @Override + public T permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit) { + delegate().permitKeepAliveTime(keepAliveTime, timeUnit); + return thisT(); + } + + @Override + public T permitKeepAliveWithoutCalls(boolean permit) { + delegate().permitKeepAliveWithoutCalls(permit); + return thisT(); + } + @Override public T maxInboundMessageSize(int bytes) { delegate().maxInboundMessageSize(bytes); diff --git a/api/src/main/java/io/grpc/ServerBuilder.java b/api/src/main/java/io/grpc/ServerBuilder.java index 6a8954b1a20..bd0d8e89a0a 100644 --- a/api/src/main/java/io/grpc/ServerBuilder.java +++ b/api/src/main/java/io/grpc/ServerBuilder.java @@ -243,6 +243,111 @@ public T handshakeTimeout(long timeout, TimeUnit unit) { throw new UnsupportedOperationException(); } + /** + * Sets the time without read activity before sending a keepalive ping. An unreasonably small + * value might be increased, and {@code Long.MAX_VALUE} nano seconds or an unreasonably large + * value will disable keepalive. The typical default is infinite when supported. + * + * @throws UnsupportedOperationException if unsupported + * @since 1.47.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/9009") + public T keepAliveTime(long keepAliveTime, TimeUnit timeUnit) { + throw new UnsupportedOperationException(); + } + + /** + * Sets a time waiting for read activity after sending a keepalive ping. If the time expires + * without any read activity on the connection, the connection is considered dead. An unreasonably + * small value might be increased. Defaults to 20 seconds when supported. + * + *

This value should be at least multiple times the RTT to allow for lost packets. + * + * @throws UnsupportedOperationException if unsupported + * @since 1.47.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/9009") + public T keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit) { + throw new UnsupportedOperationException(); + } + + /** + * Sets the maximum connection idle time, connections being idle for longer than which will be + * gracefully terminated. Idleness duration is defined since the most recent time the number of + * outstanding RPCs became zero or the connection establishment. An unreasonably small value might + * be increased. {@code Long.MAX_VALUE} nano seconds or an unreasonably large value will disable + * max connection idle. + * + * @throws UnsupportedOperationException if unsupported + * @since 1.47.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/9009") + public T maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit) { + throw new UnsupportedOperationException(); + } + + /** + * Sets the maximum connection age, connections lasting longer than which will be gracefully + * terminated. An unreasonably small value might be increased. A random jitter of +/-10% will be + * added to it. {@code Long.MAX_VALUE} nano seconds or an unreasonably large value will disable + * max connection age. + * + * @throws UnsupportedOperationException if unsupported + * @since 1.47.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/9009") + public T maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit) { + throw new UnsupportedOperationException(); + } + + /** + * Sets the grace time for the graceful connection termination. Once the max connection age + * is reached, RPCs have the grace time to complete. RPCs that do not complete in time will be + * cancelled, allowing the connection to terminate. {@code Long.MAX_VALUE} nano seconds or an + * unreasonably large value are considered infinite. + * + * @throws UnsupportedOperationException if unsupported + * @see #maxConnectionAge(long, TimeUnit) + * @since 1.47.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/9009") + public T maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit) { + throw new UnsupportedOperationException(); + } + + /** + * Specify the most aggressive keep-alive time clients are permitted to configure. The server will + * try to detect clients exceeding this rate and when detected will forcefully close the + * connection. The typical default is 5 minutes when supported. + * + *

Even though a default is defined that allows some keep-alives, clients must not use + * keep-alive without approval from the service owner. Otherwise, they may experience failures in + * the future if the service becomes more restrictive. When unthrottled, keep-alives can cause a + * significant amount of traffic and CPU usage, so clients and servers should be conservative in + * what they use and accept. + * + * @throws UnsupportedOperationException if unsupported + * @see #permitKeepAliveWithoutCalls(boolean) + * @since 1.47.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/9009") + public T permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit) { + throw new UnsupportedOperationException(); + } + + /** + * Sets whether to allow clients to send keep-alive HTTP/2 PINGs even if there are no outstanding + * RPCs on the connection. Defaults to {@code false} when supported. + * + * @throws UnsupportedOperationException if unsupported + * @see #permitKeepAliveTime(long, TimeUnit) + * @since 1.47.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/9009") + public T permitKeepAliveWithoutCalls(boolean permit) { + throw new UnsupportedOperationException(); + } + /** * Sets the maximum message size allowed to be received on the server. If not called, * defaults to 4 MiB. The default provides protection to servers who haven't considered the diff --git a/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java b/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java index c1268cfdb09..574117d0461 100644 --- a/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java +++ b/core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java @@ -148,6 +148,48 @@ public T handshakeTimeout(long timeout, TimeUnit unit) { return thisT(); } + @Override + public T keepAliveTime(long keepAliveTime, TimeUnit timeUnit) { + delegate().keepAliveTime(keepAliveTime, timeUnit); + return thisT(); + } + + @Override + public T keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit) { + delegate().keepAliveTimeout(keepAliveTimeout, timeUnit); + return thisT(); + } + + @Override + public T maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit) { + delegate().maxConnectionIdle(maxConnectionIdle, timeUnit); + return thisT(); + } + + @Override + public T maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit) { + delegate().maxConnectionAge(maxConnectionAge, timeUnit); + return thisT(); + } + + @Override + public T maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit) { + delegate().maxConnectionAgeGrace(maxConnectionAgeGrace, timeUnit); + return thisT(); + } + + @Override + public T permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit) { + delegate().permitKeepAliveTime(keepAliveTime, timeUnit); + return thisT(); + } + + @Override + public T permitKeepAliveWithoutCalls(boolean permit) { + delegate().permitKeepAliveWithoutCalls(permit); + return thisT(); + } + @Override public T maxInboundMessageSize(int bytes) { delegate().maxInboundMessageSize(bytes); diff --git a/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java b/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java index ff5553eb116..5de57c78799 100644 --- a/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java +++ b/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java @@ -490,6 +490,7 @@ public NettyServerBuilder maxInboundMetadataSize(int bytes) { * * @since 1.3.0 */ + @Override public NettyServerBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit) { checkArgument(keepAliveTime > 0L, "keepalive time must be positiveļ¼š%s", keepAliveTime); keepAliveTimeInNanos = timeUnit.toNanos(keepAliveTime); @@ -511,6 +512,7 @@ public NettyServerBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit) { * * @since 1.3.0 */ + @Override public NettyServerBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit) { checkArgument(keepAliveTimeout > 0L, "keepalive timeout must be positive: %s", keepAliveTimeout); @@ -533,6 +535,7 @@ public NettyServerBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeU * * @since 1.4.0 */ + @Override public NettyServerBuilder maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit) { checkArgument(maxConnectionIdle > 0L, "max connection idle must be positive: %s", maxConnectionIdle); @@ -554,6 +557,7 @@ public NettyServerBuilder maxConnectionIdle(long maxConnectionIdle, TimeUnit tim * * @since 1.3.0 */ + @Override public NettyServerBuilder maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit) { checkArgument(maxConnectionAge > 0L, "max connection age must be positive: %s", maxConnectionAge); @@ -576,6 +580,7 @@ public NettyServerBuilder maxConnectionAge(long maxConnectionAge, TimeUnit timeU * @see #maxConnectionAge(long, TimeUnit) * @since 1.3.0 */ + @Override public NettyServerBuilder maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit) { checkArgument(maxConnectionAgeGrace >= 0L, "max connection age grace must be non-negative: %s", maxConnectionAgeGrace); @@ -600,6 +605,7 @@ public NettyServerBuilder maxConnectionAgeGrace(long maxConnectionAgeGrace, Time * @see #permitKeepAliveWithoutCalls(boolean) * @since 1.3.0 */ + @Override public NettyServerBuilder permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit) { checkArgument(keepAliveTime >= 0, "permit keepalive time must be non-negative: %s", keepAliveTime); @@ -614,6 +620,7 @@ public NettyServerBuilder permitKeepAliveTime(long keepAliveTime, TimeUnit timeU * @see #permitKeepAliveTime(long, TimeUnit) * @since 1.3.0 */ + @Override public NettyServerBuilder permitKeepAliveWithoutCalls(boolean permit) { permitKeepAliveWithoutCalls = permit; return this;