import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
-import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.TreeMap;
+import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import com.google.common.collect.Sets;
/**
* Segmented journal.
*/
-public class SegmentedJournal<E> implements Journal<E> {
+public final class SegmentedJournal<E> implements Journal<E> {
/**
* Returns a new Raft log builder.
private final SegmentedJournalWriter<E> writer;
private volatile long commitIndex;
- private final NavigableMap<Long, JournalSegment<E>> segments = new ConcurrentSkipListMap<>();
+ private final ConcurrentNavigableMap<Long, JournalSegment<E>> segments = new ConcurrentSkipListMap<>();
private final Collection<SegmentedJournalReader<E>> readers = Sets.newConcurrentHashSet();
private JournalSegment<E> currentSegment;
/**
* Opens the segments.
*/
- private void open() {
+ private synchronized void open() {
// Load existing log segments from disk.
for (JournalSegment<E> segment : loadSegments()) {
segments.put(segment.descriptor().index(), segment);
/**
* Raft log builder.
*/
- public static class Builder<E> {
+ public static final class Builder<E> {
private static final boolean DEFAULT_FLUSH_ON_COMMIT = false;
private static final String DEFAULT_NAME = "atomix";
private static final String DEFAULT_DIRECTORY = System.getProperty("user.dir");
private static final int DEFAULT_MAX_ENTRY_SIZE = 1024 * 1024;
private static final int DEFAULT_MAX_ENTRIES_PER_SEGMENT = 1024 * 1024;
private static final double DEFAULT_INDEX_DENSITY = .005;
- private static final int DEFAULT_CACHE_SIZE = 1024;
-
- protected String name = DEFAULT_NAME;
- protected StorageLevel storageLevel = StorageLevel.DISK;
- protected File directory = new File(DEFAULT_DIRECTORY);
- protected Namespace namespace;
- protected int maxSegmentSize = DEFAULT_MAX_SEGMENT_SIZE;
- protected int maxEntrySize = DEFAULT_MAX_ENTRY_SIZE;
- protected int maxEntriesPerSegment = DEFAULT_MAX_ENTRIES_PER_SEGMENT;
- protected double indexDensity = DEFAULT_INDEX_DENSITY;
- protected int cacheSize = DEFAULT_CACHE_SIZE;
+
+ private String name = DEFAULT_NAME;
+ private StorageLevel storageLevel = StorageLevel.DISK;
+ private File directory = new File(DEFAULT_DIRECTORY);
+ private Namespace namespace;
+ private int maxSegmentSize = DEFAULT_MAX_SEGMENT_SIZE;
+ private int maxEntrySize = DEFAULT_MAX_ENTRY_SIZE;
+ private int maxEntriesPerSegment = DEFAULT_MAX_ENTRIES_PER_SEGMENT;
+ private double indexDensity = DEFAULT_INDEX_DENSITY;
private boolean flushOnCommit = DEFAULT_FLUSH_ON_COMMIT;
protected Builder() {
@Deprecated
public Builder<E> withCacheSize(int cacheSize) {
checkArgument(cacheSize >= 0, "cacheSize must be positive");
- this.cacheSize = cacheSize;
return this;
}