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.
*/
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.

View File

@ -45,7 +45,7 @@ import java.util.concurrent.TimeUnit;
*/
public class KeepAliveManager {
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 final ScheduledExecutorService scheduler;
@ -98,7 +98,7 @@ public class KeepAliveManager {
}
});
private long keepAliveDelayInNanos;
private long keepAliveTimeInNanos;
private long keepAliveTimeoutInNanos;
private enum State {
@ -134,26 +134,26 @@ public class KeepAliveManager {
* Creates a KeepAliverManager.
*/
public KeepAliveManager(KeepAlivePinger keepAlivePinger, ScheduledExecutorService scheduler,
long keepAliveDelayInNanos, long keepAliveTimeoutInNanos,
long keepAliveTimeInNanos, long keepAliveTimeoutInNanos,
boolean keepAliveDuringTransportIdle) {
this(keepAlivePinger, scheduler, SYSTEM_TICKER,
// 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),
keepAliveDuringTransportIdle);
}
@VisibleForTesting
KeepAliveManager(KeepAlivePinger keepAlivePinger, ScheduledExecutorService scheduler,
Ticker ticker, long keepAliveDelayInNanos, long keepAliveTimeoutInNanos,
Ticker ticker, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos,
boolean keepAliveDuringTransportIdle) {
this.keepAlivePinger = checkNotNull(keepAlivePinger, "keepAlivePinger");
this.scheduler = checkNotNull(scheduler, "scheduler");
this.ticker = checkNotNull(ticker, "ticker");
this.keepAliveDelayInNanos = keepAliveDelayInNanos;
this.keepAliveTimeInNanos = keepAliveTimeInNanos;
this.keepAliveTimeoutInNanos = keepAliveTimeoutInNanos;
this.keepAliveDuringTransportIdle = keepAliveDuringTransportIdle;
nextKeepaliveTime = ticker.read() + keepAliveDelayInNanos;
nextKeepaliveTime = ticker.read() + keepAliveTimeInNanos;
}
/** Start keepalive monitoring. */
@ -167,7 +167,7 @@ public class KeepAliveManager {
* Transport has received some data so that we can delay sending keepalives.
*/
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
// 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.
@ -187,7 +187,7 @@ public class KeepAliveManager {
// schedule a new ping
state = State.PING_SCHEDULED;
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.checkNotNull;
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_TIME_NANOS;
import static io.grpc.internal.GrpcUtil.KEEPALIVE_TIME_NANOS_DISABLED;
import com.google.common.annotations.VisibleForTesting;
@ -252,7 +252,7 @@ public final class NettyChannelBuilder
@Deprecated
public final NettyChannelBuilder enableKeepAlive(boolean 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);
}
@ -263,10 +263,10 @@ public final class NettyChannelBuilder
* @deprecated Please use {@link #keepAliveTime} and {@link #keepAliveTimeout} instead
*/
@Deprecated
public final NettyChannelBuilder enableKeepAlive(boolean enable, long keepAliveDelay,
public final NettyChannelBuilder enableKeepAlive(boolean enable, long keepAliveTime,
TimeUnit delayUnit, long keepAliveTimeout, TimeUnit timeoutUnit) {
if (enable) {
return keepAliveTime(keepAliveDelay, delayUnit)
return keepAliveTime(keepAliveTime, delayUnit)
.keepAliveTimeout(keepAliveTimeout, timeoutUnit);
}
return keepAliveTime(KEEPALIVE_TIME_NANOS_DISABLED, TimeUnit.NANOSECONDS);
@ -451,7 +451,7 @@ public final class NettyChannelBuilder
private final int flowControlWindow;
private final int maxMessageSize;
private final int maxHeaderListSize;
private final long keepAliveDelayNanos;
private final long keepAliveTimeNanos;
private final long keepAliveTimeoutNanos;
private final boolean keepAliveWithoutCalls;
@ -461,7 +461,7 @@ public final class NettyChannelBuilder
Class<? extends Channel> channelType, Map<ChannelOption<?>, ?> channelOptions,
NegotiationType negotiationType, SslContext sslContext, EventLoopGroup group,
int flowControlWindow, int maxMessageSize, int maxHeaderListSize,
long keepAliveDelayNanos, long keepAliveTimeoutNanos, boolean keepAliveWithoutCalls) {
long keepAliveTimeNanos, long keepAliveTimeoutNanos, boolean keepAliveWithoutCalls) {
this.channelType = channelType;
this.negotiationType = negotiationType;
this.channelOptions = new HashMap<ChannelOption<?>, Object>(channelOptions);
@ -481,7 +481,7 @@ public final class NettyChannelBuilder
this.flowControlWindow = flowControlWindow;
this.maxMessageSize = maxMessageSize;
this.maxHeaderListSize = maxHeaderListSize;
this.keepAliveDelayNanos = keepAliveDelayNanos;
this.keepAliveTimeNanos = keepAliveTimeNanos;
this.keepAliveTimeoutNanos = keepAliveTimeoutNanos;
this.keepAliveWithoutCalls = keepAliveWithoutCalls;
usingSharedGroup = group == null;
@ -504,7 +504,7 @@ public final class NettyChannelBuilder
NettyClientTransport transport = new NettyClientTransport(
dparams.getTargetServerAddress(), channelType, channelOptions, group,
dparams.getProtocolNegotiator(), flowControlWindow,
maxMessageSize, maxHeaderListSize, keepAliveDelayNanos, keepAliveTimeoutNanos,
maxMessageSize, maxHeaderListSize, keepAliveTimeNanos, keepAliveTimeoutNanos,
keepAliveWithoutCalls, dparams.getAuthority(), dparams.getUserAgent());
return transport;
}

View File

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

View File

@ -31,8 +31,8 @@
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_TIME_NANOS;
import static io.grpc.internal.GrpcUtil.KEEPALIVE_TIME_NANOS_DISABLED;
import com.google.common.annotations.VisibleForTesting;
@ -164,7 +164,7 @@ public class OkHttpChannelBuilder extends
@Deprecated
public final OkHttpChannelBuilder enableKeepAlive(boolean enable) {
if (enable) {
return keepAliveTime(DEFAULT_KEEPALIVE_DELAY_NANOS, TimeUnit.NANOSECONDS);
return keepAliveTime(DEFAULT_KEEPALIVE_TIME_NANOS, TimeUnit.NANOSECONDS);
} else {
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
public final OkHttpChannelBuilder enableKeepAlive(boolean enable, long keepAliveDelay,
public final OkHttpChannelBuilder enableKeepAlive(boolean enable, long keepAliveTime,
TimeUnit delayUnit, long keepAliveTimeout, TimeUnit timeoutUnit) {
if (enable) {
return keepAliveTime(keepAliveDelay, delayUnit)
return keepAliveTime(keepAliveTime, delayUnit)
.keepAliveTimeout(keepAliveTimeout, timeoutUnit);
} else {
return keepAliveTime(KEEPALIVE_TIME_NANOS_DISABLED, TimeUnit.NANOSECONDS);
@ -360,7 +360,7 @@ public class OkHttpChannelBuilder extends
private final ConnectionSpec connectionSpec;
private final int maxMessageSize;
private final boolean enableKeepAlive;
private final long keepAliveDelayNanos;
private final long keepAliveTimeNanos;
private final long keepAliveTimeoutNanos;
private final boolean keepAliveWithoutCalls;
private boolean closed;
@ -370,14 +370,14 @@ public class OkHttpChannelBuilder extends
ConnectionSpec connectionSpec,
int maxMessageSize,
boolean enableKeepAlive,
long keepAliveDelayNanos,
long keepAliveTimeNanos,
long keepAliveTimeoutNanos,
boolean keepAliveWithoutCalls) {
this.socketFactory = socketFactory;
this.connectionSpec = connectionSpec;
this.maxMessageSize = maxMessageSize;
this.enableKeepAlive = enableKeepAlive;
this.keepAliveDelayNanos = keepAliveDelayNanos;
this.keepAliveTimeNanos = keepAliveTimeNanos;
this.keepAliveTimeoutNanos = keepAliveTimeoutNanos;
this.keepAliveWithoutCalls = keepAliveWithoutCalls;
@ -412,7 +412,7 @@ public class OkHttpChannelBuilder extends
proxyAddress, null, null);
if (enableKeepAlive) {
transport.enableKeepAlive(
true, keepAliveDelayNanos, keepAliveTimeoutNanos, keepAliveWithoutCalls);
true, keepAliveTimeNanos, keepAliveTimeoutNanos, keepAliveWithoutCalls);
}
return transport;
}

View File

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