This class generates unique ids for a resource type. For example, nodes in a nodes space are connected to each other via relationships. On nodes and relationship one can add properties. We have three different resource types here (nodes, relationships and properties) where each resource needs a unique id to be able to differ resources of the same type from each other. Creating three id generators (one for each resource type ) will do the trick.
IdGenerator
makes use of so called "defragged" ids. A defragged id is an id that has been in use one or many times but the resource that was using it doesn't exist anymore. This makes it possible to reuse the id and that in turn makes it possible to write a resource store with fixed records and size (you can calculate the position of a record by knowing the id without using indexes or a translation table).
The id returned from {@link #nextId} may not be the lowestavailable id but will be one of the defragged ids if such exist or the next new free id that has never been used.
The {@link #freeId} will not check if the id passed in to it really is free.Passing a non free id will corrupt the id generator and {@link #nextId}method will eventually return that id.
The {@link #close()} method must always be invoked when done using angenerator (for this time). Failure to do will render the generator as "sticky" and unusable next time you try to initialize a generator using the same file. There can only be one id generator instance per id generator file.
In case of disk/file I/O failure an IOException
is thrown.