예제 #1
0
        protected void EncodeAndSend(AmqpFrame frame, ushort channelNumber = 0)
        {
            var buffer = new ByteBuffer(512, true);

            AmqpCodec.EncodeFrame(buffer, frame, channelNumber);
            connection.HandleFrame(buffer);
        }
예제 #2
0
 public void SendFrame(AmqpFrame frame)
 {
     if (!State.CanSendFrames())
     {
         throw new AmqpException(ErrorCode.IllegalState, $"Cannot send frame when session state is {State.ToString()}.");
     }
     Connection.SendFrame(frame, ChannelNumber);
 }
예제 #3
0
 internal void HandleSessionFrame(AmqpFrame frame, ByteBuffer buffer = null)
 {
     lock (stateSyncRoot)
     {
         try
         {
             if (frame is Begin)
             {
                 HandleBeginFrame(frame as Begin);
             }
             else if (frame is Attach)
             {
                 InterceptAttachFrame(frame as Attach);
             }
             else if (frame is Flow)
             {
                 InterceptFlowFrame(frame as Flow);
             }
             else if (frame is Transfer)
             {
                 InterceptTransferFrame(frame as Transfer, buffer);
             }
             else if (frame is Disposition)
             {
                 InterceptDispositionFrame(frame as Disposition);
             }
             else if (frame is Detach)
             {
                 InterceptDetachFrame(frame as Detach);
             }
             else if (frame is End)
             {
                 HandleEndFrame(frame as End);
             }
             else
             {
                 throw new AmqpException(ErrorCode.IllegalState, $"Received frame {frame.Descriptor.ToString()} but session state is {State.ToString()}.");
             }
         }
         catch (AmqpException amqpException)
         {
             trace.Error(amqpException);
             EndSession(amqpException.Error);
         }
         catch (Exception fatalException)
         {
             trace.Fatal(fatalException, "Ending Session due to fatal exception.");
             var error = new Error()
             {
                 Condition   = ErrorCode.InternalError,
                 Description = "Ending Session due to fatal exception: " + fatalException.Message,
             };
             EndSession(error);
         }
     }
 }
예제 #4
0
        private void HandleSessionFrame(AmqpFrame frame, ushort remoteChannel, ByteBuffer buffer = null)
        {
            if (State != ConnectionStateEnum.OPENED)
            {
                throw new AmqpException(ErrorCode.IllegalState, $"Received Begin Frame but current state is {State.ToString()}.");
            }

            var session = GetSessionFromRemoteChannel(remoteChannel, true);

            session.HandleSessionFrame(frame, buffer);
        }
예제 #5
0
        internal void SendFrame(AmqpFrame frame, ushort channelNumber)
        {
            // TODO: get pinned send buffer from socket to prevent an unneccessary array copy
            var buffer = new ByteBuffer((int)MaxFrameSize, false);

            AmqpCodec.EncodeFrame(buffer, frame, channelNumber);
            if (Trace.IsDebugEnabled)
            {
                trace.Debug("SEND CH({0}) {1}", channelNumber.ToString(), frame.ToString());
            }
            socket.Write(buffer);
        }
예제 #6
0
 public void HandleLinkFrame(AmqpFrame frame, ByteBuffer buffer = null)
 {
     lock (stateSyncRoot)
     {
         try
         {
             if (frame is Attach)
             {
                 HandleAttachFrame(frame as Attach);
             }
             else if (frame is Flow)
             {
                 HandleFlowFrame(frame as Flow);
             }
             else if (frame is Transfer)
             {
                 HandleTransferFrame(frame as Transfer, buffer);
             }
             else if (frame is Detach)
             {
                 HandleDetachFrame(frame as Detach);
             }
             else
             {
                 throw new AmqpException(ErrorCode.IllegalState, $"Received frame {frame.Descriptor.ToString()} but link state is {State.ToString()}.");
             }
         }
         catch (AmqpException amqpException)
         {
             trace.Error(amqpException);
             DetachLink(amqpException.Error, destoryLink: true);
         }
         catch (Exception fatalException)
         {
             trace.Fatal(fatalException, "Ending Session due to fatal exception.");
             var error = new Error()
             {
                 Condition   = ErrorCode.InternalError,
                 Description = "Ending Session due to fatal exception: " + fatalException.Message,
             };
             DetachLink(error, destoryLink: true);
         }
     }
 }
예제 #7
0
        public static void EncodeFrame(ByteBuffer buffer, AmqpFrame frame, ushort channelNumber)
        {
            buffer.ValidateWrite(8);

            var frameStartOffset = buffer.WriteOffset;

            // header
            buffer.AppendWrite(FixedWidth.UInt);       // placeholder for frame size
            AmqpBitConverter.WriteUByte(buffer, 0x02); // data offset (2*4 = 8 bytes to account for header)
            AmqpBitConverter.WriteUByte(buffer, 0x00); // frame type = AMQP frame
            AmqpBitConverter.WriteUShort(buffer, channelNumber);

            // frame body, may be null/empty
            if (frame != null)
            {
                frame.Encode(buffer);
            }

            // frame size
            int frameSize = buffer.WriteOffset - frameStartOffset;

            AmqpBitConverter.WriteInt(buffer.Buffer, frameStartOffset, frameSize);
        }
예제 #8
0
 private void HandleConnectionFrame(AmqpFrame frame, ushort remoteChannelNumber, ByteBuffer buffer)
 {
     if (frame is Open)
     {
         HandleOpenFrame(frame as Open);
     }
     else if (frame is Begin)
     {
         InterceptBeginFrame(frame as Begin, remoteChannelNumber);
     }
     else if (frame is End)
     {
         InterceptEndFrame(frame as End, remoteChannelNumber);
     }
     else if (frame is Close)
     {
         HandleCloseFrame(frame as Close);
     }
     else
     {
         HandleSessionFrame(frame, remoteChannelNumber, buffer);
     }
 }