public virtual void SetUp() { RcvBuffer = new UnsafeBuffer(new byte[ALIGNED_FRAME_LENGTH]); DataHeader = new DataHeaderFlyweight(); MockFragmentHandler = A.Fake<FragmentHandler>(); MockControlledFragmentHandler = A.Fake<IControlledFragmentHandler>(); Position = A.Fake<IPosition>(options => options.Wrapping(new AtomicLongPosition())); LogBuffers = A.Fake<LogBuffers>(); ErrorHandler = A.Fake<ErrorHandler>(); Subscription = A.Fake<Subscription>(); AtomicBuffers = new UnsafeBuffer[(LogBufferDescriptor.PARTITION_COUNT * 2) + 1]; TermBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; DataHeader.Wrap(RcvBuffer); for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { AtomicBuffers[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); TermBuffers[i] = AtomicBuffers[i]; AtomicBuffers[i + LogBufferDescriptor.PARTITION_COUNT] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_META_DATA_LENGTH]); } AtomicBuffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX] = new UnsafeBuffer(new byte[LogBufferDescriptor.LOG_META_DATA_LENGTH]); A.CallTo(() => LogBuffers.AtomicBuffers()).Returns(AtomicBuffers); A.CallTo(() => LogBuffers.TermLength()).Returns(TERM_BUFFER_LENGTH); }
public virtual void SetUp() { RcvBuffer = new UnsafeBuffer(new byte[ALIGNED_FRAME_LENGTH]); DataHeader = new DataHeaderFlyweight(); MockFragmentHandler = A.Fake <FragmentHandler>(); MockControlledFragmentHandler = A.Fake <IControlledFragmentHandler>(); Position = A.Fake <IPosition>(options => options.Wrapping(new AtomicLongPosition())); LogBuffers = A.Fake <LogBuffers>(); ErrorHandler = A.Fake <ErrorHandler>(); Subscription = A.Fake <Subscription>(); AtomicBuffers = new UnsafeBuffer[(LogBufferDescriptor.PARTITION_COUNT * 2) + 1]; TermBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; DataHeader.Wrap(RcvBuffer); for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { AtomicBuffers[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); TermBuffers[i] = AtomicBuffers[i]; AtomicBuffers[i + LogBufferDescriptor.PARTITION_COUNT] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_META_DATA_LENGTH]); } AtomicBuffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX] = new UnsafeBuffer(new byte[LogBufferDescriptor.LOG_META_DATA_LENGTH]); A.CallTo(() => LogBuffers.AtomicBuffers()).Returns(AtomicBuffers); A.CallTo(() => LogBuffers.TermLength()).Returns(TERM_BUFFER_LENGTH); }
internal Publication(ClientConductor clientConductor, string channel, int streamId, int sessionId, IReadablePosition positionLimit, LogBuffers logBuffers, long registrationId) { var buffers = logBuffers.AtomicBuffers(); var logMetaDataBuffer = buffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX]; for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { _termAppenders[i] = new TermAppender(buffers[i], buffers[i + LogBufferDescriptor.PARTITION_COUNT]); } var termLength = logBuffers.TermLength(); _maxPayloadLength = LogBufferDescriptor.MtuLength(logMetaDataBuffer) - DataHeaderFlyweight.HEADER_LENGTH; MaxMessageLength = FrameDescriptor.ComputeMaxMessageLength(termLength); _clientConductor = clientConductor; Channel = channel; StreamId = streamId; SessionId = sessionId; InitialTermId = LogBufferDescriptor.InitialTermId(logMetaDataBuffer); _logMetaDataBuffer = logMetaDataBuffer; RegistrationId = registrationId; _positionLimit = positionLimit; _logBuffers = logBuffers; _positionBitsToShift = IntUtil.NumberOfTrailingZeros(termLength); _headerWriter = new HeaderWriter(LogBufferDescriptor.DefaultFrameHeader(logMetaDataBuffer)); }
/// <summary> /// Construct a new image over a log to represent a stream of messages from a <seealso cref="Publication"/>. /// </summary> /// <param name="subscription"> to which this <seealso cref="Image"/> belongs. </param> /// <param name="sessionId"> of the stream of messages. </param> /// <param name="subscriberPosition"> for indicating the position of the subscriber in the stream. </param> /// <param name="logBuffers"> containing the stream of messages. </param> /// <param name="errorHandler"> to be called if an error occurs when polling for messages. </param> /// <param name="sourceIdentity"> of the source sending the stream of messages. </param> /// <param name="correlationId"> of the request to the media driver. </param> public Image(Subscription subscription, int sessionId, IPosition subscriberPosition, LogBuffers logBuffers, ErrorHandler errorHandler, string sourceIdentity, long correlationId) { Subscription = subscription; SessionId = sessionId; _subscriberPosition = subscriberPosition; _logBuffers = logBuffers; _errorHandler = errorHandler; SourceIdentity = sourceIdentity; CorrelationId = correlationId; var buffers = logBuffers.AtomicBuffers(); Array.Copy(buffers, 0, _termBuffers, 0, LogBufferDescriptor.PARTITION_COUNT); var termLength = logBuffers.TermLength(); _termLengthMask = termLength - 1; _positionBitsToShift = IntUtil.NumberOfTrailingZeros(termLength); _header = new Header(LogBufferDescriptor.InitialTermId(buffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX]), _positionBitsToShift); }
public void SetUp() { _sendBuffer = new byte[SendBufferCapacity]; _atomicSendBuffer = new UnsafeBuffer(_sendBuffer); _logMetaDataBuffer = new UnsafeBuffer(new byte[LogBufferDescriptor.LOG_META_DATA_LENGTH]); _termBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; _termMetaDataBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; _buffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT * 2 + 1]; _conductor = A.Fake <ClientConductor>(); _logBuffers = A.Fake <LogBuffers>(); _publicationLimit = A.Fake <IReadablePosition>(); A.CallTo(() => _publicationLimit.Volatile).Returns(2 * SendBufferCapacity); A.CallTo(() => _logBuffers.AtomicBuffers()).Returns(_buffers); A.CallTo(() => _logBuffers.TermLength()).Returns(LogBufferDescriptor.TERM_MIN_LENGTH); LogBufferDescriptor.InitialTermId(_logMetaDataBuffer, TermID1); LogBufferDescriptor.TimeOfLastStatusMessage(_logMetaDataBuffer, 0); for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { _termBuffers[i] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_MIN_LENGTH]); _termMetaDataBuffers[i] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_META_DATA_LENGTH]); _buffers[i] = _termBuffers[i]; _buffers[i + LogBufferDescriptor.PARTITION_COUNT] = _termMetaDataBuffers[i]; } _buffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX] = _logMetaDataBuffer; _publication = new Publication(_conductor, Channel, StreamID1, SessionID1, _publicationLimit, _logBuffers, CorrelationID); _publication.IncRef(); LogBufferDescriptor.InitialiseTailWithTermId(_termMetaDataBuffers[0], TermID1); }
public void SetUp() { _sendBuffer = new byte[SendBufferCapacity]; _atomicSendBuffer = new UnsafeBuffer(_sendBuffer); _logMetaDataBuffer = new UnsafeBuffer(new byte[LogBufferDescriptor.LOG_META_DATA_LENGTH]); _termBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; _termMetaDataBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; _buffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT*2 + 1]; _conductor = A.Fake<ClientConductor>(); _logBuffers = A.Fake<LogBuffers>(); _publicationLimit = A.Fake<IReadablePosition>(); A.CallTo(() => _publicationLimit.Volatile).Returns(2*SendBufferCapacity); A.CallTo(() => _logBuffers.AtomicBuffers()).Returns(_buffers); A.CallTo(() => _logBuffers.TermLength()).Returns(LogBufferDescriptor.TERM_MIN_LENGTH); LogBufferDescriptor.InitialTermId(_logMetaDataBuffer, TermID1); LogBufferDescriptor.TimeOfLastStatusMessage(_logMetaDataBuffer, 0); for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { _termBuffers[i] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_MIN_LENGTH]); _termMetaDataBuffers[i] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_META_DATA_LENGTH]); _buffers[i] = _termBuffers[i]; _buffers[i + LogBufferDescriptor.PARTITION_COUNT] = _termMetaDataBuffers[i]; } _buffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX] = _logMetaDataBuffer; _publication = new Publication(_conductor, Channel, StreamID1, SessionID1, _publicationLimit, _logBuffers, CorrelationID); _publication.IncRef(); LogBufferDescriptor.InitialiseTailWithTermId(_termMetaDataBuffers[0], TermID1); }