Class RequestIDSequence


  • final class RequestIDSequence
    extends java.lang.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 int INCREMENT_BITS
      Bits devoted to incremented values.
      private static java.util.concurrent.locks.Lock LOCK
      Internal lock.
      private static long MASK
      Max bits mask.
      private static int MAX_BITS
      Maximum number of bits available for representing request IDs, according to the XEP-0124 spec.s
      private static long MAX_INITIAL
      Max initial value.
      private static long MIN_INCREMENTS
      Minimum number of times the initial RID can be incremented before exceeding the maximum.
      private java.util.concurrent.atomic.AtomicLong nextRequestID
      The last reqest ID used, or <= 0 if a new request ID needs to be generated.
      private static java.security.SecureRandom RAND
      Random number generator.
    • Constructor Summary

      Constructors 
      Constructor Description
      RequestIDSequence()
      Prevent direct construction.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      long getNextRID()
      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 Detail

      • 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:
        Constant Field Values
      • INCREMENT_BITS

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

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

        private static final java.security.SecureRandom RAND
        Random number generator.
      • LOCK

        private static final java.util.concurrent.locks.Lock LOCK
        Internal lock.
      • nextRequestID

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

      • RequestIDSequence

        RequestIDSequence()
        Prevent direct construction.
    • Method Detail

      • 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