Skip to content

Commit

Permalink
QUEUE-16 renamed chronicle to ChronicleQueue to be consistent with th…
Browse files Browse the repository at this point in the history
…e naming we use for ChronicleMap
  • Loading branch information
Rob Austin committed Feb 11, 2015
1 parent 4cf3327 commit 98bd46a
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 48 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
* C-type byte arrays that you can access any random index "directly" using pointers. File portions can be used as * C-type byte arrays that you can access any random index "directly" using pointers. File portions can be used as
* ByteBuffers if the portion is mapped into memory. * ByteBuffers if the portion is mapped into memory.
* *
* <p>{@link Chronicle} (now in the specific sense) is the main interface for management and can * <p>{@link ChronicleQueue} (now in the specific sense) is the main interface for management and can
* be seen as the "Collection class" of the <em>Chronicle</em> environment. You will reserve a portion of memory and * be seen as the "Collection class" of the <em>Chronicle</em> environment. You will reserve a portion of memory and
* then put/fetch/update records using the {@link Chronicle} interface.</p> * then put/fetch/update records using the {@link ChronicleQueue} interface.</p>
* *
* <p>{@link Excerpt} is the main data container in a {@link Chronicle}, * <p>{@link Excerpt} is the main data container in a {@link ChronicleQueue},
* each Chronicle is composed of Excerpts. Putting data to a chronicle means starting a new Excerpt, writing data into * each Chronicle is composed of Excerpts. Putting data to a chronicle means starting a new Excerpt, writing data into
* it and finishing the Excerpt at the end.</p> * it and finishing the Excerpt at the end.</p>
* *
Expand All @@ -36,7 +36,7 @@
* *
* @author peter.lawrey * @author peter.lawrey
*/ */
public interface Chronicle extends Closeable { public interface ChronicleQueue extends Closeable {
/** /**
* @return A descriptive name for this chronicle which can be used for logging. * @return A descriptive name for this chronicle which can be used for logging.
*/ */
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.openhft.chronicle.queue; package net.openhft.chronicle.queue;


import net.openhft.chronicle.queue.impl.SingleChronicle; import net.openhft.chronicle.queue.impl.SingleChronicleQueue;


import java.io.IOException; import java.io.IOException;


Expand All @@ -20,7 +20,7 @@ public ChronicleQueueBuilder blockSize(int blockSize) {
return this; return this;
} }


public Chronicle build() throws IOException { public ChronicleQueue build() throws IOException {
return new SingleChronicle(name, blockSize); return new SingleChronicleQueue(name, blockSize);
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import net.openhft.lang.model.constraints.NotNull; import net.openhft.lang.model.constraints.NotNull;


/** /**
* The main data container of a {@link Chronicle}, an extended version of {@link ExcerptTailer} which also facilitates * The main data container of a {@link ChronicleQueue}, an extended version of {@link ExcerptTailer} which also facilitates
* random access. * random access.
* *
* @author peter.lawrey * @author peter.lawrey
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.function.Consumer; import java.util.function.Consumer;


/** /**
* The component that facilitates sequentially writing data to a {@link Chronicle}. * The component that facilitates sequentially writing data to a {@link ChronicleQueue}.
* *
* @author peter.lawrey * @author peter.lawrey
*/ */
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public interface ExcerptCommon {
/** /**
* @return the chronicle associated with this Excerpt * @return the chronicle associated with this Excerpt
*/ */
Chronicle chronicle(); ChronicleQueue chronicle();
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.function.Function; import java.util.function.Function;


/** /**
* The component that facilitates sequentially reading data from a {@link Chronicle}. * The component that facilitates sequentially reading data from a {@link ChronicleQueue}.
* *
* @author peter.lawrey * @author peter.lawrey
*/ */
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.openhft.chronicle.queue.impl; package net.openhft.chronicle.queue.impl;


import net.openhft.chronicle.queue.Chronicle; import net.openhft.chronicle.queue.ChronicleQueue;
import net.openhft.lang.io.Bytes; import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.MultiStoreBytes; import net.openhft.lang.io.MultiStoreBytes;


Expand All @@ -9,7 +9,7 @@
/** /**
* Created by peter.lawrey on 03/02/15. * Created by peter.lawrey on 03/02/15.
*/ */
public interface DirectChronicle extends Chronicle { public interface DirectChronicleQueue extends ChronicleQueue {
void appendDocument(Bytes buffer); void appendDocument(Bytes buffer);


boolean readDocument(AtomicLong offset, Bytes buffer); boolean readDocument(AtomicLong offset, Bytes buffer);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Header init(Compression compression) {
uuid = UUID.randomUUID(); uuid = UUID.randomUUID();
created = ZonedDateTime.now(); created = ZonedDateTime.now();
user = System.getProperty("user.name"); user = System.getProperty("user.name");
host = SingleChronicle.getHostName(); host = SingleChronicleQueue.getHostName();
this.compression = compression.name(); this.compression = compression.name();
writeByte.setOrderedValue(PADDED_SIZE); writeByte.setOrderedValue(PADDED_SIZE);
return this; return this;
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.openhft.chronicle.queue.impl; package net.openhft.chronicle.queue.impl;


import net.openhft.chronicle.queue.Chronicle; import net.openhft.chronicle.queue.ChronicleQueue;
import net.openhft.chronicle.queue.ExcerptAppender; import net.openhft.chronicle.queue.ExcerptAppender;
import net.openhft.chronicle.wire.BinaryWire; import net.openhft.chronicle.wire.BinaryWire;
import net.openhft.chronicle.wire.Wire; import net.openhft.chronicle.wire.Wire;
Expand All @@ -15,13 +15,13 @@
*/ */
public class SingleAppender implements ExcerptAppender { public class SingleAppender implements ExcerptAppender {


private final DirectChronicle chronicle; private final DirectChronicleQueue chronicle;
private final ChronicleWireOut wireOut; private final ChronicleWireOut wireOut;
private final Bytes buffer = DirectStore.allocateLazy(128 * 1024).bytes(); private final Bytes buffer = DirectStore.allocateLazy(128 * 1024).bytes();
private final Wire wire = new BinaryWire(buffer); private final Wire wire = new BinaryWire(buffer);


public SingleAppender(Chronicle chronicle) { public SingleAppender(ChronicleQueue chronicle) {
this.chronicle = (DirectChronicle) chronicle; this.chronicle = (DirectChronicleQueue) chronicle;
wireOut = new ChronicleWireOut(null); wireOut = new ChronicleWireOut(null);
} }


Expand Down Expand Up @@ -54,7 +54,7 @@ public long lastWrittenIndex() {
} }


@Override @Override
public Chronicle chronicle() { public ChronicleQueue chronicle() {
return chronicle; return chronicle;
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* *
* Created by peter on 30/01/15. * Created by peter on 30/01/15.
*/ */
public class SingleChronicle implements Chronicle, DirectChronicle { public class SingleChronicleQueue implements ChronicleQueue, DirectChronicleQueue {
static final long MAGIC_OFFSET = 0L; static final long MAGIC_OFFSET = 0L;
static final long HEADER_OFFSET = 8L; static final long HEADER_OFFSET = 8L;
static final long UNINITIALISED = 0L; static final long UNINITIALISED = 0L;
Expand All @@ -46,7 +46,7 @@ public class SingleChronicle implements Chronicle, DirectChronicle {
private final Bytes bytes; private final Bytes bytes;
private long firstBytes = -1; private long firstBytes = -1;


public SingleChronicle(String filename, long blockSize) throws IOException { public SingleChronicleQueue(String filename, long blockSize) throws IOException {
file = new MappedFile(filename, blockSize); file = new MappedFile(filename, blockSize);
headerMemory = file.acquire(0); headerMemory = file.acquire(0);
bytes = headerMemory.bytes(); bytes = headerMemory.bytes();
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.openhft.chronicle.queue.impl; package net.openhft.chronicle.queue.impl;


import net.openhft.chronicle.queue.Chronicle; import net.openhft.chronicle.queue.ChronicleQueue;
import net.openhft.chronicle.queue.ExcerptTailer; import net.openhft.chronicle.queue.ExcerptTailer;
import net.openhft.chronicle.wire.BinaryWire; import net.openhft.chronicle.wire.BinaryWire;
import net.openhft.chronicle.wire.Wire; import net.openhft.chronicle.wire.Wire;
Expand All @@ -13,13 +13,13 @@
* Created by peter.lawrey on 30/01/15. * Created by peter.lawrey on 30/01/15.
*/ */
public class SingleTailer implements ExcerptTailer { public class SingleTailer implements ExcerptTailer {
private final DirectChronicle chronicle; private final DirectChronicleQueue chronicle;
long index; long index;
private final MultiStoreBytes bytes = new MultiStoreBytes(); private final MultiStoreBytes bytes = new MultiStoreBytes();
private final Wire wire = new BinaryWire(bytes); private final Wire wire = new BinaryWire(bytes);


public SingleTailer(Chronicle chronicle) { public SingleTailer(ChronicleQueue chronicle) {
this.chronicle = (DirectChronicle) chronicle; this.chronicle = (DirectChronicleQueue) chronicle;
toStart(); toStart();
} }


Expand Down Expand Up @@ -53,7 +53,7 @@ public ExcerptTailer toEnd() {
} }


@Override @Override
public Chronicle chronicle() { public ChronicleQueue chronicle() {
return chronicle; return chronicle;
} }
} }
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,10 @@
package net.openhft.chronicle.queue.impl.ringbuffer; package net.openhft.chronicle.queue.impl.ringbuffer;


import net.openhft.lang.Jvm;
import net.openhft.lang.io.Bytes; import net.openhft.lang.io.Bytes;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;


import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicLong;

/** /**
* Multi writer single Reader, zero GC, ring buffer * Multi writer single Reader, zero GC, ring buffer
* *
Expand Down Expand Up @@ -177,7 +175,7 @@ private class Header {
private final long writeUpToOffset; private final long writeUpToOffset;
private final long readLocationOffset; private final long readLocationOffset;
private final Bytes buffer; private final Bytes buffer;
private final boolean vmSupportsLongCAS;


/** /**
* @param buffer the bytes for the header * @param buffer the bytes for the header
Expand All @@ -201,17 +199,12 @@ private Header(@NotNull Bytes buffer) throws Exception {


this.buffer = buffer.bytes(start, buffer.position()); this.buffer = buffer.bytes(start, buffer.position());



Field vm_supports_long_cas = AtomicLong.class.getDeclaredField("VM_SUPPORTS_LONG_CAS");
vm_supports_long_cas.setAccessible(true);
vmSupportsLongCAS = (Boolean) vm_supports_long_cas.get(null);


} }


private boolean compareAndSetWriteLocation(long expectedValue, long newValue) { private boolean compareAndSetWriteLocation(long expectedValue, long newValue) {


// return buffer.compareAndSwapLong(writeLocationOffset, expectedValue, newValue); if (Jvm.VMSupportsCS8())
return buffer.compareAndSwapLong(writeLocationOffset, expectedValue, newValue);
synchronized (this) { synchronized (this) {
if (expectedValue == getWriteLocation()) { if (expectedValue == getWriteLocation()) {
setWriteLocation(newValue); setWriteLocation(newValue);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


public class ChronicleTest { public class ChronicleQueueTest {


public static final int RUNS = 1000000; public static final int RUNS = 1000000;
public static final String TMP = new File("/tmp").isDirectory() ? "/tmp" : System.getProperty("java.io.tmpdir"); public static final String TMP = new File("/tmp").isDirectory() ? "/tmp" : System.getProperty("java.io.tmpdir");
Expand All @@ -28,7 +28,7 @@ public void testCreateAppender() throws Exception {
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
String name = TMP + "/single" + start + "-" + j + ".q"; String name = TMP + "/single" + start + "-" + j + ".q";
new File(name).deleteOnExit(); new File(name).deleteOnExit();
Chronicle chronicle = new ChronicleQueueBuilder(name).build(); ChronicleQueue chronicle = new ChronicleQueueBuilder(name).build();


futureList.add(ForkJoinPool.commonPool().submit(() -> { futureList.add(ForkJoinPool.commonPool().submit(() -> {
writeSome(chronicle); writeSome(chronicle);
Expand All @@ -43,7 +43,7 @@ public void testCreateAppender() throws Exception {
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
String name = TMP + "/single" + start + "-" + j + ".q"; String name = TMP + "/single" + start + "-" + j + ".q";
new File(name).deleteOnExit(); new File(name).deleteOnExit();
Chronicle chronicle = new ChronicleQueueBuilder(name).build(); ChronicleQueue chronicle = new ChronicleQueueBuilder(name).build();


futureList.add(ForkJoinPool.commonPool().submit(() -> { futureList.add(ForkJoinPool.commonPool().submit(() -> {
readSome(chronicle); readSome(chronicle);
Expand All @@ -59,7 +59,7 @@ public void testCreateAppender() throws Exception {
} }
} }


private void readSome(Chronicle chronicle) throws IOException { private void readSome(ChronicleQueue chronicle) throws IOException {
ExcerptTailer tailer = chronicle.createTailer(); ExcerptTailer tailer = chronicle.createTailer();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
// TODO check this is still needed in future versions. // TODO check this is still needed in future versions.
Expand All @@ -69,7 +69,7 @@ private void readSome(Chronicle chronicle) throws IOException {
} }
} }


private void writeSome(Chronicle chronicle) throws IOException { private void writeSome(ChronicleQueue chronicle) throws IOException {
ExcerptAppender appender = chronicle.createAppender(); ExcerptAppender appender = chronicle.createAppender();
for (int i = 0; i < RUNS; i++) { for (int i = 0; i < RUNS; i++) {
appender.writeDocument(wire -> wire.write(TestKey.test).text("Hello World23456789012345678901234567890")); appender.writeDocument(wire -> wire.write(TestKey.test).text("Hello World23456789012345678901234567890"));
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.openhft.chronicle.queue; package net.openhft.chronicle.queue;


import net.openhft.chronicle.queue.impl.DirectChronicle; import net.openhft.chronicle.queue.impl.DirectChronicleQueue;
import net.openhft.lang.io.Bytes; import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.DirectStore; import net.openhft.lang.io.DirectStore;
import org.junit.Test; import org.junit.Test;
Expand Down Expand Up @@ -29,7 +29,7 @@
Threads: 10 - Write rate 143.6 M/s - Read rate 268.7 M/s Threads: 10 - Write rate 143.6 M/s - Read rate 268.7 M/s
Threads: 11 - Write rate 161.7 M/s - Read rate 260.8 M/s Threads: 11 - Write rate 161.7 M/s - Read rate 260.8 M/s
*/ */
public class DirectChronicleStringTest { public class DirectChronicleQueueStringTest {


public static final int RUNS = 1000000; public static final int RUNS = 1000000;
public static final String EXPECTED_STRING = "Hello World23456789012345678901234567890"; public static final String EXPECTED_STRING = "Hello World23456789012345678901234567890";
Expand All @@ -45,7 +45,7 @@ public void testCreateAppender() throws Exception {
for (int j = 0; j < t; j++) { for (int j = 0; j < t; j++) {
String name = TMP + "/single" + start + "-" + j + ".q"; String name = TMP + "/single" + start + "-" + j + ".q";
new File(name).deleteOnExit(); new File(name).deleteOnExit();
DirectChronicle chronicle = (DirectChronicle) new ChronicleQueueBuilder(name) DirectChronicleQueue chronicle = (DirectChronicleQueue) new ChronicleQueueBuilder(name)
.build(); .build();


futureList.add(ForkJoinPool.commonPool().submit(() -> { futureList.add(ForkJoinPool.commonPool().submit(() -> {
Expand All @@ -61,7 +61,7 @@ public void testCreateAppender() throws Exception {
for (int j = 0; j < t; j++) { for (int j = 0; j < t; j++) {
String name = TMP + "/single" + start + "-" + j + ".q"; String name = TMP + "/single" + start + "-" + j + ".q";
new File(name).deleteOnExit(); new File(name).deleteOnExit();
DirectChronicle chronicle = (DirectChronicle) new ChronicleQueueBuilder(name) DirectChronicleQueue chronicle = (DirectChronicleQueue) new ChronicleQueueBuilder(name)
.build(); .build();


futureList.add(ForkJoinPool.commonPool().submit(() -> { futureList.add(ForkJoinPool.commonPool().submit(() -> {
Expand All @@ -78,7 +78,7 @@ public void testCreateAppender() throws Exception {
} }
} }


private void readSome(DirectChronicle chronicle) throws IOException { private void readSome(DirectChronicleQueue chronicle) throws IOException {
final Bytes toRead = DirectStore.allocate(EXPECTED_BYTES.length).bytes(); final Bytes toRead = DirectStore.allocate(EXPECTED_BYTES.length).bytes();
AtomicLong offset = new AtomicLong(chronicle.firstBytes()); AtomicLong offset = new AtomicLong(chronicle.firstBytes());
for (int i = 0; i < RUNS; i++) { for (int i = 0; i < RUNS; i++) {
Expand All @@ -87,7 +87,7 @@ private void readSome(DirectChronicle chronicle) throws IOException {
} }
} }


private void writeSome(DirectChronicle chronicle) throws IOException { private void writeSome(DirectChronicleQueue chronicle) throws IOException {
final Bytes toWrite = DirectStore.allocate(EXPECTED_BYTES.length).bytes(); final Bytes toWrite = DirectStore.allocate(EXPECTED_BYTES.length).bytes();
toWrite.write(EXPECTED_BYTES); toWrite.write(EXPECTED_BYTES);
for (int i = 0; i < RUNS; i++) { for (int i = 0; i < RUNS; i++) {
Expand Down

0 comments on commit 98bd46a

Please sign in to comment.