Class RequestIDSequence

java.lang.Object
org.igniterealtime.jbosh.RequestIDSequence

final class RequestIDSequence extends Object
Request ID sequence generator. This generator generates a random first RID and then manages the sequence from there on out.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    Bits devoted to incremented values.
    private static final Lock
    Internal lock.
    private static final long
    Max bits mask.
    private static final int
    Maximum number of bits available for representing request IDs, according to the XEP-0124 spec.s
    private static final long
    Max initial value.
    private static final long
    Minimum number of times the initial RID can be incremented before exceeding the maximum.
    private AtomicLong
    The last reqest ID used, or <= 0 if a new request ID needs to be generated.
    private static final SecureRandom
    Random number generator.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Prevent direct construction.
  • Method Summary

    Modifier and Type
    Method
    Description
    private long
    Generates an initial RID value by generating numbers until a number is found which is smaller than the maximum allowed value and greater than zero.
    long
    Calculates the next request ID value to use.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_BITS

      private static final int MAX_BITS
      Maximum number of bits available for representing request IDs, according to the XEP-0124 spec.s
      See Also:
    • INCREMENT_BITS

      private static final int INCREMENT_BITS
      Bits devoted to incremented values.
      See Also:
    • MIN_INCREMENTS

      private static final long MIN_INCREMENTS
      Minimum number of times the initial RID can be incremented before exceeding the maximum.
      See Also:
    • MAX_INITIAL

      private static final long MAX_INITIAL
      Max initial value.
      See Also:
    • MASK

      private static final long MASK
      Max bits mask.
      See Also:
    • RAND

      private static final SecureRandom RAND
      Random number generator.
    • LOCK

      private static final Lock LOCK
      Internal lock.
    • nextRequestID

      private AtomicLong nextRequestID
      The last reqest ID used, or <= 0 if a new request ID needs to be generated.
  • Constructor Details

    • RequestIDSequence

      RequestIDSequence()
      Prevent direct construction.
  • Method Details

    • getNextRID

      public long getNextRID()
      Calculates the next request ID value to use. This number must be initialized such that it is unlikely to ever exceed 2 ^ 53, according to XEP-0124.
      Returns:
      next request ID value
    • generateInitialValue

      private long generateInitialValue()
      Generates an initial RID value by generating numbers until a number is found which is smaller than the maximum allowed value and greater than zero.
      Returns:
      random initial value