public class FileBasedGenerator extends InMemoryIDGenerator
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.
IDGenerator.Ordered, IDGenerator.OrderedSupport
Constructor and Description |
---|
FileBasedGenerator() |
Modifier and Type | Method and Description |
---|---|
String |
getID()
Generates and returns a new ID.
|
void |
reset() |
void |
setDirectory(String directory) |
void |
setFileName(String fileName) |
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. |
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. |
set
getIncrement
public FileBasedGenerator()
public String getID() throws IOException
IDGenerator
getID
in interface IDGenerator
getID
in class InMemoryIDGenerator
IOException
public void setDirectory(String directory)
public void setFileName(String fileName)
public void setMinimizeReads(boolean theMinimizeReads)
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.public void setNeverFail(boolean neverFail)
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.public void reset()
reset
in interface IDGenerator.Ordered
reset
in class InMemoryIDGenerator
Copyright © 2001–2017 University Health Network. All rights reserved.