Exemple #1
0
        /// <summary>
        /// Poll for new messages in a stream. If new messages are found beyond the last consumed position then they
        /// will be delivered to the <seealso cref="FragmentHandler"/> up to a limited number of fragments as specified.
        ///
        /// Use a <see cref="FragmentAssembler"/> to assemble messages which span multiple fragments.
        /// </summary>
        /// <param name="fragmentHandler"> to which message fragments are delivered. </param>
        /// <param name="fragmentLimit">   for the number of fragments to be consumed during one polling operation. </param>
        /// <returns> the number of fragments that have been consumed. </returns>
        /// <seealso cref="FragmentAssembler" />
        /// <seealso cref="ImageFragmentAssembler" />
        public int Poll(IFragmentHandler fragmentHandler, int fragmentLimit)
        {
            if (_isClosed)
            {
                return(0);
            }

            var position = _subscriberPosition.Get();

            return(TermReader.Read(
                       ActiveTermBuffer(position),
                       (int)position & _termLengthMask,
                       fragmentHandler,
                       fragmentLimit,
                       _header,
                       _errorHandler,
                       position,
                       _subscriberPosition));
        }
Exemple #2
0
        public long Position()
        {
            if (_isClosed)
            {
                return(_finalPosition);
            }

            return(_subscriberPosition.Get());
        }
Exemple #3
0
        public void ShouldPollNoFragmentsToBoundedControlledFragmentHandlerWithMaxPositionBeforeInitialPosition()
        {
            var initialPosition = LogBufferDescriptor.ComputePosition(INITIAL_TERM_ID, 0, POSITION_BITS_TO_SHIFT, INITIAL_TERM_ID);
            var maxPosition     = initialPosition - DataHeaderFlyweight.HEADER_LENGTH;

            Position.SetOrdered(initialPosition);
            var image = CreateImage();

            InsertDataFrame(INITIAL_TERM_ID, OffsetForFrame(0));
            InsertDataFrame(INITIAL_TERM_ID, OffsetForFrame(1));

            A.CallTo(() => MockControlledFragmentHandler.OnFragment(A <UnsafeBuffer> ._, A <int> ._, A <int> ._, A <Header> ._)).Returns(ControlledFragmentHandlerAction.CONTINUE);

            var fragmentsRead = image.BoundedControlledPoll(MockControlledFragmentHandler, maxPosition, int.MaxValue);

            Assert.That(fragmentsRead, Is.EqualTo(0));
            Assert.That(Position.Get(), Is.EqualTo(initialPosition));

            A.CallTo(() => MockControlledFragmentHandler.OnFragment(A <UnsafeBuffer> ._, DataHeaderFlyweight.HEADER_LENGTH, DATA.Length, A <Header> ._)).MustNotHaveHappened();
        }
Exemple #4
0
        /// <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;
            _joiningPosition    = subscriberPosition.Get();

            _termBuffers = logBuffers.TermBuffers();

            var termLength = logBuffers.TermLength();

            _termLengthMask      = termLength - 1;
            _positionBitsToShift = IntUtil.NumberOfTrailingZeros(termLength);
            _initialTermId       = LogBufferDescriptor.InitialTermId(logBuffers.MetaDataBuffer());
            _header = new Header(LogBufferDescriptor.InitialTermId(logBuffers.MetaDataBuffer()), _positionBitsToShift, this);
        }
 //这个里面是通用方法,实现增删改查排序(动软代码生成器自动生成)
 #region  Method
 /// <summary>
 /// 获取用户信息
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Position Get(int id)
 {
     return(dao.Get(id));
 }