all: Use "keepalive time" instead of "keepalive delay"

It should have always been 'time', to match the terminology of TCP
Keepalive.
This commit is contained in:
Eric Anderson 2017-04-10 09:14:25 -07:00
parent af4982b763
commit b56a728502
6 changed files with 35 additions and 35 deletions

View File

@ -175,7 +175,7 @@ public final class GrpcUtil {
/** /**
* The default delay in nanos before we send a keepalive. * The default delay in nanos before we send a keepalive.
*/ */
public static final long DEFAULT_KEEPALIVE_DELAY_NANOS = TimeUnit.MINUTES.toNanos(1); public static final long DEFAULT_KEEPALIVE_TIME_NANOS = TimeUnit.MINUTES.toNanos(1);
/** /**
* The default timeout in nanos for a keepalive ping request. * The default timeout in nanos for a keepalive ping request.

View File

@ -45,7 +45,7 @@ import java.util.concurrent.TimeUnit;
*/ */
public class KeepAliveManager { public class KeepAliveManager {
private static final SystemTicker SYSTEM_TICKER = new SystemTicker(); private static final SystemTicker SYSTEM_TICKER = new SystemTicker();
private static final long MIN_KEEPALIVE_DELAY_NANOS = TimeUnit.SECONDS.toNanos(10); private static final long MIN_KEEPALIVE_TIME_NANOS = TimeUnit.SECONDS.toNanos(10);
private static final long MIN_KEEPALIVE_TIMEOUT_NANOS = TimeUnit.MICROSECONDS.toNanos(499L); private static final long MIN_KEEPALIVE_TIMEOUT_NANOS = TimeUnit.MICROSECONDS.toNanos(499L);
private final ScheduledExecutorService scheduler; private final ScheduledExecutorService scheduler;
@ -98,7 +98,7 @@ public class KeepAliveManager {
} }
}); });
private long keepAliveDelayInNanos; private long keepAliveTimeInNanos;
private long keepAliveTimeoutInNanos; private long keepAliveTimeoutInNanos;
private enum State { private enum State {
@ -134,26 +134,26 @@ public class KeepAliveManager {
* Creates a KeepAliverManager. * Creates a KeepAliverManager.
*/ */
public KeepAliveManager(KeepAlivePinger keepAlivePinger, ScheduledExecutorService scheduler, public KeepAliveManager(KeepAlivePinger keepAlivePinger, ScheduledExecutorService scheduler,
long keepAliveDelayInNanos, long keepAliveTimeoutInNanos, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos,
boolean keepAliveDuringTransportIdle) { boolean keepAliveDuringTransportIdle) {
this(keepAlivePinger, scheduler, SYSTEM_TICKER, this(keepAlivePinger, scheduler, SYSTEM_TICKER,
// Set a minimum cap on keepalive dealy. // Set a minimum cap on keepalive dealy.
Math.max(MIN_KEEPALIVE_DELAY_NANOS, keepAliveDelayInNanos), Math.max(MIN_KEEPALIVE_TIME_NANOS, keepAliveTimeInNanos),
Math.max(MIN_KEEPALIVE_TIMEOUT_NANOS, keepAliveTimeoutInNanos), Math.max(MIN_KEEPALIVE_TIMEOUT_NANOS, keepAliveTimeoutInNanos),
keepAliveDuringTransportIdle); keepAliveDuringTransportIdle);
} }
@VisibleForTesting @VisibleForTesting
KeepAliveManager(KeepAlivePinger keepAlivePinger, ScheduledExecutorService scheduler, KeepAliveManager(KeepAlivePinger keepAlivePinger, ScheduledExecutorService scheduler,
Ticker ticker, long keepAliveDelayInNanos, long keepAliveTimeoutInNanos, Ticker ticker, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos,
boolean keepAliveDuringTransportIdle) { boolean keepAliveDuringTransportIdle) {
this.keepAlivePinger = checkNotNull(keepAlivePinger, "keepAlivePinger"); this.keepAlivePinger = checkNotNull(keepAlivePinger, "keepAlivePinger");
this.scheduler = checkNotNull(scheduler, "scheduler"); this.scheduler = checkNotNull(scheduler, "scheduler");
this.ticker = checkNotNull(ticker, "ticker"); this.ticker = checkNotNull(ticker, "ticker");
this.keepAliveDelayInNanos = keepAliveDelayInNanos; this.keepAliveTimeInNanos = keepAliveTimeInNanos;
this.keepAliveTimeoutInNanos = keepAliveTimeoutInNanos; this.keepAliveTimeoutInNanos = keepAliveTimeoutInNanos;
this.keepAliveDuringTransportIdle = keepAliveDuringTransportIdle; this.keepAliveDuringTransportIdle = keepAliveDuringTransportIdle;
nextKeepaliveTime = ticker.read() + keepAliveDelayInNanos; nextKeepaliveTime = ticker.read() + keepAliveTimeInNanos;
} }
/** Start keepalive monitoring. */ /** Start keepalive monitoring. */
@ -167,7 +167,7 @@ public class KeepAliveManager {
* Transport has received some data so that we can delay sending keepalives. * Transport has received some data so that we can delay sending keepalives.
*/ */
public synchronized void onDataReceived() { public synchronized void onDataReceived() {
nextKeepaliveTime = ticker.read() + keepAliveDelayInNanos; nextKeepaliveTime = ticker.read() + keepAliveTimeInNanos;
// We do not cancel the ping future here. This avoids constantly scheduling and cancellation in // We do not cancel the ping future here. This avoids constantly scheduling and cancellation in
// a busy transport. Instead, we update the status here and reschedule later. So we actually // a busy transport. Instead, we update the status here and reschedule later. So we actually
// keep one sendPing task always in flight when there're active rpcs. // keep one sendPing task always in flight when there're active rpcs.
@ -187,7 +187,7 @@ public class KeepAliveManager {
// schedule a new ping // schedule a new ping
state = State.PING_SCHEDULED; state = State.PING_SCHEDULED;
pingFuture = pingFuture =
scheduler.schedule(sendPing, keepAliveDelayInNanos, TimeUnit.NANOSECONDS); scheduler.schedule(sendPing, keepAliveTimeInNanos, TimeUnit.NANOSECONDS);
} }
} }

View File

@ -34,8 +34,8 @@ package io.grpc.netty;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static io.grpc.internal.GrpcUtil.DEFAULT_KEEPALIVE_DELAY_NANOS;
import static io.grpc.internal.GrpcUtil.DEFAULT_KEEPALIVE_TIMEOUT_NANOS; import static io.grpc.internal.GrpcUtil.DEFAULT_KEEPALIVE_TIMEOUT_NANOS;
import static io.grpc.internal.GrpcUtil.DEFAULT_KEEPALIVE_TIME_NANOS;
import static io.grpc.internal.GrpcUtil.KEEPALIVE_TIME_NANOS_DISABLED; import static io.grpc.internal.GrpcUtil.KEEPALIVE_TIME_NANOS_DISABLED;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -252,7 +252,7 @@ public final class NettyChannelBuilder
@Deprecated @Deprecated
public final NettyChannelBuilder enableKeepAlive(boolean enable) { public final NettyChannelBuilder enableKeepAlive(boolean enable) {
if (enable) { if (enable) {
return keepAliveTime(DEFAULT_KEEPALIVE_DELAY_NANOS, TimeUnit.NANOSECONDS); return keepAliveTime(DEFAULT_KEEPALIVE_TIME_NANOS, TimeUnit.NANOSECONDS);
} }
return keepAliveTime(KEEPALIVE_TIME_NANOS_DISABLED, TimeUnit.NANOSECONDS); return keepAliveTime(KEEPALIVE_TIME_NANOS_DISABLED, TimeUnit.NANOSECONDS);
} }
@ -263,10 +263,10 @@ public final class NettyChannelBuilder
* @deprecated Please use {@link #keepAliveTime} and {@link #keepAliveTimeout} instead * @deprecated Please use {@link #keepAliveTime} and {@link #keepAliveTimeout} instead
*/ */
@Deprecated @Deprecated
public final NettyChannelBuilder enableKeepAlive(boolean enable, long keepAliveDelay, public final NettyChannelBuilder enableKeepAlive(boolean enable, long keepAliveTime,
TimeUnit delayUnit, long keepAliveTimeout, TimeUnit timeoutUnit) { TimeUnit delayUnit, long keepAliveTimeout, TimeUnit timeoutUnit) {
if (enable) { if (enable) {
return keepAliveTime(keepAliveDelay, delayUnit) return keepAliveTime(keepAliveTime, delayUnit)
.keepAliveTimeout(keepAliveTimeout, timeoutUnit); .keepAliveTimeout(keepAliveTimeout, timeoutUnit);
} }
return keepAliveTime(KEEPALIVE_TIME_NANOS_DISABLED, TimeUnit.NANOSECONDS); return keepAliveTime(KEEPALIVE_TIME_NANOS_DISABLED, TimeUnit.NANOSECONDS);
@ -451,7 +451,7 @@ public final class NettyChannelBuilder
private final int flowControlWindow; private final int flowControlWindow;
private final int maxMessageSize; private final int maxMessageSize;
private final int maxHeaderListSize; private final int maxHeaderListSize;
private final long keepAliveDelayNanos; private final long keepAliveTimeNanos;
private final long keepAliveTimeoutNanos; private final long keepAliveTimeoutNanos;
private final boolean keepAliveWithoutCalls; private final boolean keepAliveWithoutCalls;
@ -461,7 +461,7 @@ public final class NettyChannelBuilder
Class<? extends Channel> channelType, Map<ChannelOption<?>, ?> channelOptions, Class<? extends Channel> channelType, Map<ChannelOption<?>, ?> channelOptions,
NegotiationType negotiationType, SslContext sslContext, EventLoopGroup group, NegotiationType negotiationType, SslContext sslContext, EventLoopGroup group,
int flowControlWindow, int maxMessageSize, int maxHeaderListSize, int flowControlWindow, int maxMessageSize, int maxHeaderListSize,
long keepAliveDelayNanos, long keepAliveTimeoutNanos, boolean keepAliveWithoutCalls) { long keepAliveTimeNanos, long keepAliveTimeoutNanos, boolean keepAliveWithoutCalls) {
this.channelType = channelType; this.channelType = channelType;
this.negotiationType = negotiationType; this.negotiationType = negotiationType;
this.channelOptions = new HashMap<ChannelOption<?>, Object>(channelOptions); this.channelOptions = new HashMap<ChannelOption<?>, Object>(channelOptions);
@ -481,7 +481,7 @@ public final class NettyChannelBuilder
this.flowControlWindow = flowControlWindow; this.flowControlWindow = flowControlWindow;
this.maxMessageSize = maxMessageSize; this.maxMessageSize = maxMessageSize;
this.maxHeaderListSize = maxHeaderListSize; this.maxHeaderListSize = maxHeaderListSize;
this.keepAliveDelayNanos = keepAliveDelayNanos; this.keepAliveTimeNanos = keepAliveTimeNanos;
this.keepAliveTimeoutNanos = keepAliveTimeoutNanos; this.keepAliveTimeoutNanos = keepAliveTimeoutNanos;
this.keepAliveWithoutCalls = keepAliveWithoutCalls; this.keepAliveWithoutCalls = keepAliveWithoutCalls;
usingSharedGroup = group == null; usingSharedGroup = group == null;
@ -504,7 +504,7 @@ public final class NettyChannelBuilder
NettyClientTransport transport = new NettyClientTransport( NettyClientTransport transport = new NettyClientTransport(
dparams.getTargetServerAddress(), channelType, channelOptions, group, dparams.getTargetServerAddress(), channelType, channelOptions, group,
dparams.getProtocolNegotiator(), flowControlWindow, dparams.getProtocolNegotiator(), flowControlWindow,
maxMessageSize, maxHeaderListSize, keepAliveDelayNanos, keepAliveTimeoutNanos, maxMessageSize, maxHeaderListSize, keepAliveTimeNanos, keepAliveTimeoutNanos,
keepAliveWithoutCalls, dparams.getAuthority(), dparams.getUserAgent()); keepAliveWithoutCalls, dparams.getAuthority(), dparams.getUserAgent());
return transport; return transport;
} }

View File

@ -84,7 +84,7 @@ class NettyClientTransport implements ConnectionClientTransport {
private final int maxMessageSize; private final int maxMessageSize;
private final int maxHeaderListSize; private final int maxHeaderListSize;
private KeepAliveManager keepAliveManager; private KeepAliveManager keepAliveManager;
private final long keepAliveDelayNanos; private final long keepAliveTimeNanos;
private final long keepAliveTimeoutNanos; private final long keepAliveTimeoutNanos;
private final boolean keepAliveWithoutCalls; private final boolean keepAliveWithoutCalls;
@ -102,7 +102,7 @@ class NettyClientTransport implements ConnectionClientTransport {
SocketAddress address, Class<? extends Channel> channelType, SocketAddress address, Class<? extends Channel> channelType,
Map<ChannelOption<?>, ?> channelOptions, EventLoopGroup group, Map<ChannelOption<?>, ?> channelOptions, EventLoopGroup group,
ProtocolNegotiator negotiator, int flowControlWindow, int maxMessageSize, ProtocolNegotiator negotiator, int flowControlWindow, int maxMessageSize,
int maxHeaderListSize, long keepAliveDelayNanos, long keepAliveTimeoutNanos, int maxHeaderListSize, long keepAliveTimeNanos, long keepAliveTimeoutNanos,
boolean keepAliveWithoutCalls, String authority, @Nullable String userAgent) { boolean keepAliveWithoutCalls, String authority, @Nullable String userAgent) {
this.negotiator = Preconditions.checkNotNull(negotiator, "negotiator"); this.negotiator = Preconditions.checkNotNull(negotiator, "negotiator");
this.address = Preconditions.checkNotNull(address, "address"); this.address = Preconditions.checkNotNull(address, "address");
@ -112,7 +112,7 @@ class NettyClientTransport implements ConnectionClientTransport {
this.flowControlWindow = flowControlWindow; this.flowControlWindow = flowControlWindow;
this.maxMessageSize = maxMessageSize; this.maxMessageSize = maxMessageSize;
this.maxHeaderListSize = maxHeaderListSize; this.maxHeaderListSize = maxHeaderListSize;
this.keepAliveDelayNanos = keepAliveDelayNanos; this.keepAliveTimeNanos = keepAliveTimeNanos;
this.keepAliveTimeoutNanos = keepAliveTimeoutNanos; this.keepAliveTimeoutNanos = keepAliveTimeoutNanos;
this.keepAliveWithoutCalls = keepAliveWithoutCalls; this.keepAliveWithoutCalls = keepAliveWithoutCalls;
this.authority = new AsciiString(authority); this.authority = new AsciiString(authority);
@ -177,9 +177,9 @@ class NettyClientTransport implements ConnectionClientTransport {
lifecycleManager = new ClientTransportLifecycleManager( lifecycleManager = new ClientTransportLifecycleManager(
Preconditions.checkNotNull(transportListener, "listener")); Preconditions.checkNotNull(transportListener, "listener"));
EventLoop eventLoop = group.next(); EventLoop eventLoop = group.next();
if (keepAliveDelayNanos != KEEPALIVE_TIME_NANOS_DISABLED) { if (keepAliveTimeNanos != KEEPALIVE_TIME_NANOS_DISABLED) {
keepAliveManager = new KeepAliveManager( keepAliveManager = new KeepAliveManager(
new ClientKeepAlivePinger(this), eventLoop, keepAliveDelayNanos, keepAliveTimeoutNanos, new ClientKeepAlivePinger(this), eventLoop, keepAliveTimeNanos, keepAliveTimeoutNanos,
keepAliveWithoutCalls); keepAliveWithoutCalls);
} }

View File

@ -31,8 +31,8 @@
package io.grpc.okhttp; package io.grpc.okhttp;
import static io.grpc.internal.GrpcUtil.DEFAULT_KEEPALIVE_DELAY_NANOS;
import static io.grpc.internal.GrpcUtil.DEFAULT_KEEPALIVE_TIMEOUT_NANOS; import static io.grpc.internal.GrpcUtil.DEFAULT_KEEPALIVE_TIMEOUT_NANOS;
import static io.grpc.internal.GrpcUtil.DEFAULT_KEEPALIVE_TIME_NANOS;
import static io.grpc.internal.GrpcUtil.KEEPALIVE_TIME_NANOS_DISABLED; import static io.grpc.internal.GrpcUtil.KEEPALIVE_TIME_NANOS_DISABLED;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -164,7 +164,7 @@ public class OkHttpChannelBuilder extends
@Deprecated @Deprecated
public final OkHttpChannelBuilder enableKeepAlive(boolean enable) { public final OkHttpChannelBuilder enableKeepAlive(boolean enable) {
if (enable) { if (enable) {
return keepAliveTime(DEFAULT_KEEPALIVE_DELAY_NANOS, TimeUnit.NANOSECONDS); return keepAliveTime(DEFAULT_KEEPALIVE_TIME_NANOS, TimeUnit.NANOSECONDS);
} else { } else {
return keepAliveTime(KEEPALIVE_TIME_NANOS_DISABLED, TimeUnit.NANOSECONDS); return keepAliveTime(KEEPALIVE_TIME_NANOS_DISABLED, TimeUnit.NANOSECONDS);
} }
@ -176,10 +176,10 @@ public class OkHttpChannelBuilder extends
* @deprecated Use {@link #keepAliveTime} and {@link #keepAliveTimeout} instead * @deprecated Use {@link #keepAliveTime} and {@link #keepAliveTimeout} instead
*/ */
@Deprecated @Deprecated
public final OkHttpChannelBuilder enableKeepAlive(boolean enable, long keepAliveDelay, public final OkHttpChannelBuilder enableKeepAlive(boolean enable, long keepAliveTime,
TimeUnit delayUnit, long keepAliveTimeout, TimeUnit timeoutUnit) { TimeUnit delayUnit, long keepAliveTimeout, TimeUnit timeoutUnit) {
if (enable) { if (enable) {
return keepAliveTime(keepAliveDelay, delayUnit) return keepAliveTime(keepAliveTime, delayUnit)
.keepAliveTimeout(keepAliveTimeout, timeoutUnit); .keepAliveTimeout(keepAliveTimeout, timeoutUnit);
} else { } else {
return keepAliveTime(KEEPALIVE_TIME_NANOS_DISABLED, TimeUnit.NANOSECONDS); return keepAliveTime(KEEPALIVE_TIME_NANOS_DISABLED, TimeUnit.NANOSECONDS);
@ -360,7 +360,7 @@ public class OkHttpChannelBuilder extends
private final ConnectionSpec connectionSpec; private final ConnectionSpec connectionSpec;
private final int maxMessageSize; private final int maxMessageSize;
private final boolean enableKeepAlive; private final boolean enableKeepAlive;
private final long keepAliveDelayNanos; private final long keepAliveTimeNanos;
private final long keepAliveTimeoutNanos; private final long keepAliveTimeoutNanos;
private final boolean keepAliveWithoutCalls; private final boolean keepAliveWithoutCalls;
private boolean closed; private boolean closed;
@ -370,14 +370,14 @@ public class OkHttpChannelBuilder extends
ConnectionSpec connectionSpec, ConnectionSpec connectionSpec,
int maxMessageSize, int maxMessageSize,
boolean enableKeepAlive, boolean enableKeepAlive,
long keepAliveDelayNanos, long keepAliveTimeNanos,
long keepAliveTimeoutNanos, long keepAliveTimeoutNanos,
boolean keepAliveWithoutCalls) { boolean keepAliveWithoutCalls) {
this.socketFactory = socketFactory; this.socketFactory = socketFactory;
this.connectionSpec = connectionSpec; this.connectionSpec = connectionSpec;
this.maxMessageSize = maxMessageSize; this.maxMessageSize = maxMessageSize;
this.enableKeepAlive = enableKeepAlive; this.enableKeepAlive = enableKeepAlive;
this.keepAliveDelayNanos = keepAliveDelayNanos; this.keepAliveTimeNanos = keepAliveTimeNanos;
this.keepAliveTimeoutNanos = keepAliveTimeoutNanos; this.keepAliveTimeoutNanos = keepAliveTimeoutNanos;
this.keepAliveWithoutCalls = keepAliveWithoutCalls; this.keepAliveWithoutCalls = keepAliveWithoutCalls;
@ -412,7 +412,7 @@ public class OkHttpChannelBuilder extends
proxyAddress, null, null); proxyAddress, null, null);
if (enableKeepAlive) { if (enableKeepAlive) {
transport.enableKeepAlive( transport.enableKeepAlive(
true, keepAliveDelayNanos, keepAliveTimeoutNanos, keepAliveWithoutCalls); true, keepAliveTimeNanos, keepAliveTimeoutNanos, keepAliveWithoutCalls);
} }
return transport; return transport;
} }

View File

@ -181,7 +181,7 @@ class OkHttpClientTransport implements ConnectionClientTransport {
private ScheduledExecutorService scheduler; private ScheduledExecutorService scheduler;
private KeepAliveManager keepAliveManager; private KeepAliveManager keepAliveManager;
private boolean enableKeepAlive; private boolean enableKeepAlive;
private long keepAliveDelayNanos; private long keepAliveTimeNanos;
private long keepAliveTimeoutNanos; private long keepAliveTimeoutNanos;
private boolean keepAliveWithoutCalls; private boolean keepAliveWithoutCalls;
@Nullable @Nullable
@ -246,10 +246,10 @@ class OkHttpClientTransport implements ConnectionClientTransport {
/** /**
* Enable keepalive with custom delay and timeout. * Enable keepalive with custom delay and timeout.
*/ */
void enableKeepAlive(boolean enable, long keepAliveDelayNanos, void enableKeepAlive(boolean enable, long keepAliveTimeNanos,
long keepAliveTimeoutNanos, boolean keepAliveWithoutCalls) { long keepAliveTimeoutNanos, boolean keepAliveWithoutCalls) {
enableKeepAlive = enable; enableKeepAlive = enable;
this.keepAliveDelayNanos = keepAliveDelayNanos; this.keepAliveTimeNanos = keepAliveTimeNanos;
this.keepAliveTimeoutNanos = keepAliveTimeoutNanos; this.keepAliveTimeoutNanos = keepAliveTimeoutNanos;
this.keepAliveWithoutCalls = keepAliveWithoutCalls; this.keepAliveWithoutCalls = keepAliveWithoutCalls;
} }
@ -373,7 +373,7 @@ class OkHttpClientTransport implements ConnectionClientTransport {
if (enableKeepAlive) { if (enableKeepAlive) {
scheduler = SharedResourceHolder.get(TIMER_SERVICE); scheduler = SharedResourceHolder.get(TIMER_SERVICE);
keepAliveManager = new KeepAliveManager( keepAliveManager = new KeepAliveManager(
new ClientKeepAlivePinger(this), scheduler, keepAliveDelayNanos, keepAliveTimeoutNanos, new ClientKeepAlivePinger(this), scheduler, keepAliveTimeNanos, keepAliveTimeoutNanos,
keepAliveWithoutCalls); keepAliveWithoutCalls);
keepAliveManager.onTransportStarted(); keepAliveManager.onTransportStarted();
} }