Class TimestampSynchronizer

java.lang.Object
com.fasterxml.uuid.TimestampSynchronizer
Direct Known Subclasses:
FileBasedTimestampSynchronizer

public abstract class TimestampSynchronizer extends Object
This is the API for utility classes optionally used by UUIDTimer to ensure that timestamp values used for generating time/location-based UUIDs are monotonically increasing, as well as that only one such generator is ever used on a single system, even in presence of multiple JVMs.

The default implementation used by JUG is FileBasedTimestampSynchronizer.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    Method UUIDTimer will call if this synchronizer object is being replaced by another synchronizer (or removed, that is, no more synchronization is to be done).
    protected abstract long
    Initialization method is will be called on an instance by UUIDTimer right after it's been configured with one.
    protected abstract long
    update(long now)
    Method called by UUIDTimer to indicate that it has generated a timestamp value that is beyond last legal timestamp value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TimestampSynchronizer

      protected TimestampSynchronizer()
  • Method Details

    • initialize

      protected abstract long initialize() throws IOException
      Initialization method is will be called on an instance by UUIDTimer right after it's been configured with one. At this point the implementation instance should have been properly configured, and should be able to determine the first legal timestamp value (return value). Method should also initialize any locking that it does (if any), such as locking files it needs.

      Return value thus indicates the lowest initial time value that can be used by the caller that can not have been used by previous incarnations of the UUID generator (assuming instance was able to find properly persisted data to figure that out). However, caller also needs to make sure that it will call update(long) when it actually needs the time stamp for the first time, since this method can not allocate timestamps beyond this initial value at this point.

      Returns:
      First (and last) legal timestamp to use; 0L if it can not determine it and caller can use whatever value (current timestamp) it has access to.
      Throws:
      IOException
    • deactivate

      protected abstract void deactivate() throws IOException
      Method UUIDTimer will call if this synchronizer object is being replaced by another synchronizer (or removed, that is, no more synchronization is to be done). It will not be called if JVM terminates.
      Throws:
      IOException
    • update

      protected abstract long update(long now) throws IOException
      Method called by UUIDTimer to indicate that it has generated a timestamp value that is beyond last legal timestamp value. The method should only return once it has "locked" specified timestamp value (and possible additional ones).
      Parameters:
      now - Timestamp value caller wants to use, and that the synchronizer is asked to protect.
      Returns:
      First timestamp value that can NOT be used by the caller; has to be higher than the input timestamp value
      Throws:
      IOException