krati.core.segment
Interface Segment
- All Known Implementing Classes:
- AbstractSegment, ChannelSegment, MappedSegment, MemorySegment, WriteBufferSegment
public interface Segment
Segment Storage Version: 1
The segment header section uses the first 128 bytes, but only the first 16 bytes are used.
The segment data section stores varying-length data in the format of repeated [length][data ... ...].
Header Section:
0x00 long -- 8 bytes lastForcedTime
0x08 long -- 8 bytes storageVersion
0x10 long -- 8 bytes reserved
0x18 long -- 8 bytes reserved
0x20 long -- 8 bytes reserved
0x28 long -- 8 bytes reserved
0x30 long -- 8 bytes reserved
0x38 long -- 8 bytes reserved
0x40 long -- 8 bytes reserved
0x48 long -- 8 bytes reserved
0x50 long -- 8 bytes reserved
0x58 long -- 8 bytes reserved
0x60 long -- 8 bytes reserved
0x68 long -- 8 bytes reserved
0x70 long -- 8 bytes reserved
0x78 long -- 8 bytes reserved
Data Section:
[length1][data1 ... ...]
[length2][data2 ... ... ... ... ... ...]
[length3][data3 ... ... ... ...]
[length4][data4 ...]
...
- Author:
- jwu
Method Summary |
int |
append(byte[] data)
|
int |
append(byte[] data,
int offset,
int length)
|
int |
appendInt(int value)
|
int |
appendLong(long value)
|
int |
appendShort(short value)
|
void |
asReadOnly()
|
boolean |
canAppendToBuffer()
|
boolean |
canReadFromBuffer()
|
void |
close(boolean force)
|
void |
decrLoadSize(int byteCnt)
|
void |
force()
|
long |
getAppendPosition()
|
long |
getInitialSize()
|
int |
getInitialSizeMB()
|
long |
getLastForcedTime()
|
double |
getLoadFactor()
|
int |
getLoadSize()
|
Segment.Mode |
getMode()
|
File |
getSegmentFile()
|
int |
getSegmentId()
|
String |
getStatus()
|
long |
getStorageVersion()
|
void |
incrLoadSize(int byteCnt)
|
boolean |
isReadOnly()
|
boolean |
isRecyclable()
|
void |
read(int pos,
byte[] dst)
|
void |
read(int pos,
byte[] dst,
int offset,
int length)
|
int |
readInt(int pos)
|
long |
readLong(int pos)
|
short |
readShort(int pos)
|
void |
reinit()
Re-initialize this Segment for read and write. |
void |
setAppendPosition(long pos)
|
int |
transferTo(int pos,
int length,
Segment targetSegment)
|
int |
transferTo(int pos,
int length,
WritableByteChannel targetChannel)
|
STORAGE_VERSION
static final long STORAGE_VERSION
- See Also:
- Constant Field Values
defaultSegmentCompactFactor
static final double defaultSegmentCompactFactor
- See Also:
- Constant Field Values
defaultSegmentFileSizeMB
static final int defaultSegmentFileSizeMB
- See Also:
- Constant Field Values
maxSegmentFileSizeMB
static final int maxSegmentFileSizeMB
- See Also:
- Constant Field Values
minSegmentFileSizeMB
static final int minSegmentFileSizeMB
- See Also:
- Constant Field Values
posLastForcedTime
static final int posLastForcedTime
- See Also:
- Constant Field Values
posStorageVersion
static final int posStorageVersion
- See Also:
- Constant Field Values
dataStartPosition
static final int dataStartPosition
- The data section starts at offset 128.
- See Also:
- Constant Field Values
getMode
Segment.Mode getMode()
getSegmentId
int getSegmentId()
getSegmentFile
File getSegmentFile()
getInitialSize
long getInitialSize()
getInitialSizeMB
int getInitialSizeMB()
getLoadSize
int getLoadSize()
getLoadFactor
double getLoadFactor()
incrLoadSize
void incrLoadSize(int byteCnt)
decrLoadSize
void decrLoadSize(int byteCnt)
getAppendPosition
long getAppendPosition()
throws IOException
- Throws:
IOException
setAppendPosition
void setAppendPosition(long pos)
throws IOException
- Throws:
IOException
readInt
int readInt(int pos)
throws IOException
- Throws:
IOException
readLong
long readLong(int pos)
throws IOException
- Throws:
IOException
readShort
short readShort(int pos)
throws IOException
- Throws:
IOException
read
void read(int pos,
byte[] dst)
throws IOException
- Throws:
IOException
read
void read(int pos,
byte[] dst,
int offset,
int length)
throws IOException
- Throws:
IOException
appendInt
int appendInt(int value)
throws IOException
- Throws:
IOException
appendLong
int appendLong(long value)
throws IOException
- Throws:
IOException
appendShort
int appendShort(short value)
throws IOException
- Throws:
IOException
append
int append(byte[] data)
throws IOException
- Throws:
IOException
append
int append(byte[] data,
int offset,
int length)
throws IOException
- Throws:
IOException
transferTo
int transferTo(int pos,
int length,
Segment targetSegment)
throws IOException
- Throws:
IOException
transferTo
int transferTo(int pos,
int length,
WritableByteChannel targetChannel)
throws IOException
- Throws:
IOException
isReadOnly
boolean isReadOnly()
asReadOnly
void asReadOnly()
throws IOException
- Throws:
IOException
force
void force()
throws IOException
- Throws:
IOException
close
void close(boolean force)
throws IOException
- Throws:
IOException
getLastForcedTime
long getLastForcedTime()
- Returns:
- the last forced time in milliseconds since the epoch, January 01, 1970, 00:00:00 GMT.
getStorageVersion
long getStorageVersion()
- Returns:
- the storage version of this segment.
isRecyclable
boolean isRecyclable()
- Returns:
- whether this Segment is recyclable.
canReadFromBuffer
boolean canReadFromBuffer()
- Returns:
- whether this Segment can support reads from a buffer.
canAppendToBuffer
boolean canAppendToBuffer()
- Returns:
- whether this Segment can support writes by appending to a buffer.
reinit
void reinit()
throws IOException
- Re-initialize this Segment for read and write.
- Throws:
IOException
getStatus
String getStatus()
- Returns:
- the descriptive status of this Segment.
Copyright © 2011. All Rights Reserved.