Add an examples for distributed counters.

This commit is contained in:
Peter Lawrey
2014-10-04 10:30:06 +01:00
parent a7750e6826
commit d096fe9c91
@@ -0,0 +1,29 @@
package net.openhft.chronicle.map.example;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.ChronicleMapBuilder;
import net.openhft.lang.model.DataValueClasses;
import net.openhft.lang.values.LongValue;
import java.io.File;
import java.io.IOException;
public class DistributedSequenceMain {
public static void main(String... ignored) throws IOException {
Class<LongValue> longValueClass = DataValueClasses.directClassFor(LongValue.class);
ChronicleMap<String, LongValue> map =
ChronicleMapBuilder.of(String.class, longValueClass)
.entries(128)
.actualSegments(1)
.create(new File("/tmp/counters"));
LongValue value = DataValueClasses.newDirectReference(longValueClass);
map.acquireUsing("sequence", value);
for (int i = 0; i < 1000000; i++) {
long nextId = value.addAtomicValue(1);
}
map.close();
}
}