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, ByteOrder.LittleEndian), buffer.GetLong(i + LEADERSHIP_TERM_ID_OFFSET, ByteOrder.LittleEndian), buffer.GetLong(i + TERM_BASE_LOG_POSITION_OFFSET, ByteOrder.LittleEndian), buffer.GetLong(i + TERM_POSITION_OFFSET, ByteOrder.LittleEndian), buffer.GetLong(i + TIMESTAMP_OFFSET, ByteOrder.LittleEndian), buffer.GetInt(i + MEMBER_ID_VOTE_OFFSET, ByteOrder.LittleEndian), entryType, nextEntryIndex)); } ++nextEntryIndex; } }
/// <summary> /// Try to gap fill the current term at a given offset if the gap contains no data. /// /// Note: the gap offset plus gap length must end on a <seealso cref="FrameDescriptor.FRAME_ALIGNMENT"/> boundary. /// </summary> /// <param name="logMetaDataBuffer"> containing the default headers </param> /// <param name="termBuffer"> to gap fill </param> /// <param name="termId"> for the current term. </param> /// <param name="gapOffset"> to fill from </param> /// <param name="gapLength"> to length of the gap. </param> /// <returns> true if the gap has been filled with a padding record or false if data found. </returns> public static bool TryFillGap(UnsafeBuffer logMetaDataBuffer, UnsafeBuffer termBuffer, int termId, int gapOffset, int gapLength) { int offset = gapOffset + gapLength - FrameDescriptor.FRAME_ALIGNMENT; while (offset >= gapOffset) { if (0 != termBuffer.GetInt(offset)) { return(false); } offset -= FrameDescriptor.FRAME_ALIGNMENT; } LogBufferDescriptor.ApplyDefaultHeader(logMetaDataBuffer, termBuffer, gapOffset); FrameDescriptor.FrameType(termBuffer, gapOffset, HeaderFlyweight.HDR_TYPE_PAD); FrameDescriptor.FrameTermOffset(termBuffer, gapOffset); FrameDescriptor.FrameTermId(termBuffer, gapOffset, termId); FrameDescriptor.FrameLengthOrdered(termBuffer, gapOffset, gapLength); return(true); }
/// <summary> /// Get the value of the page size used for this log. /// </summary> /// <param name="metaDataBuffer"> containing the metadata. </param> /// <returns> the value of the page size used for this log. </returns> public static int PageSize(UnsafeBuffer metaDataBuffer) { return(metaDataBuffer.GetInt(LOG_PAGE_SIZE_OFFSET)); }
/// <summary> /// Get the value of the Term Length used for this log. /// </summary> /// <param name="metaDataBuffer"> containing the metadata. </param> /// <returns> the value of the term length used for this log. </returns> public static int TermLength(UnsafeBuffer metaDataBuffer) { return(metaDataBuffer.GetInt(LOG_TERM_LENGTH_OFFSET)); }
public static int MtuLength(UnsafeBuffer metaDataBuffer) { return(metaDataBuffer.GetInt(LOG_MTU_LENGTH_OFFSET)); }
public static int InitialTermId(UnsafeBuffer metaDataBuffer) { return(metaDataBuffer.GetInt(LOG_INITIAL_TERM_ID_OFFSET)); }
/// <summary> /// This is called automatically by <seealso cref="Connect()"/> and its overloads. /// There is no need to call it from a client application. It is responsible for providing default /// values for options that are not individually changed through field setters. /// </summary> /// <returns> this Aeron.Context for method chaining. </returns> public Context Conclude() { try { _cncFile = new FileInfo(Path.Combine(_aeronDirectoryName, CncFileDescriptor.CNC_FILE)); if (_epochClock == null) { _epochClock = new SystemEpochClock(); } if (_nanoClock == null) { _nanoClock = new SystemNanoClock(); } if (_idleStrategy == null) { _idleStrategy = new SleepingIdleStrategy(IdleSleepMs); } if (CncFile() != null) { _cncByteBuffer = IoUtil.MapExistingFile(CncFile().FullName); _cncMetaDataBuffer = CncFileDescriptor.CreateMetaDataBuffer(_cncByteBuffer); var cncVersion = _cncMetaDataBuffer.GetInt(CncFileDescriptor.CncVersionOffset(0)); if (CncFileDescriptor.CNC_VERSION != cncVersion) { throw new InvalidOperationException( "aeron cnc file version not understood: version=" + cncVersion); } } if (_toClientBuffer == null) { var receiver = new BroadcastReceiver(CncFileDescriptor.CreateToClientsBuffer(_cncByteBuffer, _cncMetaDataBuffer)); _toClientBuffer = new CopyBroadcastReceiver(receiver); } if (_toDriverBuffer == null) { _toDriverBuffer = new ManyToOneRingBuffer(CncFileDescriptor.CreateToDriverBuffer(_cncByteBuffer, _cncMetaDataBuffer)); } if (CountersMetaDataBuffer() == null) { CountersMetaDataBuffer(CncFileDescriptor.CreateCountersMetaDataBuffer(_cncByteBuffer, _cncMetaDataBuffer)); } if (CountersValuesBuffer() == null) { CountersValuesBuffer(CncFileDescriptor.CreateCountersValuesBuffer(_cncByteBuffer, _cncMetaDataBuffer)); } _interServiceTimeout = CncFileDescriptor.ClientLivenessTimeout(_cncMetaDataBuffer); if (_logBuffersFactory == null) { _logBuffersFactory = new MappedLogBuffersFactory(); } if (_errorHandler == null) { _errorHandler = DEFAULT_ERROR_HANDLER; } if (_availableImageHandler == null) { _availableImageHandler = image => { }; } if (_unavailableImageHandler == null) { _unavailableImageHandler = image => { }; } } catch ( Exception ex) { Console.WriteLine("***"); Console.WriteLine("***"); Console.WriteLine("Failed to connect to the Media Driver - is it currently running?"); Console.WriteLine("***"); Console.WriteLine("***"); throw new InvalidOperationException("Could not initialise communication buffers", ex); } return(this); }
/// <summary> /// Get the session id 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 session id field. </returns> public static int FrameSessionId(UnsafeBuffer buffer, int termOffset) { return(buffer.GetInt(SessionIdOffset(termOffset), ByteOrder.LittleEndian)); }
/// <summary> /// Is the frame at data frame at the beginning of packet a heartbeat message? /// </summary> /// <param name="packet"> containing the data frame. </param> /// <param name="length"> of the data frame. </param> /// <returns> true if a heartbeat otherwise false. </returns> public static bool IsHeartbeat(UnsafeBuffer packet, int length) { return(length == HEADER_LENGTH && packet.GetInt(0) == 0); }
public static int TermOffset(UnsafeBuffer termBuffer, int frameOffset) { return(termBuffer.GetInt(frameOffset + TERM_OFFSET_FIELD_OFFSET, ByteOrder.LittleEndian)); }
public static int StreamId(UnsafeBuffer termBuffer, int frameOffset) { return(termBuffer.GetInt(frameOffset + STREAM_ID_FIELD_OFFSET, ByteOrder.LittleEndian)); }
public static int SessionId(UnsafeBuffer termBuffer, int frameOffset) { return(termBuffer.GetInt(frameOffset + SESSION_ID_FIELD_OFFSET, ByteOrder.LittleEndian)); }
public HeaderWriter(UnsafeBuffer defaultHeader) { _versionFlagsType = (long)defaultHeader.GetInt(HeaderFlyweight.VERSION_FIELD_OFFSET) << 32; _sessionId = (long)defaultHeader.GetInt(DataHeaderFlyweight.SESSION_ID_FIELD_OFFSET) << 32; _streamId = defaultHeader.GetInt(DataHeaderFlyweight.STREAM_ID_FIELD_OFFSET) & 0xFFFFFFFFL; }
public virtual int VersionWeak() { return(buffer.GetInt(versionFieldOffset)); }
public int ClusterId() { return(buffer.GetInt(MarkFileHeaderDecoder.ClusterIdEncodingOffset())); }
/// <summary> /// Get the fragment length 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 fragment length field from the header. </returns> public static int FragmentLength(UnsafeBuffer termBuffer, int frameOffset) { return(termBuffer.GetInt(frameOffset + FRAME_LENGTH_FIELD_OFFSET, ByteOrder.LittleEndian)); }