Package io.grpc.internal
Class KeepAliveEnforcer
- java.lang.Object
-
- io.grpc.internal.KeepAliveEnforcer
-
public final class KeepAliveEnforcer extends java.lang.Object
Monitors the client's PING usage to make sure the rate is permitted.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
KeepAliveEnforcer.SystemTicker
(package private) static interface
KeepAliveEnforcer.Ticker
-
Field Summary
Fields Modifier and Type Field Description private long
epoch
private boolean
hasOutstandingCalls
static long
IMPLICIT_PERMIT_TIME_NANOS
private long
lastValidPingTime
static int
MAX_PING_STRIKES
private long
minTimeNanos
private boolean
permitWithoutCalls
private int
pingStrikes
private KeepAliveEnforcer.Ticker
ticker
-
Constructor Summary
Constructors Constructor Description KeepAliveEnforcer(boolean permitWithoutCalls, long minTime, java.util.concurrent.TimeUnit unit)
KeepAliveEnforcer(boolean permitWithoutCalls, long minTime, java.util.concurrent.TimeUnit unit, KeepAliveEnforcer.Ticker ticker)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static long
compareNanos(long time1, long time2)
Positive when time1 is greater; negative when time2 is greater; 0 when equal.void
onTransportActive()
There are outstanding RPCs on the transport.void
onTransportIdle()
There are no outstanding RPCs on the transport.boolean
pingAcceptable()
Returnsfalse
when client is misbehaving and should be disconnected.void
resetCounters()
Reset any counters because PINGs are allowed in response to something sent.
-
-
-
Field Detail
-
MAX_PING_STRIKES
public static final int MAX_PING_STRIKES
- See Also:
- Constant Field Values
-
IMPLICIT_PERMIT_TIME_NANOS
public static final long IMPLICIT_PERMIT_TIME_NANOS
-
permitWithoutCalls
private final boolean permitWithoutCalls
-
minTimeNanos
private final long minTimeNanos
-
ticker
private final KeepAliveEnforcer.Ticker ticker
-
epoch
private final long epoch
-
lastValidPingTime
private long lastValidPingTime
-
hasOutstandingCalls
private boolean hasOutstandingCalls
-
pingStrikes
private int pingStrikes
-
-
Constructor Detail
-
KeepAliveEnforcer
public KeepAliveEnforcer(boolean permitWithoutCalls, long minTime, java.util.concurrent.TimeUnit unit)
-
KeepAliveEnforcer
KeepAliveEnforcer(boolean permitWithoutCalls, long minTime, java.util.concurrent.TimeUnit unit, KeepAliveEnforcer.Ticker ticker)
-
-
Method Detail
-
pingAcceptable
@CheckReturnValue public boolean pingAcceptable()
Returnsfalse
when client is misbehaving and should be disconnected.
-
resetCounters
public void resetCounters()
Reset any counters because PINGs are allowed in response to something sent. Typically called when sending HEADERS and DATA frames.
-
onTransportActive
public void onTransportActive()
There are outstanding RPCs on the transport.
-
onTransportIdle
public void onTransportIdle()
There are no outstanding RPCs on the transport.
-
compareNanos
private static long compareNanos(long time1, long time2)
Positive when time1 is greater; negative when time2 is greater; 0 when equal. It is important to use something like this instead of directly comparing nano times. SeeSystem.nanoTime()
.
-
-