public class SegmentManager extends Object implements AutoCloseable
Segments of the Log.
The segment manager keeps track of segments in a given Log and provides an interface to loading, retrieving,
and compacting those segments.
| Constructor and Description |
|---|
SegmentManager(String name,
Storage storage,
Serializer serializer) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
long |
commitIndex()
Returns the log compact index.
|
Segment |
createSegment(SegmentDescriptor descriptor)
Creates a new segment.
|
Segment |
currentSegment()
Returns the current segment.
|
Segment |
firstSegment()
Returns the first segment in the log.
|
Segment |
lastSegment()
Returns the last segment in the log.
|
Segment |
loadSegment(long segmentId,
long segmentVersion)
Loads a segment.
|
Segment |
nextSegment()
Creates and returns the next segment.
|
void |
removeSegment(Segment segment)
Removes a segment.
|
void |
replaceSegments(Collection<Segment> segments,
Segment segment)
Inserts a segment.
|
Collection<Segment> |
reverseSegments()
Returns the collection of segments in reverse order.
|
Segment |
segment(long index)
Returns the segment for the given index.
|
Collection<Segment> |
segments()
Returns the collection of segments.
|
Serializer |
serializer()
Returns the entry serializer.
|
String |
toString() |
public SegmentManager(String name, Storage storage, Serializer serializer)
NullPointerException - if segments is nullpublic Serializer serializer()
public long commitIndex()
public Segment currentSegment()
public Segment firstSegment()
IllegalStateException - if the segment manager is not openpublic Segment lastSegment()
IllegalStateException - if the segment manager is not openpublic Segment nextSegment()
IllegalStateException - if the segment manager is not openpublic Collection<Segment> segments()
public Collection<Segment> reverseSegments()
public Segment segment(long index)
index - The index for which to return the segment.IllegalStateException - if the segment manager is not openpublic void replaceSegments(Collection<Segment> segments, Segment segment)
segment - The segment to insert.IllegalStateException - if the segment is unknownpublic void removeSegment(Segment segment)
segment - The segment to remove.public Segment createSegment(SegmentDescriptor descriptor)
public Segment loadSegment(long segmentId, long segmentVersion)
public void close()
close in interface AutoCloseableCopyright © 2013–2016. All rights reserved.