Java Code Examples for net.openhft.chronicle.bytes.NativeBytesStore#nativeStoreWithFixedCapacity()
The following examples show how to use
net.openhft.chronicle.bytes.NativeBytesStore#nativeStoreWithFixedCapacity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncrementalRefreshHolder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public boolean put(final IncrementalRefreshQueueEntry queueEntry, final long rptSeqNum) { if (rptSeqNumHolder < rptSeqNum) { rptSeqNumHolder = rptSeqNum; final MdpGroupEntry incrEntry = queueEntry.groupEntry; this.entrySize = incrEntry.getBlockLength(); this.matchEventIndicator = queueEntry.matchEventIndicator; this.incrPcktSeqNum = queueEntry.incrPcktSeqNum; if (store.capacity() < entrySize) { store.release(); store = NativeBytesStore.nativeStoreWithFixedCapacity(entrySize); } incrEntry.buffer().copyTo(incrEntry.getAbsoluteEntryOffset(), this.store, entrySize); this.sbeGroupType = incrEntry.getSbeGroupType(); return true; } else { if(logger.isTraceEnabled()) { logger.trace("Incremental Refresh Entry #{} data was not stored because too old", rptSeqNum); } return false; } }
Example 2
Source File: PacketHolder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 6 votes |
public boolean put(final MdpPacket mdpPacket, final long seqNum) { if (seqNumHolder < seqNum) { seqNumHolder = seqNum; packetSize = mdpPacket.getPacketSize(); if (store.capacity() < packetSize) { store.release(); store = NativeBytesStore.nativeStoreWithFixedCapacity(packetSize); } mdpPacket.buffer().copyTo(this.store); return true; } else { logger.trace("MDP Packet #{} data was not stored because too old", seqNum); return false; } }
Example 3
Source File: MDPOffHeapBuffer.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 5 votes |
public MDPOffHeapBuffer(int capacity) { NativeBytesStore<Void> emptyStore = NativeBytesStore.nativeStoreWithFixedCapacity(SbeConstants.MDP_PACKET_MAX_SIZE); emptyStore.writeUnsignedInt(MESSAGE_SEQ_NUM_OFFSET, UNDEFINED_VALUE); emptyPacket.buffer().copyFrom(emptyStore); data = new MdpPacket[capacity]; for (int i = 0; i < capacity; i++) { MdpPacket mdpPacket = MdpPacket.allocate(); mdpPacket.buffer().copyFrom(emptyStore); data[i] = mdpPacket; } }
Example 4
Source File: IncrementalRefreshPerfTest.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 5 votes |
private Set<Integer> generateTestPackets(final MdpPacket samplePckt, final int testPacketsNum) { this.testPackets = new ArrayList<>(testPacketsNum); final Map<Integer, Integer> rptSeqNums = new HashMap<>(); final NativeBytesStore<Void> store = NativeBytesStore.nativeStoreWithFixedCapacity(samplePckt.getPacketSize()); samplePckt.buffer().copyTo(store); for (int i = 1; i <= testPacketsNum; i++) { store.writeUnsignedInt(MESSAGE_SEQ_NUM_OFFSET, i); final Iterator<MdpMessage> mdpMessageIterator = samplePckt.iterator(); while (mdpMessageIterator.hasNext()) { final MdpMessage mdpMessage = mdpMessageIterator.next(); final MdpMessageType messageType = mdpHandlerBuilder.getMdpMessageTypes().getMessageType(mdpMessage.getSchemaId()); mdpMessage.setMessageType(messageType); if (mdpMessage.getGroup(MdConstants.NO_MD_ENTRIES, incrGroup)) { while (incrGroup.hashNext()) { incrGroup.next(); final int secId = incrGroup.getInt32(MdConstants.SECURITY_ID); if (!rptSeqNums.containsKey(secId)) { rptSeqNums.put(secId, 0); } final int incrRptSeqNum = rptSeqNums.get(secId) + 1; final SbeGroup sbeGroup = (SbeGroup) incrGroup; final SbeFieldType fieldType = sbeGroup.getSbeGroupType().getMetadataContainer().findField(RPT_SEQ_NUM); final int offset = ((SbeGroup)incrGroup).getAbsoluteEntryOffset() + fieldType.getFieldType().getOffset().intValue(); store.writeUnsignedInt(offset, incrRptSeqNum); rptSeqNums.put(secId, incrRptSeqNum); } } } final byte[] bytes = new byte[samplePckt.getPacketSize()]; store.copyTo(bytes); testPackets.add(bytes); } samplePckt.release(); return rptSeqNums.keySet(); }
Example 5
Source File: BytesRingBufferTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Before public void setup() { try { outBuffer = NativeBytesStore.nativeStoreWithFixedCapacity(12); out = outBuffer.bytes(); out.writeUTFΔ(EXPECTED); output = out.flip().bytes(); } catch (Throwable e) { e.printStackTrace(); fail(); } }
Example 6
Source File: BytesRingBufferTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void testSimpledSingleThreadedWriteRead() { try (NativeBytesStore<Void> nativeStore = NativeBytesStore.nativeStoreWithFixedCapacity(150)) { final BytesRingBuffer bytesRingBuffer = new BytesRingBuffer(nativeStore.bytes()); bytesRingBuffer.offer(data()); Bytes actual = bytesRingBuffer.take(maxSize -> input.clear()); assertEquals(EXPECTED, actual.readUTFΔ()); } }
Example 7
Source File: DirectChronicleQueueStringTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
private void writeSome(DirectChronicleQueue chronicle) { NativeBytesStore allocate = NativeBytesStore.nativeStoreWithFixedCapacity(EXPECTED_BYTES.length); final Bytes toWrite = allocate.bytes(); for (int i = 0; i < RUNS; i++) { toWrite.clear(); toWrite.write(EXPECTED_BYTES); toWrite.flip(); chronicle.appendDocument(toWrite); } }
Example 8
Source File: DirectChronicleQueueStringTest.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
private void readSome(DirectChronicleQueue chronicle) { NativeBytesStore allocate = NativeBytesStore.nativeStoreWithFixedCapacity(EXPECTED_BYTES.length); final Bytes toRead = allocate.bytes(); AtomicLong offset = new AtomicLong(chronicle.firstBytes()); for (int i = 0; i < RUNS; i++) { toRead.clear(); chronicle.readDocument(offset, toRead); } }
Example 9
Source File: ModelUtils.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 4 votes |
private static byte[] getMDPHeader(long sequence, long sendingTime){ final NativeBytesStore mdpHeader = NativeBytesStore.nativeStoreWithFixedCapacity(MDP_HEADER_SIZE); mdpHeader.writeUnsignedInt(MESSAGE_SEQ_NUM_OFFSET, sequence); mdpHeader.writeLong(MESSAGE_SENDING_TIME_OFFSET, sendingTime); return mdpHeader.toByteArray(); }
Example 10
Source File: IncrementalRefreshHolder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 4 votes |
public IncrementalRefreshHolder(final int incrQueueEntryDefSize) { store = NativeBytesStore.nativeStoreWithFixedCapacity(incrQueueEntryDefSize); }
Example 11
Source File: PacketHolder.java From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 | 4 votes |
public PacketHolder(final int incrQueueDefPacketSize) { store = NativeBytesStore.nativeStoreWithFixedCapacity(incrQueueDefPacketSize); }
Example 12
Source File: DoubleArray.java From Chronicle-Map with Apache License 2.0 | 4 votes |
public DoubleArray(int capacity) { bs = NativeBytesStore.nativeStoreWithFixedCapacity(BASE + capacity * 8L); bs.writeInt(CAPACITY, capacity); offset = 0; this.capacity = capacity; }
Example 13
Source File: ThroughputPerfMain2.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") public static void main(String[] args) { String base = path + "/delete-" + System.nanoTime() + ".me"; long start = System.nanoTime(); long count = 0; nbs = NativeBytesStore.nativeStoreWithFixedCapacity(size); long blockSize = OS.is64Bit() ? 4L << 30 : 256L << 20; try (ChronicleQueue q = SingleChronicleQueueBuilder.binary(base) .rollCycle(RollCycles.LARGE_HOURLY_XSPARSE) .blockSize(blockSize) .build()) { ExcerptAppender appender = q.acquireAppender(); count += appender.batchAppend(time * 1000, ThroughputPerfMain2::writeMessages); } nbs.releaseLast(); long mid = System.nanoTime(); long time1 = mid - start; Bytes bytes = Bytes.allocateElasticDirect(64); try (ChronicleQueue q = SingleChronicleQueueBuilder.binary(base) .rollCycle(RollCycles.LARGE_HOURLY_XSPARSE) .blockSize(blockSize) .build()) { ExcerptTailer tailer = q.createTailer(); for (long i = 0; i < count; i++) { try (DocumentContext dc = tailer.readingDocument()) { bytes.clear(); bytes.write(dc.wire().bytes()); } } } bytes.releaseLast(); long end = System.nanoTime(); long time2 = end - mid; System.out.printf("Writing %,d messages took %.3f seconds, at a rate of %,d per second%n", count, time1 / 1e9, (long) (1e9 * count / time1)); System.out.printf("Reading %,d messages took %.3f seconds, at a rate of %,d per second%n", count, time2 / 1e9, (long) (1e9 * count / time2)); System.gc(); // make sure its cleaned up for windows to delete. IOTools.deleteDirWithFiles(base, 2); }