Beispiel #1
0
        internal Session(Connection connection, Begin begin)
        {
            this.connection = connection;
            this.channel = connection.AddSession(this);
            this.handleMax = begin.HandleMax;
            this.localLinks = new Link[1];
            this.remoteLinks = new Link[1];
            this.incomingList = new LinkedList();
            this.outgoingList = new LinkedList();
            this.nextOutgoingId = uint.MaxValue - 2u;
            this.outgoingWindow = begin.IncomingWindow;
            this.incomingDeliveryId = uint.MaxValue;

            begin.NextOutgoingId = this.nextOutgoingId;
            this.state = State.BeginSent;
            this.SendBegin(begin);
        }
Beispiel #2
0
        void OnTransfer(Transfer transfer, ByteBuffer buffer)
        {
            bool newDelivery;
            lock (this.ThisLock)
            {
                if (this.incomingWindow-- == 0)
                {
                    this.SendFlow(new Flow());
                }

                this.nextIncomingId++;
                newDelivery = transfer.HasDeliveryId && transfer.DeliveryId > this.incomingDeliveryId;
                if (newDelivery)
                {
                    this.incomingDeliveryId = transfer.DeliveryId;
                }
            }

            Link link = this.GetLink(transfer.Handle);
            Delivery delivery = null;
            if (newDelivery)
            {
                delivery = new Delivery()
                {
                    DeliveryId = transfer.DeliveryId,
                    Link = link,
                    Tag = transfer.DeliveryTag,
                    Settled = transfer.Settled,
                    State = transfer.State
                };

                if (!delivery.Settled)
                {
                    lock (this.ThisLock)
                    {
                        this.incomingList.Add(delivery);
                    }
                }
            }

            link.OnTransfer(delivery, transfer, buffer);
        }
Beispiel #3
0
        void OnDelivery(SequenceNumber deliveryId)
        {
            // called with lock held
            if (this.credit <= 0)
            {
                throw new AmqpException(ErrorCode.TransferLimitExceeded,
                    Fx.Format(SRAmqp.DeliveryLimitExceeded, deliveryId));
            }

            this.deliveryCount++;
            this.credit--;
        }
Beispiel #4
0
 internal override void OnAttach(uint remoteHandle, Attach attach)
 {
     base.OnAttach(remoteHandle, attach);
     this.deliveryCount = attach.InitialDeliveryCount;
 }
Beispiel #5
0
        internal void OnBegin(ushort remoteChannel, Begin begin)
        {
            lock (this.ThisLock)
            {
                if (this.state == State.BeginSent)
                {
                    this.state = State.Opened;
                }
                else if (this.state == State.EndPipe)
                {
                    this.state = State.EndSent;
                }
                else
                {
                    throw new AmqpException(ErrorCode.IllegalState,
                        Fx.Format(SRAmqp.AmqpIllegalOperationState, "OnBegin", this.state));
                }

                this.outgoingWindow = begin.IncomingWindow;
                this.nextIncomingId = begin.NextOutgoingId;
            }

            if (begin.HandleMax < this.handleMax)
            {
                this.handleMax = begin.HandleMax;
            }

            if (this.onBegin != null)
            {
                this.onBegin(this, begin);
            }
        }
Beispiel #6
0
        public int CompareTo(SequenceNumber value)
        {
            int delta = this.sequenceNumber - value.sequenceNumber;
            if (delta == int.MinValue)
            {
                // Behavior of comparing 0u-2147483648u, 1u-2147483649u, ...
                // is undefined, so we do not allow it.
                throw new AmqpException(ErrorCode.NotAllowed,
                    Fx.Format(SRAmqp.InvalidSequenceNumberComparison, (uint)this.sequenceNumber, (uint)value.sequenceNumber));
            }

            return delta;
        }
Beispiel #7
0
 internal override void OnAttach(uint remoteHandle, Attach attach)
 {
     base.OnAttach(remoteHandle, attach);
     this.deliveryCount = attach.InitialDeliveryCount;
 }