HCOLL-136 HCOLL-137 HCOLL-153 HCOLL-160

1. Separated ChronicleMapBuilder (for non-Byteable values) and
OffHeapUpdatableChronicleMapBuilder (for Byteable values) with common base
AbstractChronicleMapBuilder (public just to inherit common javadocs)

2. Added ChronicleHashBuilder.keyDeserializationFactory() and
AbstractChronicleMapBuilder.valueDeserializationFactory() (former
ChronicleMapBuilder.valueFactory() method)

3. Changed ChronicleMap.get(), getUsing() API and impl to what was
initially intended - now they ALWAYS returns null, if key is absent

4. acquireUsing() API, common for the cases with Byteable and non-Byteable
values: puts defaultValue or defaultValueProvider.get(key), if the key is
absent, then acquireUsing() behaves just like getUsing()

5. For off0heap updatable ChronicleMaps (Byteable values), added
prepareValueBytes() configuration which formalizes zeroing out value bytes

6. Javadoc fixes and improvements
This commit is contained in:
leventov
2014-10-27 20:15:26 +03:00
parent b374a9bd50
commit 0c45ee8aff
30 changed files with 1529 additions and 1084 deletions
@@ -29,7 +29,7 @@ import static org.junit.Assert.fail;
public class AcquireGetUsingMain {
public static void main(String[] args) throws Exception {
File file = new File(System.getProperty("java.io.tmpdir") + "/test1");
ChronicleMap<String, Data> theSharedMap = ChronicleMapBuilder.of(String.class, Data.class).file(file).create();
ChronicleMap<String, Data> theSharedMap = OffHeapUpdatableChronicleMapBuilder.of(String.class, Data.class).file(file).create();
Data data = DataValueClasses.newDirectReference(Data.class);
String processType = "testkey";
if (theSharedMap.getUsing(processType, data) == null) {
@@ -75,7 +75,7 @@ public class CHMLatencyTestMain {
File file = File.createTempFile("testCHMLatency", "deleteme");
// File file = new File("testCHMLatency.deleteme");
file.delete();
ChronicleMap<LongValue, LongValue> countersMap = ChronicleMapBuilder.of(LongValue.class, LongValue.class)
ChronicleMap<LongValue, LongValue> countersMap = OffHeapUpdatableChronicleMapBuilder.of(LongValue.class, LongValue.class)
.entries(KEYS)
.entrySize(24).create();
@@ -34,8 +34,8 @@ public class CHMTest5 {
public static void main(String[] args) throws Exception {
//First create (or access if already created) the shared map
ChronicleMapBuilder<String, CHMTest5Data> builder =
ChronicleMapBuilder.of(String.class, CHMTest5Data.class)
OffHeapUpdatableChronicleMapBuilder<String, CHMTest5Data> builder =
OffHeapUpdatableChronicleMapBuilder.of(String.class, CHMTest5Data.class)
.entries(1000);
//// don't include this, just to check it is as expected.
@@ -110,13 +110,12 @@ public class ChronicleMapTest {
private static ChronicleMap<CharSequence, LongValue> getSharedMap(
long entries, int segments, int entrySize, Alignment alignment)
throws IOException {
return ChronicleMapBuilder.of(CharSequence.class, LongValue.class)
return OffHeapUpdatableChronicleMapBuilder.of(CharSequence.class, LongValue.class)
.entries(entries)
.minSegments(segments)
.entrySize(entrySize)
.entryAndValueAlignment(alignment)
.valueMarshallerAndFactory(ByteableLongValueMarshaller.INSTANCE,
DirectLongValueFactory.INSTANCE).create();
.create();
}
private static void printStatus() {
@@ -578,13 +577,11 @@ public class ChronicleMapTest {
// int runs = Integer.getInteger("runs", 10);
for (int runs : new int[]{10, 50, 250, 500, 1000, 2500}) {
final long entries = runs * 1000 * 1000L;
ChronicleMapBuilder<CharSequence, IntValue> builder = ChronicleMapBuilder
OffHeapUpdatableChronicleMapBuilder<CharSequence, IntValue> builder = OffHeapUpdatableChronicleMapBuilder
.of(CharSequence.class, IntValue.class)
.entries(entries)
.minSegments(1024)
.entrySize(20)
.valueMarshallerAndFactory(ByteableIntValueMarshaller.INSTANCE,
DirectIntValueFactory.INSTANCE);
.entrySize(20);
final ChronicleMap<CharSequence, IntValue> map = builder.create();
@@ -18,6 +18,7 @@
package net.openhft.chronicle.map;
import net.openhft.lang.model.DataValueClasses;
import net.openhft.lang.values.LongValue;
import org.junit.Ignore;
import org.junit.Test;
@@ -28,6 +29,7 @@ import java.util.Arrays;
import java.util.Random;
import static net.openhft.chronicle.map.Alignment.OF_4_BYTES;
import static net.openhft.lang.model.DataValueClasses.newDirectReference;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -138,7 +140,7 @@ public class EntryCountMapTest {
private void testEntriesMaxSize(int segments, int minSize, int maxSize, int seed) throws IOException {
int counter = minSize + new Random(seed + segments * 1000).nextInt(9999);
ChronicleMap<CharSequence, LongValue> map = getSharedMap(minSize, segments, 32);
LongValue longValue = DirectLongValueFactory.INSTANCE.create();
LongValue longValue = newDirectReference(LongValue.class);
try {
for (int j = 0; j < maxSize * 12 / 10 + 300; j++) {
String key = "key:" + counter++;
@@ -195,13 +197,11 @@ public class EntryCountMapTest {
private static ChronicleMap<CharSequence, LongValue> getSharedMap(
long entries, int segments, int entrySize, Alignment alignment)
throws IOException {
ChronicleMapBuilder<CharSequence, LongValue> mapBuilder = ChronicleMapBuilder.of(CharSequence.class, LongValue.class)
OffHeapUpdatableChronicleMapBuilder<CharSequence, LongValue> mapBuilder = OffHeapUpdatableChronicleMapBuilder.of(CharSequence.class, LongValue.class)
.entries(entries)
.minSegments(segments)
.entrySize(entrySize)
.entryAndValueAlignment(alignment)
.valueMarshallerAndFactory(ByteableLongValueMarshaller.INSTANCE,
DirectLongValueFactory.INSTANCE)
.file(getPersistenceFile());
return mapBuilder.create();
}
@@ -242,13 +242,13 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
}
@Override
public V getUsing(K key, V value) {
return map1.getUsing(key, value);
public V getUsing(K key, V usingValue) {
return map1.getUsing(key, usingValue);
}
@Override
public V acquireUsing(K key, V value) {
return map1.acquireUsing(key, value);
public V acquireUsing(K key, V usingValue) {
return map1.acquireUsing(key, usingValue);
}
@Override
@@ -21,6 +21,7 @@ package net.openhft.chronicle.map.fromdocs;
import net.openhft.affinity.AffinitySupport;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.ChronicleMapBuilder;
import net.openhft.chronicle.map.OffHeapUpdatableChronicleMapBuilder;
import net.openhft.lang.model.DataValueClasses;
import org.junit.Test;
@@ -55,8 +56,8 @@ public class OpenJDKAndHashMapExamplesTest {
File file = new File(TMP + "/chm-myBondPortfolioCHM-" + System.nanoTime());
file.deleteOnExit();
ChronicleMap<String, BondVOInterface> chm = ChronicleMapBuilder
.of(String.class, directClassFor(BondVOInterface.class))
ChronicleMap<String, BondVOInterface> chm = OffHeapUpdatableChronicleMapBuilder
.of(String.class, BondVOInterface.class)
.keySize(10)
.file(file)
.create();
@@ -76,8 +77,8 @@ public class OpenJDKAndHashMapExamplesTest {
mpx1030.setAskPx(109.7);
mpx1030.setBidPx(107.6);
ChronicleMap<String, BondVOInterface> chmB = ChronicleMapBuilder
.of(String.class, directClassFor(BondVOInterface.class))
ChronicleMap<String, BondVOInterface> chmB = OffHeapUpdatableChronicleMapBuilder
.of(String.class, BondVOInterface.class)
.keySize(10)
.file(file)
.create();
@@ -140,13 +140,13 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
}
@Override
public V getUsing(K key, V value) {
return d.getUsing(key, value);
public V getUsing(K key, V usingValue) {
return d.getUsing(key, usingValue);
}
@Override
public V acquireUsing(K key, V value) {
return d.acquireUsing(key, value);
public V acquireUsing(K key, V usingValue) {
return d.acquireUsing(key, usingValue);
}
@Override