Class LockedFile

java.lang.Object
com.fasterxml.uuid.ext.LockedFile

class LockedFile extends Object
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.

  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • logger

      static LockedFile.LoggerWrapper logger
    • DEFAULT_LENGTH

      static final int DEFAULT_LENGTH
      Expected 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

      final File mFile
    • mRAFile

    • mChannel

      FileChannel mChannel
    • mLock

      FileLock mLock
    • mWriteBuffer

      ByteBuffer mWriteBuffer
    • mWeirdSize

      boolean mWeirdSize
      Flag set if the original file (created before this instance was created) had size other than default size and needs to be truncated
    • mLastTimestamp

      long mLastTimestamp
      Marker 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

      static final String HEX_DIGITS
      See Also:
  • Constructor Details

  • Method Details

    • logging

      static void logging(boolean enabled)
    • deactivate

      public void deactivate()
    • readStamp

      public long readStamp()
    • writeStamp

      public void writeStamp(long stamp) throws IOException
      Throws:
      IOException
    • doDeactivate

      protected static void doDeactivate(File f, RandomAccessFile raf, FileLock lock)