use of net.openhft.chronicle.queue.ChronicleQueueBuilder in project Chronicle-Queue by OpenHFT.
the class QueueWireHandler method getQueue.
private ChronicleQueue getQueue(StringBuilder cspText) {
ChronicleQueue queue;
if (cid == 0) {
// cid hasn't been passed in need to map it from csp
cid = cspToCid.computeIfAbsent(cspText.toString(), s -> cidCounter.incrementAndGet());
String[] parts = cspText.toString().split("/");
String filename = "/tmp/" + parts[1] + "/" + parts[2] + ".q";
queue = fileNameToChronicle.computeIfAbsent(filename, s -> {
try {
return new ChronicleQueueBuilder(filename).build();
} catch (IOException e) {
e.printStackTrace();
}
return null;
});
cidToQueue.put(cid, queue);
} else {
// if the cid has been created then there must be a corresponding queue
queue = cidToQueue.get(cid);
assert queue != null;
}
return queue;
}
use of net.openhft.chronicle.queue.ChronicleQueueBuilder in project Chronicle-Queue by OpenHFT.
the class ZipBytesRingBufferTest method testZipAndAppend.
@Test
public void testZipAndAppend() {
File file = null;
try {
NativeBytesStore allocate = NativeBytesStore.nativeStoreWithFixedCapacity(1024);
NativeBytesStore msgBytes = NativeBytesStore.nativeStoreWithFixedCapacity(150);
net.openhft.chronicle.bytes.Bytes message = msgBytes.bytes();
message.writeUTFΔ("Hello World");
message.flip();
file = File.createTempFile("chronicle", "q");
DirectChronicleQueue chronicle = (DirectChronicleQueue) new ChronicleQueueBuilder(file.getName()).build();
final long writeAddress = getHeader((SingleChronicleQueue) chronicle).getWriteByte();
final BytesRingBuffer ring = new BytesRingBuffer(allocate.bytes());
final ZippedDocumentAppender zippedDocumentAppender = new ZippedDocumentAppender(ring, chronicle);
zippedDocumentAppender.append(message);
long initialValue = chronicle.firstBytes();
AtomicLong offset = new AtomicLong(initialValue);
while (lastWrite((SingleChronicleQueue) chronicle) == writeAddress) {
// wait for data to be written ( via another thread )
}
// read the data from chronicle into actual
Bytes actual = NativeBytesStore.nativeStoreWithFixedCapacity(100).bytes();
chronicle.readDocument(offset, actual);
// "Hello World" zipped should be 12 chars
Assert.assertEquals(12, actual.flip().remaining());
} finally {
if (file != null)
file.delete();
}
}
Aggregations