Skip to content

Commit

Permalink
elastic#7053 Refactor Queue Settings Class to Using a Builder Pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
original-brownbear committed May 18, 2017
1 parent 78f7063 commit 1a2c0c8
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 407 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.apache.commons.io.FileUtils;
import org.logstash.Event;
import org.logstash.Timestamp;
import org.logstash.ackedqueue.FileSettings;
import org.logstash.ackedqueue.Queue;
import org.logstash.ackedqueue.Settings;
import org.logstash.ackedqueue.SettingsImpl;
import org.logstash.ackedqueue.io.FileCheckpointIO;
import org.logstash.ackedqueue.io.MmapPageIO;
import org.openjdk.jmh.annotations.Benchmark;
Expand Down Expand Up @@ -83,14 +83,13 @@ public static void main(final String... args) throws RunnerException {
}

private static Settings settings() {
Settings s = new FileSettings(Files.createTempDir().getPath());
s.setCapacity(256 * 1024 * 1024);
s.setQueueMaxBytes(Long.MAX_VALUE);
s.setElementIOFactory(MmapPageIO::new);
s.setCheckpointMaxWrites(50_000);
s.setCheckpointMaxAcks(50_000);
s.setCheckpointIOFactory(FileCheckpointIO::new);
s.setElementClass(Event.class);
return s;
return SettingsImpl.fileSettingsBuilder(Files.createTempDir().getPath())
.capacity(256 * 1024 * 1024)
.queueMaxBytes(Long.MAX_VALUE)
.elementIOFactory(MmapPageIO::new)
.checkpointMaxWrites(50_000)
.checkpointMaxAcks(50_000)
.checkpointIOFactory(FileCheckpointIO::new)
.elementClass(Event.class).build();
}
}
130 changes: 0 additions & 130 deletions logstash-core/src/main/java/org/logstash/ackedqueue/FileSettings.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class Queue implements Closeable {
private final int maxUnread;
private final int checkpointMaxAcks;
private final int checkpointMaxWrites;
private final int checkpointMaxInterval;

private final AtomicBoolean closed;

Expand Down Expand Up @@ -90,12 +89,11 @@ public Queue(Settings settings) {
settings.getElementClass(),
settings.getMaxUnread(),
settings.getCheckpointMaxWrites(),
settings.getCheckpointMaxAcks(),
settings.getCheckpointMaxInterval()
settings.getCheckpointMaxAcks()
);
}

public Queue(String dirPath, int pageCapacity, long maxBytes, CheckpointIO checkpointIO, PageIOFactory pageIOFactory, Class elementClass, int maxUnread, int checkpointMaxWrites, int checkpointMaxAcks, int checkpointMaxInterval) {
private Queue(String dirPath, int pageCapacity, long maxBytes, CheckpointIO checkpointIO, PageIOFactory pageIOFactory, Class elementClass, int maxUnread, int checkpointMaxWrites, int checkpointMaxAcks) {
this.dirPath = dirPath;
this.pageCapacity = pageCapacity;
this.maxBytes = maxBytes;
Expand All @@ -109,7 +107,6 @@ public Queue(String dirPath, int pageCapacity, long maxBytes, CheckpointIO check
this.maxUnread = maxUnread;
this.checkpointMaxAcks = checkpointMaxAcks;
this.checkpointMaxWrites = checkpointMaxWrites;
this.checkpointMaxInterval = checkpointMaxInterval;
this.unreadCount = 0;
this.currentByteSize = 0;

Expand Down
39 changes: 21 additions & 18 deletions logstash-core/src/main/java/org/logstash/ackedqueue/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@
import org.logstash.ackedqueue.io.PageIOFactory;

public interface Settings {
Settings setCheckpointIOFactory(CheckpointIOFactory factory);

Settings setElementIOFactory(PageIOFactory factory);

Settings setElementClass(Class elementClass);

Settings setCapacity(int capacity);

Settings setQueueMaxBytes(long size);

Settings setMaxUnread(int maxUnread);

Settings setCheckpointMaxAcks(int checkpointMaxAcks);

Settings setCheckpointMaxWrites(int checkpointMaxWrites);

Settings setCheckpointMaxInterval(int checkpointMaxInterval);

CheckpointIOFactory getCheckpointIOFactory();

Expand All @@ -39,6 +22,26 @@ public interface Settings {
int getCheckpointMaxAcks();

int getCheckpointMaxWrites();

interface Builder {

Builder checkpointIOFactory(CheckpointIOFactory factory);

Builder elementIOFactory(PageIOFactory factory);

Builder elementClass(Class elementClass);

Builder capacity(int capacity);

Builder queueMaxBytes(long size);

Builder maxUnread(int maxUnread);

Builder checkpointMaxAcks(int checkpointMaxAcks);

Builder checkpointMaxWrites(int checkpointMaxWrites);

Settings build();

int getCheckpointMaxInterval();
}
}
Loading

0 comments on commit 1a2c0c8

Please sign in to comment.