*/
package io.atomix.storage.journal;
+import com.google.common.base.MoreObjects;
import io.atomix.storage.journal.index.JournalIndex;
import io.atomix.storage.journal.index.SparseJournalIndex;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
-import static com.google.common.base.MoreObjects.toStringHelper;
-import static com.google.common.base.Preconditions.checkState;
-
/**
* Log segment.
*
writer = new FileChannelJournalSegmentWriter<>(channel, this, maxEntrySize, index, namespace);
}
- /**
- * Returns the segment ID.
- *
- * @return The segment ID.
- */
- public long id() {
- return descriptor.id();
- }
-
- /**
- * Returns the segment version.
- *
- * @return The segment version.
- */
- public long version() {
- return descriptor.version();
- }
-
/**
* Returns the segment's starting index.
*
* @return The segment's starting index.
*/
- public long index() {
+ long index() {
return descriptor.index();
}
*
* @return The last index in the segment.
*/
- public long lastIndex() {
+ long lastIndex() {
return writer.getLastIndex();
}
*
* @return the size of the segment
*/
- public int size() {
+ int size() {
try {
return (int) channel.size();
} catch (IOException e) {
*
* @return The segment file.
*/
- public JournalSegmentFile file() {
+ JournalSegmentFile file() {
return file;
}
*
* @return The segment descriptor.
*/
- public JournalSegmentDescriptor descriptor() {
+ JournalSegmentDescriptor descriptor() {
return descriptor;
}
- /**
- * Returns a boolean value indicating whether the segment is empty.
- *
- * @return Indicates whether the segment is empty.
- */
- public boolean isEmpty() {
- return length() == 0;
- }
-
- /**
- * Returns the segment length.
- *
- * @return The segment length.
- */
- public long length() {
- return writer.getNextIndex() - index();
- }
-
/**
* Acquires a reference to the log segment.
*/
* Checks whether the segment is open.
*/
private void checkOpen() {
- checkState(open, "Segment not open");
+ if (!open) {
+ throw new IllegalStateException("Segment not open");
+ }
}
/**
/**
* Deletes the segment.
*/
- public void delete() {
+ void delete() {
try {
Files.deleteIfExists(file.file().toPath());
} catch (IOException e) {
@Override
public String toString() {
- return toStringHelper(this)
- .add("id", id())
- .add("version", version())
+ return MoreObjects.toStringHelper(this)
+ .add("id", descriptor.id())
+ .add("version", descriptor.version())
.add("index", index())
.toString();
}