/// <summary> /// Read all the errors in a log since a given timestamp. /// </summary> /// <param name="buffer"> containing the <seealso cref="DistinctErrorLog"/>. </param> /// <param name="consumer"> to be called for each exception encountered. </param> /// <param name="sinceTimestamp"> for filtering errors that have been recorded since this time. </param> /// <returns> the number of entries that has been read. </returns> public static int Read(IAtomicBuffer buffer, ErrorConsumer consumer, long sinceTimestamp) { int entries = 0; int offset = 0; int capacity = buffer.Capacity; while (offset < capacity) { int length = buffer.GetIntVolatile(offset + DistinctErrorLog.LengthOffset); if (0 == length) { break; } long lastObservationTimestamp = buffer.GetLongVolatile(offset + DistinctErrorLog.LastObservationTimestampOffset); if (lastObservationTimestamp >= sinceTimestamp) { ++entries; consumer( buffer.GetInt(offset + DistinctErrorLog.ObservationCountOffset), buffer.GetLong(offset + DistinctErrorLog.FirstObservationTimestampOffset), lastObservationTimestamp, buffer.GetStringUtf8(offset + DistinctErrorLog.EncodedErrorOffset, length - DistinctErrorLog.EncodedErrorOffset)); } offset += BitUtil.Align(length, DistinctErrorLog.RecordAlignment); } return entries; }
/// <summary> /// Read all the errors in a log since a given timestamp. /// </summary> /// <param name="buffer"> containing the <seealso cref="DistinctErrorLog"/>. </param> /// <param name="consumer"> to be called for each exception encountered. </param> /// <param name="sinceTimestamp"> for filtering errors that have been recorded since this time. </param> /// <returns> the number of entries that has been read. </returns> public static int Read(IAtomicBuffer buffer, ErrorConsumer consumer, long sinceTimestamp) { int entries = 0; int offset = 0; int capacity = buffer.Capacity; while (offset < capacity) { int length = buffer.GetIntVolatile(offset + DistinctErrorLog.LengthOffset); if (0 == length) { break; } long lastObservationTimestamp = buffer.GetLongVolatile(offset + DistinctErrorLog.LastObservationTimestampOffset); if (lastObservationTimestamp >= sinceTimestamp) { ++entries; consumer( buffer.GetInt(offset + DistinctErrorLog.ObservationCountOffset), buffer.GetLong(offset + DistinctErrorLog.FirstObservationTimestampOffset), lastObservationTimestamp, buffer.GetStringWithoutLengthUtf8(offset + DistinctErrorLog.EncodedErrorOffset, length - DistinctErrorLog.EncodedErrorOffset)); } offset += BitUtil.Align(length, DistinctErrorLog.RecordAlignment); } return(entries); }
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); A.CallTo(() => _termBuffer.GetInt(0)).Returns(length); TermRebuilder.Insert(_termBuffer, termOffset, packet, length); A.CallTo(() => _termBuffer.PutBytes(termOffset, packet, srcOffset, length)).MustHaveHappened() .Then(A.CallTo(() => _termBuffer.PutIntOrdered(termOffset, length)).MustHaveHappened()); }
/// <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)); } }
/// <summary> /// Get the maximum log position that a tracking session can reach. The get operation has volatile semantics. /// </summary> /// <param name="counters"> to search within. </param> /// <param name="counterId"> for the active commit position. </param> /// <returns> the log position if found otherwise <see cref="Aeron.NULL_VALUE"/>. </returns> public static long GetMaxLogPosition(CountersReader counters, int counterId) { IAtomicBuffer buffer = counters.MetaDataBuffer; if (counters.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED) { int recordOffset = CountersReader.MetaDataOffset(counterId); if (buffer.GetInt(recordOffset + CountersReader.TYPE_ID_OFFSET) == COMMIT_POSITION_TYPE_ID) { return(buffer.GetLongVolatile(recordOffset + CountersReader.KEY_OFFSET + MAX_LOG_POSITION_OFFSET)); } } return(Aeron.Aeron.NULL_VALUE); }
/// <summary> /// Set the maximum log position that a tracking session can reach. The set operation has volatile semantics. /// </summary> /// <param name="counters"> to search within. </param> /// <param name="counterId"> for the active commit position. </param> /// <param name="value"> to set for the new max position. </param> /// <exception cref="ClusterException"> if the counter id is not valid. </exception> public static void SetMaxLogPosition(CountersReader counters, int counterId, long value) { IAtomicBuffer buffer = counters.MetaDataBuffer; if (counters.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED) { int recordOffset = CountersReader.MetaDataOffset(counterId); if (buffer.GetInt(recordOffset + CountersReader.TYPE_ID_OFFSET) == COMMIT_POSITION_TYPE_ID) { buffer.PutLongVolatile(recordOffset + CountersReader.KEY_OFFSET + MAX_LOG_POSITION_OFFSET, value); return; } } throw new ClusterException("Counter id not valid: " + counterId); }
/// <summary> /// Find the counter id for a type of counter in a cluster. /// </summary> /// <param name="counters"> to search within. </param> /// <param name="typeId"> of the counter. </param> /// <param name="clusterId"> to which the allocated counter belongs. </param> /// <returns> the matching counter id or <seealso cref="Aeron.Aeron.NULL_VALUE"/> if not found. </returns> public static int Find(CountersReader counters, int typeId, int clusterId) { IAtomicBuffer buffer = counters.MetaDataBuffer; for (int i = 0, size = counters.MaxCounterId; i < size; i++) { int recordOffset = CountersReader.MetaDataOffset(i); if (counters.GetCounterState(i) == CountersReader.RECORD_ALLOCATED && counters.GetCounterTypeId(i) == typeId && buffer.GetInt(recordOffset + CountersReader.KEY_OFFSET) == clusterId) { return(i); } } return(Aeron.Aeron.NULL_VALUE); }
/// <summary> /// Type of the message received. /// </summary> /// <returns> typeId of the message received. </returns> public int TypeId() { return(_buffer.GetInt(RecordDescriptor.GetTypeOffset(_recordOffset))); }
public static int FrameLength(IAtomicBuffer buffer, int termOffset) { return(buffer.GetInt(termOffset)); }
public void ShouldGetIntFromNativeBuffer(IAtomicBuffer buffer) { Marshal.WriteInt32(buffer.BufferPointer, Index, IntValue); Assert.That(buffer.GetInt(Index), Is.EqualTo(IntValue)); }
public void ShouldReceiveFirstMessageFromBuffer() { const int length = 8; var recordLength = length + RecordDescriptor.HeaderLength; var recordLengthAligned = BitUtil.Align(recordLength, RecordDescriptor.RecordAlignment); long tail = recordLengthAligned; var latestRecord = tail - recordLengthAligned; var recordOffset = (int)latestRecord; A.CallTo(() => _buffer.GetLongVolatile(TailIntentCounterOffset)).Returns(tail); A.CallTo(() => _buffer.GetLongVolatile(TailCounterIndex)).Returns(tail); A.CallTo(() => _buffer.GetInt(RecordDescriptor.GetLengthOffset(recordOffset))).Returns(recordLength); A.CallTo(() => _buffer.GetInt(RecordDescriptor.GetTypeOffset(recordOffset))).Returns(MsgTypeID); Assert.True(_broadcastReceiver.ReceiveNext()); Assert.AreEqual(MsgTypeID, _broadcastReceiver.TypeId()); Assert.AreEqual(_buffer, _broadcastReceiver.Buffer()); Assert.AreEqual(RecordDescriptor.GetMsgOffset(recordOffset), _broadcastReceiver.Offset()); Assert.AreEqual(length, _broadcastReceiver.Length()); Assert.True(_broadcastReceiver.Validate()); A.CallTo(() => _buffer.GetLongVolatile(TailCounterIndex)).MustHaveHappened(); A.CallTo(() => _buffer.GetLongVolatile(TailIntentCounterOffset)).MustHaveHappened(); }
/// <summary> /// Get the length of a frame from the header. /// </summary> /// <param name="buffer"> containing the frame. </param> /// <param name="termOffset"> at which a frame begins. </param> /// <returns> the value for the frame length. </returns> public static int FrameLength(IAtomicBuffer buffer, int termOffset) { return buffer.GetInt(termOffset); }