Наследование: IAmqpSerializable
Пример #1
0
        public ProtocolHeader ExtractProtocolHeader(ByteBuffer buffer)
        {
            if (buffer.Length < AmqpConstants.ProtocolHeaderSize)
            {
                return null;
            }

            ProtocolHeader header = new ProtocolHeader();
            header.Decode(buffer);

            return header;
        }
Пример #2
0
        public override bool Equals(object obj)
        {
            ProtocolHeader otherHeader = obj as ProtocolHeader;

            if (otherHeader == null)
            {
                return(false);
            }

            return(otherHeader.protocolId == this.protocolId &&
                   otherHeader.version.Equals(this.version));
        }
Пример #3
0
        public AmqpConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) :
            base((isInitiator ? "out" : "in") + "-connection", transport, connectionSettings, isInitiator)
        {
            if (amqpSettings == null)
            {
                throw new ArgumentNullException("amqpSettings");
            }

            this.initialHeader = protocolHeader;
            this.isInitiator = isInitiator;
            this.amqpSettings = amqpSettings;
            this.sessionsByLocalHandle = new HandleTable<AmqpSession>(this.Settings.ChannelMax ?? AmqpConstants.DefaultMaxConcurrentChannels - 1);
            this.sessionsByRemoteHandle = new HandleTable<AmqpSession>(this.Settings.ChannelMax ?? AmqpConstants.DefaultMaxConcurrentChannels - 1);
            this.SessionFactory = this;
            this.heartBeat = HeartBeat.None;
        }
Пример #4
0
 public AmqpConnection CreateConnection(TransportBase transport, ProtocolHeader protocolHeader, 
     bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings)
 {
     return new AmqpConnection(transport, protocolHeader, false, amqpSettings, connectionSettings);
 }
Пример #5
0
        void SendProtocolHeader(ProtocolHeader header)
        {
#if DEBUG
            header.Trace(true);
            AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Send, header);
#endif
            this.TransitState("S:HDR", StateTransition.SendHeader);
            this.SendDatablock(header);
        }
Пример #6
0
 public AmqpConnection(TransportBase transport, ProtocolHeader protocolHeader, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) :
     this(transport, protocolHeader, true, amqpSettings, connectionSettings)
 {
 }
Пример #7
0
        protected override void OnProtocolHeader(ProtocolHeader header)
        {
#if DEBUG
            header.Trace(false);
            AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Receive, header);
#endif
            this.heartBeat.OnReceive();
            if (this.UsageMeter != null)
            {
                this.UsageMeter.OnRead(this, 0, header.EncodeSize);
            }

            this.TransitState("R:HDR", StateTransition.ReceiveHeader);
            Exception exception = null;

            if (this.isInitiator)
            {
                if (!this.initialHeader.Equals(header))
                {
                    exception = new AmqpException(AmqpErrorCode.NotImplemented, AmqpResources.GetString(AmqpResources.AmqpProtocolVersionNotSupported, this.initialHeader.ToString(), header.ToString()));
                }
            }
            else
            {
                ProtocolHeader supportedHeader = this.amqpSettings.GetSupportedHeader(header);                
                this.SendProtocolHeader(supportedHeader);
                if (!supportedHeader.Equals(header))
                {
                    exception = new AmqpException(AmqpErrorCode.NotImplemented, AmqpResources.GetString(AmqpResources.AmqpProtocolVersionNotSupported, this.initialHeader.ToString(), header.ToString()));
                }
            }

            if (exception != null)
            {
                this.CompleteOpen(false, exception);
            }
        }
Пример #8
0
        void OnReadHeaderComplete(TransportAsyncCallbackArgs args)
        {
            if (args.Exception != null)
            {
                AmqpTrace.Provider.AmqpLogError(this, "ReadHeader", args.Exception.Message);
                this.Complete(args);
                return;
            }

            try
            {
                ProtocolHeader receivedHeader = new ProtocolHeader();
                receivedHeader.Decode(new ByteBuffer(args.Buffer, args.Offset, args.Count));
#if DEBUG
                receivedHeader.Trace(false);
                AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Receive, receivedHeader);
#endif

                if (!receivedHeader.Equals(this.sentHeader))
                {
                    // TODO: need to reconnect with the reply version if supported
                    throw new AmqpException(AmqpErrorCode.NotImplemented, AmqpResources.GetString(AmqpResources.AmqpProtocolVersionNotSupported, this.sentHeader, receivedHeader));
                }

                // upgrade transport
                TransportBase secureTransport = this.settings.TransportProviders[this.providerIndex].CreateTransport(args.Transport, true);
                AmqpTrace.Provider.AmqpUpgradeTransport(this, args.Transport, secureTransport);
                args.Transport = secureTransport;
                IAsyncResult result = args.Transport.BeginOpen(this.timeoutHelper.RemainingTime(), this.OnTransportOpenCompete, args);
                if (result.CompletedSynchronously)
                {
                    this.HandleTransportOpened(result);
                }
            }
            catch (Exception exp)
            {
                if (Fx.IsFatal(exp))
                {
                    throw;
                }

                AmqpTrace.Provider.AmqpLogError(this, "OnProtocolHeader", exp.Message);
                args.Exception = exp;
                this.Complete(args);
            }
        }
Пример #9
0
        void WriteSecurityHeader(TransportAsyncCallbackArgs args)
        {
            // secure transport: header negotiation
            TransportProvider provider = this.settings.TransportProviders[this.providerIndex];
            this.sentHeader = new ProtocolHeader(provider.ProtocolId, provider.DefaultVersion);
#if DEBUG
            this.sentHeader.Trace(true);
            AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Send, this.sentHeader);
#endif

            ByteBuffer buffer = new ByteBuffer(new byte[AmqpConstants.ProtocolHeaderSize]);
            this.sentHeader.Encode(buffer);

            args.SetBuffer(buffer.Buffer, buffer.Offset, buffer.Length);
            args.CompletedCallback = this.OnWriteHeaderComplete;
            this.writer.WriteBuffer(args);
        }
Пример #10
0
        void OnReceiveFrameBuffer(ByteBuffer buffer)
        {
            if (this.State <= AmqpObjectState.OpenClosePipe)
            {
                Fx.Assert(buffer.Length == AmqpConstants.ProtocolHeaderSize, "protocol header size is wrong");
                try
                {
                    ProtocolHeader header = new ProtocolHeader();
                    header.Decode(buffer);
                    this.OnProtocolHeader(header);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }

                    AmqpTrace.Provider.AmqpLogError(this, "OnProtocolHeader", exception.Message);

                    this.TerminalException = exception;
                    this.Abort();
                }
            }
            else
            {
                try
                {
                    this.OnFrameBuffer(buffer);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }

                    AmqpTrace.Provider.AmqpLogError(this, "OnFrame", exception.Message);

                    this.SafeClose(exception);
                }
            }
        }
Пример #11
0
 protected abstract void OnProtocolHeader(ProtocolHeader header);