Esempio n. 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="IBlockHandler"/> up to a limited number of bytes.
        /// </summary>
        /// <param name="blockHandler">     to which block is delivered. </param>
        /// <param name="blockLengthLimit"> up to which a block may be in length. </param>
        /// <returns> the number of bytes that have been consumed. </returns>
        public int BlockPoll(IBlockHandler blockHandler, int blockLengthLimit)
        {
            if (_isClosed)
            {
                return(0);
            }

            var position   = _subscriberPosition.Get();
            var termOffset = (int)position & _termLengthMask;
            var termBuffer = ActiveTermBuffer(position);
            var limit      = Math.Min(termOffset + blockLengthLimit, termBuffer.Capacity);

            var resultingOffset = TermBlockScanner.Scan(termBuffer, termOffset, limit);

            var bytesConsumed = resultingOffset - termOffset;

            if (resultingOffset > termOffset)
            {
                try
                {
                    var termId = termBuffer.GetInt(termOffset + DataHeaderFlyweight.TERM_ID_FIELD_OFFSET);

                    blockHandler.OnBlock(termBuffer, termOffset, bytesConsumed, SessionId, termId);
                }
                catch (Exception t)
                {
                    _errorHandler(t);
                }

                _subscriberPosition.SetOrdered(position + bytesConsumed);
            }

            return(bytesConsumed);
        }
Esempio n. 2
0
        /// <summary>
        /// Poll the <seealso cref="Image"/>s under the subscription for available message fragments in blocks.
        /// <para>
        /// This method is useful for operations like bulk archiving and messaging indexing.
        ///
        /// </para>
        /// </summary>
        /// <param name="blockHandler">     to receive a block of fragments from each <seealso cref="Image"/>. </param>
        /// <param name="blockLengthLimit"> for each <seealso cref="Image"/> polled. </param>
        /// <returns> the number of bytes consumed. </returns>
        public long BlockPoll(IBlockHandler blockHandler, int blockLengthLimit)
        {
            long bytesConsumed = 0;

            foreach (var image in _images)
            {
                bytesConsumed += image.BlockPoll(blockHandler, blockLengthLimit);
            }

            return(bytesConsumed);
        }
 public BlockProcessor(
     IBlockProxy blockProxy,
     IBlockHandler blockHandler,
     ITransactionProcessor transactionProcessor,
     IEnumerable <IBlockFilter> blockFilters = null
     )
 {
     BlockProxy           = blockProxy;
     _blockHandler        = blockHandler;
     TransactionProcessor = transactionProcessor;
     _blockFilters        = blockFilters ?? new IBlockFilter[0];
 }
Esempio n. 4
0
 public BlockProcessor(
     IWeb3 web3,
     IBlockHandler blockHandler,
     ITransactionProcessor transactionProcessor,
     IEnumerable <IBlockFilter> blockFilters = null
     )
 {
     BlockProxy           = web3.Eth;
     BlockHandler         = blockHandler;
     TransactionProcessor = transactionProcessor;
     BlockFilters         = blockFilters ?? new IBlockFilter[0];
 }
 public BlockPostProcessor(IBlockProxy blockProxy, IBlockHandler blockHandler, ITransactionProcessor transactionProcessor) : base(blockProxy, blockHandler, transactionProcessor)
 {
 }
 public BlockVmPostProcessor(IWeb3 web3, IBlockHandler blockHandler, ITransactionProcessor transactionProcessor) : base(web3, blockHandler, transactionProcessor)
 {
 }
Esempio n. 7
0
 public void Register(IBlockHandler handler)
 {
     _handlers[handler.Identifier] = handler;
 }
Esempio n. 8
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="IBlockHandler"/> up to a limited number of bytes.
        /// </summary>
        /// <param name="blockHandler">     to which block is delivered. </param>
        /// <param name="blockLengthLimit"> up to which a block may be in length. </param>
        /// <returns> the number of bytes that have been consumed. </returns>
        public int BlockPoll(IBlockHandler blockHandler, int blockLengthLimit)
        {
            if (_isClosed)
            {
                return 0;
            }

            var position = _subscriberPosition.Get();
            var termOffset = (int) position & _termLengthMask;
            var termBuffer = ActiveTermBuffer(position);
            var limit = Math.Min(termOffset + blockLengthLimit, termBuffer.Capacity);

            var resultingOffset = TermBlockScanner.Scan(termBuffer, termOffset, limit);

            var bytesConsumed = resultingOffset - termOffset;
            if (resultingOffset > termOffset)
            {
                try
                {
                    var termId = termBuffer.GetInt(termOffset + DataHeaderFlyweight.TERM_ID_FIELD_OFFSET);

                    blockHandler.OnBlock(termBuffer, termOffset, bytesConsumed, SessionId, termId);
                }
                catch (Exception t)
                {
                    _errorHandler(t);
                }

                _subscriberPosition.SetOrdered(position + bytesConsumed);
            }

            return bytesConsumed;
        }
Esempio n. 9
0
        /// <summary>
        /// Poll the <seealso cref="Image"/>s under the subscription for available message fragments in blocks.
        /// <para>
        /// This method is useful for operations like bulk archiving and messaging indexing.
        /// 
        /// </para>
        /// </summary>
        /// <param name="blockHandler">     to receive a block of fragments from each <seealso cref="Image"/>. </param>
        /// <param name="blockLengthLimit"> for each <seealso cref="Image"/> polled. </param>
        /// <returns> the number of bytes consumed. </returns>
        public long BlockPoll(IBlockHandler blockHandler, int blockLengthLimit)
        {
            long bytesConsumed = 0;
            foreach (var image in _images)
            {
                bytesConsumed += image.BlockPoll(blockHandler, blockLengthLimit);
            }

            return bytesConsumed;
        }