/// <summary> /// Insert a packet of frames into the log at the appropriate termOffset as indicated by the term termOffset header. /// /// If the packet has already been inserted then this is a noop. /// </summary> /// <param name="termBuffer"> into which the packet should be inserted. </param> /// <param name="termOffset"> in the term at which the packet should be inserted. </param> /// <param name="packet"> containing a sequence of frames. </param> /// <param name="length"> of the packet of frames in bytes. </param> public static void Insert(IAtomicBuffer termBuffer, int termOffset, UnsafeBuffer packet, int length) { if (0 == termBuffer.GetInt(termOffset)) { termBuffer.PutBytes(termOffset + DataHeaderFlyweight.HEADER_LENGTH, packet, DataHeaderFlyweight.HEADER_LENGTH, length - DataHeaderFlyweight.HEADER_LENGTH); termBuffer.PutLong(termOffset + 24, packet.GetLong(24)); termBuffer.PutLong(termOffset + 16, packet.GetLong(16)); termBuffer.PutLong(termOffset + 8, packet.GetLong(8)); termBuffer.PutLongOrdered(termOffset, packet.GetLong(0)); } }
public void ShouldInsertIntoEmptyBuffer() { UnsafeBuffer packet = new UnsafeBuffer(new byte[256]); const int termOffset = 0; const int srcOffset = 0; const int length = 256; packet.PutInt(srcOffset, length); TermRebuilder.Insert(_termBuffer, termOffset, packet, length); A.CallTo(() => _termBuffer.PutBytes(termOffset + DataHeaderFlyweight.HEADER_LENGTH, packet, srcOffset + DataHeaderFlyweight.HEADER_LENGTH, length - DataHeaderFlyweight.HEADER_LENGTH)).MustHaveHappened() .Then(A.CallTo(() => _termBuffer.PutLong(termOffset + 24, packet.GetLong(24))).MustHaveHappened()) .Then(A.CallTo(() => _termBuffer.PutLong(termOffset + 16, packet.GetLong(16))).MustHaveHappened()) .Then(A.CallTo(() => _termBuffer.PutLong(termOffset + 8, packet.GetLong(8))).MustHaveHappened()) .Then(A.CallTo(() => _termBuffer.PutLongOrdered(termOffset, packet.GetLong(0))).MustHaveHappened()); }
public void SharedBuffer() { var bb = new byte[1024]; var ub1 = new UnsafeBuffer(bb, 0, 512); var ub2 = new UnsafeBuffer(bb, 512, 512); ub1.PutLong(Index, LongValue); ub2.PutLong(Index, 9876543210L); Assert.That(ub1.GetLong(Index), Is.EqualTo(LongValue)); }
private void CaptureEntriesFromBuffer(int limit, UnsafeBuffer buffer, List <Entry> entries) { for (int i = 0, length = limit; i < length; i += ENTRY_LENGTH) { int entryType = buffer.GetInt(i + ENTRY_TYPE_OFFSET); if (NULL_VALUE != entryType) { entries.Add(new Entry( buffer.GetLong(i + RECORDING_ID_OFFSET), buffer.GetLong(i + LEADERSHIP_TERM_ID_OFFSET), buffer.GetLong(i + LOG_POSITION_OFFSET), buffer.GetLong(i + TERM_POSITION_OFFSET), buffer.GetLong(i + TIMESTAMP_OFFSET), buffer.GetInt(i + MEMBER_ID_VOTE_OFFSET), entryType, nextEntryIndex)); } ++nextEntryIndex; } }
/// <summary> /// Get the raw value of the tail for the given partition. /// </summary> /// <param name="metaDataBuffer"> containing the tail counters. </param> /// <param name="partitionIndex"> for the tail counter. </param> /// <returns> the raw value of the tail for the current active partition. </returns> public static long RawTail(UnsafeBuffer metaDataBuffer, int partitionIndex) { return(metaDataBuffer.GetLong(TERM_TAIL_COUNTERS_OFFSET + BitUtil.SIZE_OF_LONG * partitionIndex)); }
public static long CorrelationId(UnsafeBuffer metaDataBuffer) { return(metaDataBuffer.GetLong(LOG_CORRELATION_ID_OFFSET)); }
/// <summary> /// Get the value stored in the reserve space at the end of a data frame header. /// /// Note: The value is in <seealso cref="ByteOrder.LittleEndian"/> format. /// </summary> /// <returns> the value stored in the reserve space at the end of a data frame header. </returns> /// <seealso cref="DataHeaderFlyweight"/> public long ReservedValue() { return(_buffer.GetLong(DataHeaderFlyweight.RESERVED_VALUE_OFFSET)); }
public override long Get() { return(_buffer.GetLong(_offset)); }
public long Get() { return(_buffer.GetLong(_offset)); }
/// <summary> /// Get the value of the term id into the tail counter. /// </summary> /// <returns> the current term id. </returns> public int TermId() { long rawTail = _metaDataBuffer.GetLong(LogBufferDescriptor.TERM_TAIL_COUNTER_OFFSET); return((int)((long)((ulong)rawTail >> 32))); }
public virtual long TimestampWeak() { return(buffer.GetLong(timestampFieldOffset)); }
public long RawTail() { return(_metaDataBuffer.GetLong((int)tailAddressOffset)); }
/// <summary> /// Get the reserved value field from the header. /// </summary> /// <param name="termBuffer"> containing the header. </param> /// <param name="frameOffset"> in the buffer where the header starts. </param> /// <returns> the reserved value field from the header. </returns> public static long ReservedValue(UnsafeBuffer termBuffer, int frameOffset) { return(termBuffer.GetLong(frameOffset + RESERVED_VALUE_OFFSET, ByteOrder.LittleEndian)); }