Inheritance: DescribedList
Example #1
0
        internal static ByteBuffer EncodeCommand(FrameType type, ushort channel, Performative command, int payloadSize)
        {
            int frameSize = HeaderSize;

            if (command != null)
            {
                frameSize += AmqpCodec.GetSerializableEncodeSize(command);
            }

            frameSize += payloadSize;

            ByteBuffer buffer = new ByteBuffer(frameSize, false, false);

            AmqpBitConverter.WriteUInt(buffer, (uint)frameSize);
            AmqpBitConverter.WriteUByte(buffer, DefaultDataOffset);
            AmqpBitConverter.WriteUByte(buffer, (byte)type);
            AmqpBitConverter.WriteUShort(buffer, channel);

            if (command != null)
            {
                AmqpCodec.EncodeSerializable(command, buffer);
            }

            return(buffer);
        }
Example #2
0
            public static void Log(object source, bool send, Performative command)
            {
                AmqpDebugImpl instance = AmqpDebugImpl.GetInstance(source);
                ulong code = command.DescriptorCode;
                uint p1 = 0;
                uint p2 = 0;
                if (code == Transfer.Code)
                {
                    Transfer transfer = (Transfer)command;
                    p1 = transfer.DeliveryId ?? 0;
                    p2 = transfer.Settled() ? 1u : 0u;
                }
                else if (code == Disposition.Code)
                {
                    Disposition disp = (Disposition)command;
                    p1 = disp.First ?? 0;
                    p2 = disp.Last ?? p1;
                }
                else if (code == Flow.Code)
                {
                    Flow flow = (Flow)command;
                    p1 = flow.IncomingWindow ?? 0;
                    p2 = flow.NextIncomingId ?? 0;
                    if (flow.Handle.HasValue)
                    {
                        instance.LogInternal(send, code, flow.DeliveryCount.Value, flow.LinkCredit.Value);
                    }
                }

                instance.LogInternal(send, code, p1, p2);
            }
Example #3
0
        public void WriteFrame(Performative command, bool needReply)
        {
            try
            {
#if DEBUG
                Frame frame = new Frame(FrameType.Sasl) { Command = command };
                frame.Trace(true);
                AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Send, frame);
#endif

                ByteBuffer buffer = Frame.EncodeCommand(FrameType.Sasl, 0, command, 0);
                TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
                args.SetBuffer(buffer);
                args.CompletedCallback = onWriteFrameComplete;
                args.UserToken = this;
                args.UserToken2 = needReply;
                this.writer.WriteBuffer(args);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                this.HandleException("WriteFrame", exception);
            }
        }
Example #4
0
        public static ByteBuffer EncodeCommand(FrameType type, ushort channel, Performative command, int payloadSize)
        {
            int frameSize = HeaderSize;
            if (command != null)
            {
                frameSize += AmqpCodec.GetSerializableEncodeSize(command);
            }

            frameSize += payloadSize;

            ByteBuffer buffer = new ByteBuffer(frameSize, false, false);
            AmqpBitConverter.WriteUInt(buffer, (uint)frameSize);
            AmqpBitConverter.WriteUByte(buffer, DefaultDataOffset);
            AmqpBitConverter.WriteUByte(buffer, (byte)type);
            AmqpBitConverter.WriteUShort(buffer, channel);

            if (command != null)
            {
                AmqpCodec.EncodeSerializable(command, buffer);
            }

            return buffer;
        }
Example #5
0
 public void SendCommand(Performative command, ArraySegment<byte>[] payload)
 {
     AmqpDebug.Log(this, true, command);
     this.connection.SendCommand(command, this.LocalChannel, payload);
 }
Example #6
0
 public void SendCommand(Performative command)
 {
     this.SendCommand(command, null);
 }
Example #7
0
        public void SendCommand(Performative command, ushort channel, ArraySegment<byte>[] payload)
        {
#if DEBUG
            Frame frame = new Frame();
            frame.Channel = channel;
            frame.Command = command;
            frame.Trace(true, this, channel, command, -1);
            AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Send, frame);
#endif

            int frameSize = 0;
            if (payload == null)
            {
                // The frame buffer is disposed when the write completes
                ByteBuffer buffer = Frame.EncodeCommand(FrameType.Amqp, channel, command, 0);
                frameSize = buffer.Length;
                this.SendBuffer(buffer);
            }
            else
            {
                ByteBuffer[] buffers = new ByteBuffer[1 + payload.Length];
                int payloadSize = 0;
                for (int i = 0; i < payload.Length; ++i)
                {
                    ArraySegment<byte> segment = payload[i];
                    payloadSize += segment.Count;
                    buffers[i + 1] = new ByteBuffer(segment);
                }

                // The frame buffer is disposed when the write completes
                ByteBuffer cmdBuffer = Frame.EncodeCommand(FrameType.Amqp, channel, command, payloadSize);
                frameSize = cmdBuffer.Length + payloadSize;
                buffers[0] = cmdBuffer;
                this.SendBuffers(buffers);
            }

            this.heartBeat.OnSend();
            if (this.UsageMeter != null)
            {
                this.UsageMeter.OnWrite(this, command == null ? 0 : command.DescriptorCode, frameSize);
            }
        }
Example #8
0
        public static void Log(object source, bool send, Performative command)
        {
#if AMQP_DEBUG
            AmqpDebugImpl.Log(source, send, command);
#endif
        }
Example #9
0
 public OpenEventArgs(Performative command)
 {
     this.command = command;
 }
Example #10
0
 void HandleSaslCommand(Performative command)
 {
     if (command.DescriptorCode == SaslMechanisms.Code)
     {
         this.OnSaslServerMechanisms((SaslMechanisms)command);
     }
     else if (command.DescriptorCode == SaslInit.Code)
     {
         this.OnSaslInit((SaslInit)command);
     }
     else if (command.DescriptorCode == SaslChallenge.Code)
     {
         this.saslHandler.OnChallenge((SaslChallenge)command);
     }
     else if (command.DescriptorCode == SaslResponse.Code)
     {
         this.saslHandler.OnResponse((SaslResponse)command);
     }
     else if (command.DescriptorCode == SaslOutcome.Code)
     {
         this.OnSaslOutcome((SaslOutcome)command);
     }
     else
     {
         throw new AmqpException(AmqpErrorCode.NotAllowed, command.ToString());
     }
 }