Skip to content

Commit 29e013c

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 923eaaf + ce261ba commit 29e013c

File tree

2 files changed

+90
-3
lines changed

2 files changed

+90
-3
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.higherfrequencytrading.chronicle.impl;
2+
3+
import com.higherfrequencytrading.chronicle.tools.ChronicleTools;
4+
5+
import java.io.IOException;
6+
import java.nio.ByteOrder;
7+
8+
/**
9+
10+
* @since 2013-06-30
11+
*/
12+
public class ChronicleBuilder {
13+
14+
public static IndexedChronicleBuilder newIndexedChronicleBuilder(String basePath) {
15+
return new IndexedChronicleBuilder(basePath);
16+
}
17+
18+
public static IntIndexedChronicleBuilder newIntIndexedChronicleBuilder(String basePath) {
19+
return new IntIndexedChronicleBuilder(basePath);
20+
}
21+
22+
public static class IndexedChronicleBuilder {
23+
24+
protected String basePath;
25+
protected int dataBitSizeHint =
26+
ChronicleTools.is64Bit() ? IndexedChronicle.DEFAULT_DATA_BITS_SIZE : IndexedChronicle.DEFAULT_DATA_BITS_SIZE32;
27+
protected ByteOrder byteOrder = ByteOrder.nativeOrder();
28+
protected boolean minimiseByteBuffers = !ChronicleTools.is64Bit();
29+
protected boolean synchronousMode = false;
30+
protected boolean useUnsafe = false;
31+
32+
public IndexedChronicleBuilder(String basePath) {
33+
this.basePath = basePath;
34+
}
35+
36+
public IndexedChronicleBuilder dataBitSizeHint(int dataBitSizeHint) {
37+
this.dataBitSizeHint = dataBitSizeHint;
38+
return this;
39+
}
40+
41+
public IndexedChronicleBuilder byteOrder(ByteOrder byteOrder) {
42+
this.byteOrder = byteOrder;
43+
return this;
44+
}
45+
46+
public IndexedChronicleBuilder minimiseByteBuffers(boolean minimiseByteBuffers) {
47+
this.minimiseByteBuffers = minimiseByteBuffers;
48+
return this;
49+
}
50+
51+
public IndexedChronicleBuilder useSynchronousMode(boolean synchronousMode) {
52+
this.synchronousMode = synchronousMode;
53+
return this;
54+
}
55+
56+
public IndexedChronicleBuilder useUnsafe(boolean useUnsafe) {
57+
this.useUnsafe = useUnsafe;
58+
return this;
59+
}
60+
61+
public IndexedChronicle build() throws IOException {
62+
IndexedChronicle indexedChronicle =
63+
new IndexedChronicle(basePath, dataBitSizeHint, byteOrder, minimiseByteBuffers, synchronousMode);
64+
indexedChronicle.useUnsafe(useUnsafe);
65+
return indexedChronicle;
66+
}
67+
}
68+
69+
public static class IntIndexedChronicleBuilder extends IndexedChronicleBuilder {
70+
71+
public IntIndexedChronicleBuilder(String basePath) {
72+
super(basePath);
73+
}
74+
75+
@Override
76+
public IntIndexedChronicle build() throws IOException {
77+
IntIndexedChronicle intIndexedChronicle = new IntIndexedChronicle(basePath, dataBitSizeHint, byteOrder);
78+
intIndexedChronicle.useUnsafe(useUnsafe);
79+
return intIndexedChronicle;
80+
}
81+
}
82+
83+
84+
}

chronicle/src/test/java/com/higherfrequencytrading/chronicle/impl/IndexedChronicleTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ public void rewritibleEntries() throws IOException {
4747

4848
private void doRewriteableEntries(boolean useUnsafe, boolean minimiseByteBuffers, boolean synchronousMode) throws IOException {
4949
String basePath = TMP + File.separator + "deleteme.ict";
50-
IndexedChronicle tsc = new IndexedChronicle(basePath, IndexedChronicle.DEFAULT_DATA_BITS_SIZE32,
51-
ByteOrder.nativeOrder(), minimiseByteBuffers, synchronousMode);
52-
tsc.useUnsafe(useUnsafe);
50+
IndexedChronicle tsc = ChronicleBuilder.newIndexedChronicleBuilder(basePath)
51+
.dataBitSizeHint(IndexedChronicle.DEFAULT_DATA_BITS_SIZE32)
52+
.minimiseByteBuffers(minimiseByteBuffers)
53+
.useSynchronousMode(synchronousMode)
54+
.useUnsafe(useUnsafe).build();
55+
5356
deleteOnExit(basePath);
5457

5558
tsc.clear();

0 commit comments

Comments
 (0)