Пример #1
0
        private void OnReceiveSessionFrame(Frame frame)
        {
            AmqpSession  nullable = null;
            Performative command  = frame.Command;
            ushort       channel  = frame.Channel;

            if (command.DescriptorCode != Begin.Code)
            {
                if (!this.sessionsByRemoteHandle.TryGetObject(channel, out nullable))
                {
                    if (command.DescriptorCode != End.Code && command.DescriptorCode != Detach.Code && !base.Settings.IgnoreMissingSessions)
                    {
                        throw new AmqpException(AmqpError.NotFound, SRAmqp.AmqpChannelNotFound(channel, this));
                    }
                    return;
                }
                if (command.DescriptorCode == End.Code)
                {
                    this.sessionsByRemoteHandle.Remove(channel);
                    nullable.RemoteChannel = null;
                }
            }
            else
            {
                Begin begin = (Begin)command;
                if (!begin.RemoteChannel.HasValue)
                {
                    AmqpSessionSettings amqpSessionSetting = AmqpSessionSettings.Create(begin);
                    amqpSessionSetting.RemoteChannel = new ushort?(channel);
                    nullable = this.SessionFactory.CreateSession(this, amqpSessionSetting);
                    this.AddSession(nullable, new ushort?(channel));
                }
                else
                {
                    lock (base.ThisLock)
                    {
                        if (!this.sessionsByLocalHandle.TryGetObject(begin.RemoteChannel.Value, out nullable))
                        {
                            Error  notFound      = AmqpError.NotFound;
                            ushort?remoteChannel = begin.RemoteChannel;
                            throw new AmqpException(notFound, SRAmqp.AmqpChannelNotFound(remoteChannel.Value, this));
                        }
                        nullable.RemoteChannel = new ushort?(channel);
                        this.sessionsByRemoteHandle.Add(channel, nullable);
                    }
                }
            }
            nullable.ProcessFrame(frame);
        }
Пример #2
0
        void OnReceiveSessionFrame(Frame frame)
        {
            AmqpSession  session = null;
            Performative command = frame.Command;
            ushort       channel = frame.Channel;

            if (command.DescriptorCode == Begin.Code)
            {
                Begin begin = (Begin)command;
                if (begin.RemoteChannel.HasValue)
                {
                    // reply to begin
                    lock (this.ThisLock)
                    {
                        if (!this.sessionsByLocalHandle.TryGetObject(begin.RemoteChannel.Value, out session))
                        {
                            throw new AmqpException(AmqpError.NotFound, SRClient.AmqpChannelNotFound(begin.RemoteChannel.Value));
                        }

                        session.RemoteChannel = channel;
                        this.sessionsByRemoteHandle.Add(channel, session);
                    }
                }
                else
                {
                    // new begin request
                    AmqpSessionSettings settings = AmqpSessionSettings.Create(begin);
                    settings.RemoteChannel = channel;
                    session = this.SessionFactory.CreateSession(this, settings);
                    this.AddSession(session, channel);
                }
            }
            else
            {
                if (!this.sessionsByRemoteHandle.TryGetObject((uint)channel, out session))
                {
                    if (frame.Command.DescriptorCode == End.Code ||
                        frame.Command.DescriptorCode == Detach.Code)
                    {
                        return;
                    }

                    throw new AmqpException(AmqpError.NotFound, SRClient.AmqpChannelNotFound((uint)channel));
                }
            }

            session.ProcessFrame(frame);
        }