Package com.fasterxml.uuid
Class TimestampSynchronizer
java.lang.Object
com.fasterxml.uuid.TimestampSynchronizer
- Direct Known Subclasses:
FileBasedTimestampSynchronizer
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidMethodUUIDTimerwill call if this synchronizer object is being replaced by another synchronizer (or removed, that is, no more synchronization is to be done).protected abstract longInitialization method is will be called on an instance byUUIDTimerright after it's been configured with one.protected abstract longupdate(long now) Method called byUUIDTimerto indicate that it has generated a timestamp value that is beyond last legal timestamp value.
-
Constructor Details
-
TimestampSynchronizer
protected TimestampSynchronizer()
-
-
Method Details
-
initialize
Initialization method is will be called on an instance byUUIDTimerright 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;
0Lif it can not determine it and caller can use whatever value (current timestamp) it has access to. - Throws:
IOException
-
deactivate
MethodUUIDTimerwill 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
Method called byUUIDTimerto 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
-