Package com.helger.commons.id.factory
Class FileIntIDFactory
- java.lang.Object
-
- com.helger.commons.id.factory.AbstractPersistingIntIDFactory
-
- com.helger.commons.id.factory.FileIntIDFactory
-
- All Implemented Interfaces:
IBaseIDFactory,IIntIDFactory
@ThreadSafe public class FileIntIDFactory extends AbstractPersistingIntIDFactory
Filebased persistingIIntIDFactoryimplementation.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static CharsetCHARSET_TO_USEThe charset to use for writing the filestatic intDEFAULT_RESERVE_COUNTThe default number of values to reserve with a single IO action-
Fields inherited from class com.helger.commons.id.factory.AbstractPersistingIntIDFactory
m_aLock
-
-
Constructor Summary
Constructors Constructor Description FileIntIDFactory(File aFile)FileIntIDFactory(File aFile, int nReserveCount)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)FilegetFile()inthashCode()protected intreadAndUpdateIDCounter(int nReserveCount)Read the current ID from the device.StringtoString()-
Methods inherited from class com.helger.commons.id.factory.AbstractPersistingIntIDFactory
getNewID, getReserveCount
-
-
-
-
Field Detail
-
CHARSET_TO_USE
public static final Charset CHARSET_TO_USE
The charset to use for writing the file
-
DEFAULT_RESERVE_COUNT
public static final int DEFAULT_RESERVE_COUNT
The default number of values to reserve with a single IO action- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FileIntIDFactory
public FileIntIDFactory(@Nonnull File aFile, @Nonnegative int nReserveCount)
-
-
Method Detail
-
getFile
@Nonnull public final File getFile()
- Returns:
- The
Fileto write to, as provided in the constructor. Nevernull.
-
readAndUpdateIDCounter
@MustBeLocked(WRITE) protected final int readAndUpdateIDCounter(@Nonnegative int nReserveCount)
Description copied from class:AbstractPersistingIntIDFactoryRead the current ID from the device. In case the method is called for a non-initialized device, 0 should be returned.
The update should write the read value plus the passed reserve count back to the device. This method should perform an atomic read and update to avoid that ID can be reused.
Pseudo code:protected int readAndUpdateIDCounter (int nReserveCount) { final int nRead = FileIO.read (file); FileIO.write (file, nRead + nReserveCount); return nRead; }- Specified by:
readAndUpdateIDCounterin classAbstractPersistingIntIDFactory- Parameters:
nReserveCount- the number that should be added to the read value. Always > 0.- Returns:
- 0 if this method is called for a non-initialized device, the value
read from the device otherwise or
CGlobal.ILLEGAL_UINTin case of an error.
-
equals
public boolean equals(Object o)
- Overrides:
equalsin classAbstractPersistingIntIDFactory
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractPersistingIntIDFactory
-
toString
public String toString()
- Overrides:
toStringin classAbstractPersistingIntIDFactory
-
-