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 intBits devoted to incremented values.private static final LockInternal lock.private static final longMax bits mask.private static final intMaximum number of bits available for representing request IDs, according to the XEP-0124 spec.sprivate static final longMax initial value.private static final longMinimum number of times the initial RID can be incremented before exceeding the maximum.private AtomicLongThe last reqest ID used, or <= 0 if a new request ID needs to be generated.private static final SecureRandomRandom number generator. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate longGenerates an initial RID value by generating numbers until a number is found which is smaller than the maximum allowed value and greater than zero.longCalculates 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
-