@ThreadSafe public abstract class AbstractPersistingLongIDFactory extends Object implements ILongIDFactory
ILongIDFactory reads IDs from a device. It
does it by reserving a range of n IDs so that not each ID
reservation requires IO. If only 1 ID is effectively used, the other
n-1 IDs are lost and will never be assigned to any object again.| Constructor and Description |
|---|
AbstractPersistingLongIDFactory(int nReserveCount) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
long |
getNewID()
Create a new unique long ID.
|
protected int |
getReserveCount() |
int |
hashCode() |
protected abstract long |
readAndUpdateIDCounter(int nReserveCount)
Read the current ID from the device.
|
String |
toString() |
public AbstractPersistingLongIDFactory(@Nonnegative int nReserveCount)
@Nonnegative protected final int getReserveCount()
protected abstract long readAndUpdateIDCounter(@Nonnegative int nReserveCount)
protected long readAndUpdateIDCounter (int nReserveCount)
{
final long nRead = FileIO.read (file);
FileIO.write (file, nRead + nReserveCount);
return nRead;
}
nReserveCount - the number that should be added to the read value. Always > 0.CGlobal.ILLEGAL_ULONG in case of an
error.public final long getNewID()
ILongIDFactorygetNewID in interface ILongIDFactoryCopyright © 2006–2015 phloc systems. All rights reserved.