java.lang.Object
com.fasterxml.uuid.ext.LockedFile
Utility class used by
FileBasedTimestampSynchronizer to do
actual file access and locking.
Class stores simple timestamp values based on system time accessed
using System.currentTimeMillis(). A single timestamp
is stored into a file using RandomAccessFile in fully
synchronized mode. Value is written in ISO-Latin (ISO-8859-1)
encoding (superset of Ascii, 1 byte per char) as 16-digit hexadecimal
number, surrounded by brackets. As such, file produced should
always have exact size of 18 bytes. For extra robustness, slight
variations in number of digits are accepeted, as are white space
chars before and after bracketed value.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final intExpected file length comes from hex-timestamp (16 digits), preamble "[0x",(3 chars) and trailer "]\r\n" (2 chars, linefeed to help debugging -- in some environments, missing trailing linefeed causes problems: also, 2-char linefeed to be compatible with all standard linefeeds on MacOS, Unix and Windows).(package private) static final String(package private) static LockedFile.LoggerWrapperprivate static final org.slf4j.Logger(package private) FileChannel(package private) final File(package private) longMarker used to ensure that the timestamps stored are monotonously increasing.(package private) FileLock(package private) RandomAccessFile(package private) booleanFlag set if the original file (created before this instance was created) had size other than default size and needs to be truncated(package private) ByteBuffer(package private) static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected static voiddoDeactivate(File f, RandomAccessFile raf, FileLock lock) (package private) static voidlogging(boolean enabled) longvoidwriteStamp(long stamp)
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
logger
-
DEFAULT_LENGTH
static final int DEFAULT_LENGTHExpected file length comes from hex-timestamp (16 digits), preamble "[0x",(3 chars) and trailer "]\r\n" (2 chars, linefeed to help debugging -- in some environments, missing trailing linefeed causes problems: also, 2-char linefeed to be compatible with all standard linefeeds on MacOS, Unix and Windows).- See Also:
-
READ_ERROR
static final long READ_ERROR- See Also:
-
mFile
-
mRAFile
RandomAccessFile mRAFile -
mChannel
FileChannel mChannel -
mLock
FileLock mLock -
mWriteBuffer
ByteBuffer mWriteBuffer -
mWeirdSize
boolean mWeirdSizeFlag set if the original file (created before this instance was created) had size other than default size and needs to be truncated -
mLastTimestamp
long mLastTimestampMarker used to ensure that the timestamps stored are monotonously increasing. Shouldn't really be needed, since caller should take care of it, but let's be bit paranoid here. -
HEX_DIGITS
- See Also:
-
-
Constructor Details
-
LockedFile
LockedFile(File f) throws IOException - Throws:
IOException
-
-
Method Details
-
logging
static void logging(boolean enabled) -
deactivate
public void deactivate() -
readStamp
public long readStamp() -
writeStamp
- Throws:
IOException
-
doDeactivate
-