Package org.igniterealtime.jbosh
Class RequestIDSequence
java.lang.Object
org.igniterealtime.jbosh.RequestIDSequence
Request ID sequence generator. This generator generates a random first
RID and then manages the sequence from there on out.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate 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.sprivate 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 -
Method Summary
Modifier and TypeMethodDescriptionprivate 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.
-
Field Details
-
MAX_BITS
private static final int MAX_BITSMaximum number of bits available for representing request IDs, according to the XEP-0124 spec.s- See Also:
-
INCREMENT_BITS
private static final int INCREMENT_BITSBits devoted to incremented values.- See Also:
-
MIN_INCREMENTS
private static final long MIN_INCREMENTSMinimum number of times the initial RID can be incremented before exceeding the maximum.- See Also:
-
MAX_INITIAL
private static final long MAX_INITIALMax initial value.- See Also:
-
MASK
private static final long MASKMax bits mask.- See Also:
-
RAND
Random number generator. -
LOCK
Internal lock. -
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
-