Beispiel #1
0
        public Transfer GetTransfer(uint maxFrameSize, uint linkHandle, out bool more)
        {
            more = false;
            Transfer transfer = new Transfer();
            transfer.Handle = linkHandle;
            transfer.More = false;
            if (this.BytesTransfered == 0)
            {
                transfer.DeliveryId = this.DeliveryId.Value;
                transfer.DeliveryTag = this.DeliveryTag;
                transfer.MessageFormat = AmqpConstants.AmqpMessageFormat;
                transfer.Batchable = this.Batchable;
                if (this.settled)
                {
                    transfer.Settled = true;
                }

                if (this.TxnId.Array != null)
                {
                    transfer.State = new TransactionalState() { TxnId = this.TxnId };
                }
            }

            maxFrameSize = maxFrameSize == uint.MaxValue ? AmqpConstants.DefaultMaxFrameSize : maxFrameSize;
            int overhead = Frame.HeaderSize + transfer.EncodeSize;
            if (overhead > maxFrameSize)
            {
                throw new AmqpException(AmqpError.FrameSizeTooSmall);
            }

            int payloadSize = (int)maxFrameSize - overhead;
            ArraySegment<byte>[] payload = this.GetPayload(payloadSize, out more);
            if (this.BytesTransfered > 0 && payload == null)
            {
                throw new AmqpException(AmqpError.IllegalState, "GetPayload");
            }

            transfer.More = more;
            transfer.PayloadList = payload;

            payloadSize = transfer.PayloadSize;
            this.BytesTransfered += (ulong)payloadSize;
            this.OnCompletePayload(payloadSize);

            return transfer;
        }
Beispiel #2
0
 protected override void OnProcessTransfer(Delivery delivery, Transfer transfer)
 {
     Fx.Assert(delivery == null || object.ReferenceEquals(delivery, this.currentDelivery), "The delivery must be null or must be the same as the current message.");
     this.currentDelivery.AddPayload(transfer.Payload);
     if (!transfer.More())
     {
         Utils.Trace(TraceLevel.Debug, "{0}: Complete a message with payload from {1} transfers.", this, this.currentDelivery.Count);
         AmqpMessage message = this.currentDelivery.GetMessage();
         this.currentDelivery = null;
         this.OnReceiveMessage(message);
     }
 }
Beispiel #3
0
 protected override void OnProcessTransfer(Delivery delivery, Transfer transfer)
 {
     throw new AmqpException(AmqpError.NotAllowed);
 }
Beispiel #4
0
 protected void OnReceiveFirstTransfer(Transfer transfer)
 {
     Fx.Assert(transfer.DeliveryId.HasValue, "The first transfer must have a delivery id.");
     this.nextDeliveryId = transfer.DeliveryId.Value;
     this.unsettledLwm = this.nextDeliveryId;
 }
Beispiel #5
0
            public void OnReceiveTransfer(AmqpLink link, Transfer transfer)
            {
                if (!transferEverReceived)
                {
                    this.OnReceiveFirstTransfer(transfer);
                    this.transferEverReceived = true;
                }

                lock (this.SyncRoot)
                {
                    if (this.incomingWindow == 0)
                    {
                        Utils.Trace(TraceLevel.Verbose, "{0}: Window closed", this);
                        throw new AmqpException(AmqpError.WindowViolation);
                    }

                    this.nextIncomingId.Increment();
                    --this.incomingWindow;
                }

                this.pendingTransfers.DoWork(new Tuple<AmqpLink, Transfer>(link, transfer));
            }
Beispiel #6
0
 protected abstract void OnProcessTransfer(Delivery delivery, Transfer transfer);
Beispiel #7
0
        public void ProcessTransfer(Delivery delivery, Transfer transfer)
        {
            Utils.Trace(TraceLevel.Verbose, "{0}: Receive a transfer(id:{1}, settled:{2}).", this, transfer.DeliveryId, transfer.Settled());
            if (delivery != null)
            {
                // handle new delivery
                bool creditAvailable = true;
                lock (this.syncRoot)
                {
                    creditAvailable = this.TryChargeCredit();
                }

                if (!creditAvailable)
                {
                    Utils.Trace(TraceLevel.Verbose, "{0}: The transfer {1} was rejected due to insufficient link credit.", this, transfer.DeliveryId.Value);
                    this.TryClose(new AmqpException(AmqpError.TransferLimitExceeded));
                }
                else
                {
                    delivery.Link = this;
                    delivery.DeliveryId = transfer.DeliveryId.Value;
                    delivery.DeliveryTag = transfer.DeliveryTag;
                    delivery.Settled = transfer.Settled();
                    delivery.Batchable = transfer.Batchable();
                    TransactionalState txnState = transfer.State as TransactionalState;
                    if (txnState != null)
                    {
                        delivery.TxnId = txnState.TxnId;
                    }

                    if (!delivery.Settled)
                    {
                        lock (this.syncRoot)
                        {
                            this.unsettledMap.Add(delivery.DeliveryTag, delivery);
                        }
                    }
                }
            }
            else
            {
                this.Session.OnAcceptIncomingTransfer();
            }

            this.OnProcessTransfer(delivery, transfer);
        }