|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.faunos.skwish.sys.Index
public class Index
An index of offsets backed by a file. The implementation is based on the file format described in the package summary.
IndexMetrics
Field Summary | |
---|---|
protected static int |
BASEID_WIDTH
|
protected static int |
BASEOFFSET_WIDTH
|
protected static int |
ENTRYCOUNT_WIDTH
|
static int |
FIXED_HEADER_WIDTH
The byte size of an index's fixed header. |
protected static ChannelUtil<IndexException> |
helper
|
protected FileChannel |
indexFile
The underlying persistent representation of the index. |
protected static int |
OFFSETWIDTH_WIDTH
|
protected static Validator<IndexException> |
validator
|
Constructor Summary | |
---|---|
|
Index(FileChannel indexFile)
Reads an index from the specified I/O channel. |
|
Index(FileChannel indexFile,
boolean recover)
Reads an index from the specified I/O channel. |
protected |
Index(FileChannel indexFile,
Word offsetWidth,
long baseId,
long baseOffset)
Writes a new index to the specified file. |
Method Summary | |
---|---|
void |
close()
Closes this index and its underlying file. |
void |
commit()
Commits the entry count to the backing file. |
long |
delete(long id)
Deletes the entry with the given ID. |
long |
delete(long startId,
int count)
Deletes count entries starting with the given startId . |
void |
flush()
Flushes the underlying file stream. |
long |
getContentsSize()
Returns the byte size of all the entry contents this index knows about. |
long |
getEntryCount()
Returns the number of entries that are in the index. |
long |
getIndexSize()
Returns the byte size of the index. |
long |
getLastOffset()
Returns the last offset in the content file that this instance [implicitly] manages. |
IndexMetrics |
getMetrics()
Returns the metrics of the index. |
long |
getNextId()
Returns the ID that would be returned on inserting or killing the next entry. |
boolean |
isAutoCommit()
Determines whether this instance is in auto-commit mode. |
long |
killNext()
Kills the next entry. |
long |
killNext(int count)
Kills the next count entry. |
long |
pushNext(long size)
Pushes the next entry of the given size . |
void |
readOffsets(long id,
ByteBuffer out)
Reads and returns the offsets of the entry with the specified ID. |
void |
readOffsets(long startId,
ByteBuffer out,
int count)
Reads and returns the offsets of count entries, starting at the specified
startId . |
void |
readOffsets(long startId,
ByteBuffer out,
int count,
ByteBuffer work)
|
void |
setAutoCommit(boolean autoCommit)
Sets the auto-commit property. |
static Index |
writeNewIndex(FileChannel indexFile,
Word offsetWidth,
long baseId,
long baseOffset)
Writes a new index to the specified file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int OFFSETWIDTH_WIDTH
protected static final int BASEOFFSET_WIDTH
protected static final int BASEID_WIDTH
protected static final int ENTRYCOUNT_WIDTH
public static final int FIXED_HEADER_WIDTH
protected static final ChannelUtil<IndexException> helper
protected static final Validator<IndexException> validator
protected final FileChannel indexFile
Constructor Detail |
---|
public Index(FileChannel indexFile) throws IOException
IOException
public Index(FileChannel indexFile, boolean recover) throws IOException
IOException
protected Index(FileChannel indexFile, Word offsetWidth, long baseId, long baseOffset) throws IOException
IOException
writeNewIndex(FileChannel, Word, long, long)
Method Detail |
---|
public static Index writeNewIndex(FileChannel indexFile, Word offsetWidth, long baseId, long baseOffset) throws IOException
IOException
public long getContentsSize()
public long getIndexSize()
public void readOffsets(long id, ByteBuffer out) throws IOException
out
-parameter
buffer in LONG
format using 0 (zero) as the base offset.
NotFoundException
- if id is out of range
IOException
public void readOffsets(long startId, ByteBuffer out, int count) throws IOException
count
entries, starting at the specified
startId
. The offsets are written into the given out
-parameter
buffer in LONG
format using 0 (zero) as the base offset.
The number of entry offsets written to the out
parameter is always count + 1
.
IOException
public void readOffsets(long startId, ByteBuffer out, int count, ByteBuffer work) throws IOException
IOException
public long getEntryCount()
public IndexMetrics getMetrics()
public long getLastOffset()
public long getNextId()
public void commit() throws IOException
IOException
public boolean isAutoCommit()
public void setAutoCommit(boolean autoCommit)
public long pushNext(long size) throws IOException
size
. Invoke
this method when you don't want to have to know what the
last offset was.
IOException
public long killNext() throws IOException
IOException
public long killNext(int count) throws IOException
count entry. Killing an entry
is equivalent to creating and then deleting an entry in one step, except
that this method is faster.
- Returns:
- the value of next ID property
post invocation
- Throws:
IOException
public long delete(long id) throws IOException
IOException
public long delete(long startId, int count) throws IOException
count
entries starting with the given startId
.
The specified range of entry IDs must already exist in this index. Returns the
offset of the next entry beyond the last entry deleted.
IOException
public void close() throws IOException
false
, and if the last insertions
were not followed by a commit, then those last insertions
would be lost on invoking this method.
close
in interface Closeable
IOException
public void flush() throws IOException
close()
method applies here too.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |