예제 #1
0
    public ChallengeEncoder PutEncodedChallenge(IDirectBuffer src, int srcOffset, int length)
    {
        if (length > 1073741824)
        {
            throw new InvalidOperationException("length > maxValue for type: " + length);
        }

        int headerLength = 4;
        int limit = _parentMessage.Limit();
        _parentMessage.Limit(limit + headerLength + length);
        _buffer.PutInt(limit, unchecked((int)length), ByteOrder.LittleEndian);
        _buffer.PutBytes(limit + headerLength, src, srcOffset, length);

        return this;
    }
예제 #2
0
        /// <summary>
        /// Receive one message from the broadcast buffer.
        /// </summary>
        /// <param name="handler"> to be called for each message received. </param>
        /// <returns> the number of messages that have been received. </returns>
        public virtual int Receive(MessageHandler handler)
        {
            var messagesReceived    = 0;
            var receiver            = _receiver;
            var lastSeenLappedCount = receiver.LappedCount();

            if (receiver.ReceiveNext())
            {
                if (lastSeenLappedCount != receiver.LappedCount())
                {
                    throw new InvalidOperationException("Unable to keep up with broadcast buffer");
                }

                var length   = receiver.Length();
                var capacity = _scratchBuffer.Capacity;
                if (length > capacity)
                {
                    throw new InvalidOperationException($"Buffer required size {length:D} but only has {capacity:D}");
                }

                var msgTypeId = receiver.TypeId();
                _scratchBuffer.PutBytes(0, receiver.Buffer(), receiver.Offset(), length);

                if (!receiver.Validate())
                {
                    throw new InvalidOperationException("Unable to keep up with broadcast buffer");
                }

                handler(msgTypeId, _scratchBuffer, 0, length);

                messagesReceived = 1;
            }

            return(messagesReceived);
        }
        public TaggedReplicateRequestEncoder PutSrcControlChannel(IDirectBuffer src, int srcOffset, int length)
        {
            if (length > 1073741824)
            {
                throw new InvalidOperationException("length > maxValue for type: " + length);
            }

            int headerLength = 4;
            int limit        = _parentMessage.Limit();

            _parentMessage.Limit(limit + headerLength + length);
            _buffer.PutInt(limit, unchecked ((int)length), ByteOrder.LittleEndian);
            _buffer.PutBytes(limit + headerLength, src, srcOffset, length);

            return(this);
        }
예제 #4
0
        private static void Publish <T>(T message,
                                        Publication publication,
                                        IIdleStrategy offerIdleStrategy,
                                        IMutableDirectBuffer buffer)
        {
            var serTm  = Util.Serialize(message);
            var length = serTm.Length;

            buffer.PutBytes(0, serTm);

            offerIdleStrategy.Reset();
            while (!Offer(publication, buffer, length))
            {
                // The offer failed, which is usually due to the publication
                // being temporarily blocked.  Retry the offer after a short
                // spin/yield/sleep, depending on the chosen IdleStrategy.
                //backPressureCount++;
                offerIdleStrategy.Idle();
            }

            //reporter.OnMessage(1, length);
        }
예제 #5
0
 public void GetBytes(int index, IMutableDirectBuffer dstBuffer, int dstIndex, int length)
 {
     dstBuffer.PutBytes(dstIndex, this, index, length);
 }
예제 #6
0
 public void GetBytes(int index, IMutableDirectBuffer dstBuffer, int dstIndex, int length)
 {
     dstBuffer.PutBytes(dstIndex, this, index, length);
 }