Class KeepAliveEnforcer


  • public final class KeepAliveEnforcer
    extends java.lang.Object
    Monitors the client's PING usage to make sure the rate is permitted.
    • Field Detail

      • IMPLICIT_PERMIT_TIME_NANOS

        public static final long IMPLICIT_PERMIT_TIME_NANOS
      • permitWithoutCalls

        private final boolean permitWithoutCalls
      • minTimeNanos

        private final long minTimeNanos
      • 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()
        Returns false 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. See System.nanoTime().