|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.faunos.skwish.Segment
public abstract class Segment
The elementary storage class. A segment logically consists of a mapping
of integral IDs to entries. An entry is just an uninterpreted,
bounded sequence of bytes. It may represent a file, a record, whatever.
The entry IDs a segment knows about are in the contiguous range
[baseId, nextId)
.
getBaseId()
getEntryCount()
getEntrySize(long)
, getEntrySize(long, ByteBuffer)
getNextId()
isDeleted(long)
, isDeleted(long, ByteBuffer)
isReadOnly()
baseId + entryCount = nextId
getEntry(long, ByteBuffer)
, and getEntry(long, ByteBuffer, ByteBuffer)
getEntryChannel(long)
getEntryStream(long)
NotFoundException
.
false
. If one write operation is supported, then all write operations are
supported. Invoking any of the methods in this section on a read-only instance raises
an java.lang.UnsupportedOperationException
.
delete(long)
, or in bulkdelete(long, int)
, or with the optional purge
parameterdelete(long, int, boolean)
signaling that the deleted contents should be
purged ASAP on the file system.killNext()
, andkillNext(int)
(bulk kill)Range
ImplementationRange
interface here is only valid if
the Segment
instance is not empty (entryCount > 0); o.w. the Range
contract is violated
(because Range.lo
== Range.hi
).
isReadOnly()
Field Summary | |
---|---|
protected static Validator<SegmentException> |
validator
A centralized exception raising mechanism. |
Constructor Summary | |
---|---|
Segment()
|
Method Summary | |
---|---|
boolean |
contains(long id)
Determines whether the given entry ID exists in this segment. |
void |
delete(long id)
Deletes the entry with the specified id. |
void |
delete(long id,
int count)
Deletes count entries starting at the entry with the specified id. |
abstract void |
delete(long id,
int count,
boolean purge)
Deletes count entries starting at the entry with the specified id. |
abstract long |
getBaseId()
Returns the instance's base ID. |
void |
getEntry(long id,
ByteBuffer out)
Returns the contents of the entry with the specified id. |
abstract void |
getEntry(long id,
ByteBuffer out,
ByteBuffer workBuffer)
Returns the contents of the entry with the specified id. |
abstract FileChannel |
getEntryChannel(long id)
Returns the contents of the entry with the given id
as a FileChannel , or null , if deleted. |
abstract long |
getEntryCount()
Returns the number of entries in this instance. |
abstract int |
getEntryPart(long id,
long position,
ByteBuffer out,
ByteBuffer workBuffer)
Returns the specified part of the entry contents with the specified id. |
long |
getEntrySize(long id)
Returns the size of the entry with the specified id. |
abstract long |
getEntrySize(long id,
ByteBuffer workBuffer)
Returns the size of the entry with the specified id. |
InputStream |
getEntryStream(long id)
Returns the entry with the given id as an input
stream, or null , if deleted. |
abstract long |
getNextId()
Returns the ID the entry will get on the next insertion. |
long |
hi()
Returns the high (exclusive) value of the range. |
abstract long |
insertEntry(ByteBuffer entry)
Inserts the given entry and returns the entry's ID. |
abstract long |
insertEntry(ReadableByteChannel entry)
Inserts the entry represented by the given channel. |
boolean |
isDeleted(long id)
Determines whether the entry with the specified id is deleted. |
boolean |
isDeleted(long id,
ByteBuffer workBuffer)
Determines whether the entry with the specified id is deleted. |
abstract boolean |
isReadOnly()
Determines whether this instance is read-only (unmodifiable). |
long |
killNext()
Kills the next entry ID. |
abstract long |
killNext(int count)
Kills the next count entry IDs. |
long |
lo()
Returns the low (inclusive) value of the range. |
String |
toString()
Returns a concatenation of the simple class name together with the base ID and entry count. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final Validator<SegmentException> validator
Constructor Detail |
---|
public Segment()
Method Detail |
---|
public abstract long getBaseId()
getEntryCount()
public final long lo()
Range
lo
in interface Range
public abstract long getEntryCount()
public abstract long getNextId()
public final long hi()
Range
hi
in interface Range
public boolean contains(long id)
public abstract long insertEntry(ByteBuffer entry) throws IOException
entry
- they contents of the entry
IOException
public abstract long insertEntry(ReadableByteChannel entry) throws IOException
entry
represented by the given channel.
The contents are of the entry is understood to be the entire
remaining contents in the specified channel.
This is the most efficient method for inserting a large-size entry
(even one that doesn't fit in memory).
IOException
public long killNext() throws IOException
IOException
public abstract long killNext(int count) throws IOException
count
entry IDs. A killed entry is an
entry that begins (and ends) life in the deleted state.
count
- the number of entries to kill (must be greater than 1)
IOException
public void delete(long id) throws IOException
id
- the ID of the entry to be deleted. Must be
a valid ID in this segment [baseId, baseId + entryCount)
IOException
public void delete(long id, int count) throws IOException
id
- the ID of the first entry to be deleted. Must be
a valid ID in this segment [baseId, baseId + entryCount)count
- the number of entries to be deleted. Specifies a
range of IDs to be deleted: [id, id + count). The range
of IDs must be valid entries within this segment; o.w.
an exception is raised.
IOException
public abstract void delete(long id, int count, boolean purge) throws IOException
id
- the ID of the first entry to be deleted. Must be
a valid ID in this segment [baseId, baseId + entryCount)count
- the number of entries to be deleted. Specifies a
range of IDs to be deleted: [id, id + count). The range
of IDs must be valid entries within this segment; o.w.
an exception is raised.purge
- if true
, the contents of the deleted entries
are signaled to be purged (overwritten) immediately;
o.w. the contents will be deleted on the next time the segment is
compacted.
IOException
public boolean isDeleted(long id) throws IOException
IOException
public boolean isDeleted(long id, ByteBuffer workBuffer) throws IOException
IOException
public long getEntrySize(long id) throws IOException
IOException
public abstract long getEntrySize(long id, ByteBuffer workBuffer) throws IOException
IOException
public abstract int getEntryPart(long id, long position, ByteBuffer out, ByteBuffer workBuffer) throws IOException
out.remaining()
bytes of the contents of the entry
are copied into the given out
buffer.
position
- the starting position into the entry from where data will be
copied into the out bufferout
- the out buffer into which data is writtenworkBuffer
- a work buffer with a minimum size of 16
out
has
no remaining bytes), or -1, if the position is greater than the
size of the entry, or if the entry is deleted.
IOException
public void getEntry(long id, ByteBuffer out) throws IOException
out
buffer.
out
- the buffer into which the contents are written. Its
remaining bytes must be large enough; o.w., an
exception is raised.
IOException
public InputStream getEntryStream(long id) throws IOException
id
as an input
stream, or null
, if deleted.
IOException
public abstract FileChannel getEntryChannel(long id) throws IOException
id
as a FileChannel
, or null
, if deleted.
The returned channel is positioned at zero and is read-only.
IOException
public abstract void getEntry(long id, ByteBuffer out, ByteBuffer workBuffer) throws IOException
out
buffer.
out
- the buffer into which the contents are written. Its
remaining bytes must be large enough; o.w., an exception is raised.workBuffer
- a work buffer used internally to read offsets. The minimum
capacity of this work buffer must be 16
IOException
public abstract boolean isReadOnly()
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |