Class FileBasedGenerator

All Implemented Interfaces:
IDGenerator, IDGenerator.Ordered

Replacement for MessageIDGenerator. You should not use this class directly, however, but wrap it into a DelegatingHiLoGenerator generator. Its primary improvement over MessageIDGenerator is that you can set path and file name.

Reading and writing to the file is thread-safe, however, you should not use the same file from different Java processes because no read/write locks are being checked.

  • Constructor Details

  • Method Details

    • getID

      public String getID() throws IOException
      Description copied from interface: IDGenerator
      Generates and returns a new ID. Note: This method must be implemented to be thread-safe.
      Specified by:
      getID in interface IDGenerator
      Overrides:
      getID in class InMemoryIDGenerator
      Returns:
      a new ID.
      Throws:
      IOException
    • setDirectory

      public void setDirectory(String directory)
    • setFileName

      public void setFileName(String fileName)
    • setMinimizeReads

      public void setMinimizeReads(boolean theMinimizeReads)
      If set to true (default is false) the generator minimizes the number of disk reads by caching the last read value. This means one less disk read per X number of IDs generated, but also means that multiple instances of this generator may clobber each other's values.
    • setNeverFail

      public void setNeverFail(boolean neverFail)
      If set to false (default is true), retrieving a new ID may fail if the ID file in the home directory can not be written/read. If set to true, failures will be ignored, which means that IDs may be repeated after a JVM restart.
    • reset

      public void reset()
      Specified by:
      reset in interface IDGenerator.Ordered
      Overrides:
      reset in class InMemoryIDGenerator