Class TimeBasedGenerator


public class TimeBasedGenerator extends NoArgGenerator
Implementation of UUID generator that uses time/location based generation method (version 1).

As all JUG provided implementations, this generator is fully thread-safe. Additionally, it can also be made externally synchronized with other instances (even ones running on other JVMs); to do this, use FileBasedTimestampSynchronizer (or equivalent).

Since:
3.0
  • Field Details

    • _ethernetAddress

      protected final EthernetAddress _ethernetAddress
    • _timer

      protected final UUIDTimer _timer
      Object used for synchronizing access to timestamps, to guarantee that timestamps produced by this generator are unique and monotonically increasings. Some implementations offer even stronger guarantees, for example that same guarantee holds between instances running on different JVMs (or with native code).
    • _uuidL2

      protected final long _uuidL2
      Base values for the second long (last 8 bytes) of UUID to construct
  • Constructor Details

    • TimeBasedGenerator

      public TimeBasedGenerator(EthernetAddress ethAddr, UUIDTimer timer)
      Parameters:
      ethAddr - Hardware address (802.1) to use for generating spatially unique part of UUID. If system has more than one NIC,
  • Method Details

    • getType

      public UUIDType getType()
      Description copied from class: UUIDGenerator
      Accessor for determining type of UUIDs (version) that this generator instance will produce.
      Specified by:
      getType in class UUIDGenerator
    • getEthernetAddress

      public EthernetAddress getEthernetAddress()
    • generate

      public UUID generate()
      Description copied from class: NoArgGenerator
      Method for generating a UUID.
      Specified by:
      generate in class NoArgGenerator
      Returns:
      Newly generated UUID
    • construct

      public UUID construct(long rawTimestamp)
      Method that will construct actual UUID instance for given timestamp: called by generate() but may alternatively be called directly to construct an instance with known timestamp. NOTE: calling this method directly does NOT guarantee uniqueness of resulting UUID (caller has to guarantee uniqueness)
      Parameters:
      rawTimestamp - Timestamp usually obtained from UUIDTimer.getTimestamp(), used for constructing UUID instance
      Returns:
      unix Time-based UUID constructed for given timestamp
      Since:
      4.3