Class ClockSeqFunction.ClockSeqPool

  • Enclosing interface:
    ClockSeqFunction

    public static final class ClockSeqFunction.ClockSeqPool
    extends Object
    Nested class that manages a pool of 16384 clock sequence values.

    The pool is implemented as an array of 2048 bytes (16384 bits). Each bit of the array corresponds to a clock sequence value.

    It is used to avoid that two time-based factories use the same clock sequence at same time in a class loader.

    • Constructor Detail

      • ClockSeqPool

        public ClockSeqPool()
    • Method Detail

      • take

        public int take​(int take)
        Take a value from the pool.

        If the value to be taken is already in use, it is incremented until a free value is found and returned.

        In the case that all pool values are in use, the pool is cleared and the last incremented value is returned.

        It does nothing to negative arguments.

        Parameters:
        take - value to be taken from the pool
        Returns:
        the value to be borrowed if not used
      • random

        public int random()
        Take a random value from the pool.
        Returns:
        the random value to be borrowed if not used
      • isUsed

        public boolean isUsed​(int value)
        Check if a value is used out of the pool.
        Parameters:
        value - a value to be checked in the pool
        Returns:
        true if the value is used
      • isFree

        public boolean isFree​(int value)
        Check if a value is free in the pool.
        Parameters:
        value - a value to be checked in the pool
        Returns:
        true if the value is free
      • countUsed

        public int countUsed()
        Count the used values out of the pool
        Returns:
        the count of used values
      • countFree

        public int countFree()
        Count the free values in the pool.
        Returns:
        the count of free values
      • clearPool

        public void clearPool()
        Clear all bits of the byte array that represents the pool.

        This corresponds to marking all pool values as free