forked from peter-lawrey/Java-Chronicle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
8 changed files
with
452 additions
and
28 deletions.
There are no files selected for viewing
216 changes: 216 additions & 0 deletions
216
...nicle-fix/src/test/java/com/higherfrequencytrading/chronicle/fix/FixSocketReaderTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
chronicle/src/main/java/com/higherfrequencytrading/chronicle/impl/ChronicleBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.higherfrequencytrading.chronicle.impl; | ||
|
||
import com.higherfrequencytrading.chronicle.tools.ChronicleTools; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteOrder; | ||
|
||
/** | ||
* @author jkubrynski@gmail.com | ||
* @since 2013-06-30 | ||
*/ | ||
public class ChronicleBuilder { | ||
|
||
public static IndexedChronicleBuilder newIndexedChronicleBuilder(String basePath) { | ||
return new IndexedChronicleBuilder(basePath); | ||
} | ||
|
||
public static IntIndexedChronicleBuilder newIntIndexedChronicleBuilder(String basePath) { | ||
return new IntIndexedChronicleBuilder(basePath); | ||
} | ||
|
||
public static class IndexedChronicleBuilder { | ||
|
||
protected String basePath; | ||
protected int dataBitSizeHint = | ||
ChronicleTools.is64Bit() ? IndexedChronicle.DEFAULT_DATA_BITS_SIZE : IndexedChronicle.DEFAULT_DATA_BITS_SIZE32; | ||
protected ByteOrder byteOrder = ByteOrder.nativeOrder(); | ||
protected boolean minimiseByteBuffers = !ChronicleTools.is64Bit(); | ||
protected boolean synchronousMode = false; | ||
protected boolean useUnsafe = false; | ||
|
||
public IndexedChronicleBuilder(String basePath) { | ||
this.basePath = basePath; | ||
} | ||
|
||
public IndexedChronicleBuilder dataBitSizeHint(int dataBitSizeHint) { | ||
this.dataBitSizeHint = dataBitSizeHint; | ||
return this; | ||
} | ||
|
||
public IndexedChronicleBuilder byteOrder(ByteOrder byteOrder) { | ||
this.byteOrder = byteOrder; | ||
return this; | ||
} | ||
|
||
public IndexedChronicleBuilder minimiseByteBuffers(boolean minimiseByteBuffers) { | ||
this.minimiseByteBuffers = minimiseByteBuffers; | ||
return this; | ||
} | ||
|
||
public IndexedChronicleBuilder useSynchronousMode(boolean synchronousMode) { | ||
this.synchronousMode = synchronousMode; | ||
return this; | ||
} | ||
|
||
public IndexedChronicleBuilder useUnsafe(boolean useUnsafe) { | ||
this.useUnsafe = useUnsafe; | ||
return this; | ||
} | ||
|
||
public IndexedChronicle build() throws IOException { | ||
IndexedChronicle indexedChronicle = | ||
new IndexedChronicle(basePath, dataBitSizeHint, byteOrder, minimiseByteBuffers, synchronousMode); | ||
indexedChronicle.useUnsafe(useUnsafe); | ||
return indexedChronicle; | ||
} | ||
} | ||
|
||
public static class IntIndexedChronicleBuilder extends IndexedChronicleBuilder { | ||
|
||
public IntIndexedChronicleBuilder(String basePath) { | ||
super(basePath); | ||
} | ||
|
||
@Override | ||
public IntIndexedChronicle build() throws IOException { | ||
IntIndexedChronicle intIndexedChronicle = new IntIndexedChronicle(basePath, dataBitSizeHint, byteOrder); | ||
intIndexedChronicle.useUnsafe(useUnsafe); | ||
return intIndexedChronicle; | ||
} | ||
} | ||
|
||
|
||
} |
96 changes: 96 additions & 0 deletions
96
.../src/test/java/com/higherfrequencytrading/chronicle/examples/ExampleKeyedExcerptMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.higherfrequencytrading.chronicle.examples; | ||
|
||
import com.higherfrequencytrading.chronicle.Chronicle; | ||
import com.higherfrequencytrading.chronicle.Excerpt; | ||
import com.higherfrequencytrading.chronicle.impl.IndexedChronicle; | ||
import com.higherfrequencytrading.chronicle.tools.ChronicleTools; | ||
import gnu.trove.map.hash.TObjectLongHashMap; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
|
||
/** | ||
* @author peter.lawrey | ||
*/ | ||
public class ExampleKeyedExcerptMain { | ||
private static final String TMP = System.getProperty("java.io.tmpdir"); | ||
|
||
private final Chronicle chronicle; | ||
private final Excerpt excerpt; | ||
private final TObjectLongHashMap<String> keyToExcerpt = new TObjectLongHashMap<String>() { | ||
@Override | ||
public long getNoEntryValue() { | ||
return -1; | ||
} | ||
}; | ||
|
||
public ExampleKeyedExcerptMain(String basePath) throws IOException { | ||
chronicle = new IndexedChronicle(basePath); | ||
excerpt = chronicle.createExcerpt(); | ||
} | ||
|
||
public void load() { | ||
while (excerpt.nextIndex()) { | ||
String key = excerpt.readUTF(); | ||
keyToExcerpt.put(key, excerpt.index()); | ||
} | ||
} | ||
|
||
public void putMapFor(String key, Map<String, String> map) { | ||
excerpt.startExcerpt(4096); // a guess | ||
excerpt.writeUTF(key); | ||
excerpt.writeMap(map); | ||
excerpt.finish(); | ||
} | ||
|
||
public Map<String, String> getMapFor(String key) { | ||
|
||
long value = keyToExcerpt.get(key); | ||
if (value < 0) return Collections.emptyMap(); | ||
excerpt.index(value); | ||
// skip the key | ||
excerpt.skip(excerpt.readStopBit()); | ||
return excerpt.readMap(String.class, String.class); | ||
} | ||
|
||
public void close() { | ||
chronicle.close(); | ||
} | ||
|
||
public static void main(String... ignored) throws IOException { | ||
String basePath = TMP + "/ExampleKeyedExcerptMain"; | ||
ChronicleTools.deleteOnExit(basePath); | ||
ExampleKeyedExcerptMain map = new ExampleKeyedExcerptMain(basePath); | ||
map.load(); | ||
long start = System.nanoTime(); | ||
int keys = 10000000; | ||
for (int i = 0; i < keys; i++) { | ||
Map<String, String> props = new LinkedHashMap<String, String>(); | ||
props.put("a", Integer.toString(i)); // an int. | ||
props.put("b", "value-" + i); // String | ||
props.put("c", Double.toString(i / 1000.0)); // a double | ||
map.putMapFor(Integer.toHexString(i), props); | ||
} | ||
map.close(); | ||
|
||
ExampleKeyedExcerptMain map2 = new ExampleKeyedExcerptMain(basePath); | ||
map2.load(); | ||
long start2 = System.nanoTime(); | ||
for (int i = 0; i < keys; i++) { | ||
Map<String, Object> props = new LinkedHashMap<String, Object>(); | ||
props.put("a", Integer.toString(i)); // an int. | ||
props.put("b", "value-" + i); // String | ||
props.put("c", Double.toString(i / 1000.0)); // a double | ||
Map<String, String> props2 = map2.getMapFor(Integer.toHexString(i)); | ||
assertEquals(props, props2); | ||
} | ||
map2.close(); | ||
long time = System.nanoTime() - start; | ||
long time2 = System.nanoTime() - start2; | ||
System.out.printf("Took an average of %,d ns to write and read each entry, an average of %,d ns to lookup%n", time / keys, time2 / keys); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,4 @@ | |
</dependency> | ||
</dependencies> | ||
|
||
</project> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,4 +58,4 @@ | |
<artifactId>junit</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
</project> |