Exemple #1
0
        public void ContinueWork()
        {
            T value = default(T);

            lock (this.SyncRoot)
            {
                if (this.state == SerializedWorker <T> .State.BusyWithContinue)
                {
                    return;
                }
                else if (this.state == SerializedWorker <T> .State.Busy)
                {
                    this.state = SerializedWorker <T> .State.BusyWithContinue;
                    return;
                }
                else if (this.pendingWorkList.First != null)
                {
                    value      = this.pendingWorkList.First.Value;
                    this.state = SerializedWorker <T> .State.Busy;
                }
            }
            if (value != null)
            {
                this.DoWorkInternal(value, true);
            }
        }
Exemple #2
0
 public void ExtractFrameBuffers(ByteBuffer buffer, SerializedWorker <ByteBuffer> bufferHandler)
 {
     if (this.currentFrameBuffer != null)
     {
         int num = Math.Min(this.currentFrameBuffer.Size, buffer.Length);
         AmqpBitConverter.WriteBytes(this.currentFrameBuffer, buffer.Buffer, buffer.Offset, num);
         buffer.Complete(num);
         if (this.currentFrameBuffer.Size == 0)
         {
             ByteBuffer byteBuffer = this.currentFrameBuffer;
             this.currentFrameBuffer = null;
             bufferHandler.DoWork(byteBuffer);
         }
     }
     while (buffer.Length >= AmqpCodec.MinimumFrameDecodeSize)
     {
         int frameSize = AmqpCodec.GetFrameSize(buffer);
         if (frameSize < AmqpCodec.MinimumFrameDecodeSize || frameSize > this.maxFrameSize)
         {
             throw new AmqpException(AmqpError.FramingError, SRClient.InvalidFrameSize(frameSize, this.maxFrameSize));
         }
         int num1 = Math.Min(frameSize, buffer.Length);
         this.currentFrameBuffer = new ByteBuffer(frameSize, false);
         AmqpBitConverter.WriteBytes(this.currentFrameBuffer, buffer.Buffer, buffer.Offset, num1);
         buffer.Complete(num1);
         if (frameSize != num1)
         {
             break;
         }
         ByteBuffer byteBuffer1 = this.currentFrameBuffer;
         this.currentFrameBuffer = null;
         bufferHandler.DoWork(byteBuffer1);
     }
 }
Exemple #3
0
        protected AmqpLink(AmqpSession session, AmqpLinkSettings linkSettings)
        {
            if (linkSettings == null)
            {
                throw new ArgumentNullException("linkSettings");
            }

            this.Session               = session;
            this.settings              = linkSettings;
            this.linkCredit            = this.settings.TransferLimit;
            this.settings.AutoSendFlow = this.linkCredit > 0;
            this.syncRoot              = new object();
            Source source = (Source)this.settings.Source;

            if (source != null)
            {
                this.defaultOutcome = source.DefaultOutcome;
            }

            if (this.defaultOutcome == null)
            {
                this.defaultOutcome = AmqpConstants.ReleasedOutcome;
            }

            this.unsettledMap      = new Dictionary <ArraySegment <byte>, Delivery>(ByteArrayComparer.Instance);
            this.pendingDeliveries = new SerializedWorker <Delivery>(this.TrySendDelivery, this.AbortDelivery, false);
            session.AttachLink(this);
        }
Exemple #4
0
 public void Abort()
 {
     lock (this.SyncRoot)
     {
         this.pendingWorkList.Clear();
         this.state = SerializedWorker <T> .State.Idle;
     }
 }
Exemple #5
0
 public IncomingSessionChannel(AmqpSession session)
     : base(session, session.settings.IncomingBufferSize)
 {
     this.name             = session.ToString() + "(in)";
     this.pendingTransfers = new SerializedWorker <Tuple <AmqpLink, Transfer> >(this.OnTransfer, null, false);
     this.incomingWindow   = session.settings.IncomingWindow();
     this.flowThreshold    = this.incomingWindow == uint.MaxValue ? uint.MaxValue : this.incomingWindow * 2 / 3;
     this.IsReceiver       = true;
 }
Exemple #6
0
 public OutgoingSessionChannel(AmqpSession session)
     : base(session, session.settings.OutgoingBufferSize)
 {
     this.name         = session.ToString() + "(out)";
     this.maxFrameSize = session.connection.Settings.MaxFrameSize();
     this.onSettledDeliveryComplete = this.OnSettledDeliveryComplete;
     this.inflightDeliveries        = new SerializedWorker <Delivery>(this.OnSendDelivery, null, false);
     this.nextOutgoingId            = session.settings.NextOutgoingId.Value;
     this.outgoingWindow            = session.settings.OutgoingWindow.Value;
     this.remoteIncomingWindow      = session.settings.OutgoingWindow.Value;
     this.IsReceiver = false;
 }
Exemple #7
0
 private void DoWorkInternal(T work, bool fromList)
 {
     while (work != null)
     {
         if (!this.workDelegate.Invoke(work))
         {
             lock (this.SyncRoot)
             {
                 if (this.state != SerializedWorker <T> .State.BusyWithContinue)
                 {
                     if (!fromList)
                     {
                         this.pendingWorkList.AddFirst(work);
                     }
                     this.state = SerializedWorker <T> .State.WaitingForContinue;
                     work       = default(T);
                 }
                 else
                 {
                     this.state = SerializedWorker <T> .State.Busy;
                 }
             }
         }
         else
         {
             lock (this.SyncRoot)
             {
                 work = default(T);
                 if (fromList && this.pendingWorkList.First != null)
                 {
                     this.pendingWorkList.RemoveFirst();
                 }
                 if (this.pendingWorkList.First != null)
                 {
                     work     = this.pendingWorkList.First.Value;
                     fromList = true;
                 }
                 if (work != null)
                 {
                     this.state = SerializedWorker <T> .State.Busy;
                 }
                 else
                 {
                     this.state = SerializedWorker <T> .State.Idle;
                     break;
                 }
             }
         }
     }
 }
Exemple #8
0
 public void DoWork(T work)
 {
     lock (this.SyncRoot)
     {
         if (this.state == SerializedWorker <T> .State.Idle)
         {
             this.state = SerializedWorker <T> .State.Busy;
         }
         else
         {
             this.pendingWorkList.AddLast(work);
             return;
         }
     }
     this.DoWorkInternal(work, false);
 }
Exemple #9
0
        public AmqpConnectionBase(TransportBase transport, AmqpConnectionSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            this.settings = settings;

            Fx.Assert(transport != null, "transport must not be null.");
            this.principal = transport.Principal;
            this.asyncIO   = new AsyncIO(
                AmqpConstants.AsyncBufferSize,
                transport,
                new Action <ByteBuffer>(this.OnReceiveBuffer),
                this.OnAsyncIoFaulted);
            this.bufferHandler = new SerializedWorker <ByteBuffer>(this.OnReceiveFrameBuffer, null, false);
        }
Exemple #10
0
        public void ExtractFrameBuffers(ByteBuffer buffer, SerializedWorker <ByteBuffer> bufferHandler)
        {
            if (this.currentFrameBuffer != null)
            {
                int sizeToWrite = Math.Min(this.currentFrameBuffer.Size, buffer.Length);

                this.currentFrameBuffer.WriteBytes(buffer.Buffer, buffer.Offset, sizeToWrite);
                buffer.Complete(sizeToWrite);

                if (this.currentFrameBuffer.Size == 0)
                {
                    bufferHandler.DoWork(this.currentFrameBuffer);
                    this.currentFrameBuffer = null;
                }
            }

            while (buffer.Length >= AmqpCodec.MinimumFrameDecodeSize)
            {
                int frameSize = AmqpCodec.GetFrameSize(buffer);
                if (frameSize < AmqpCodec.MinimumFrameDecodeSize || frameSize > this.maxFrameSize)
                {
                    throw new AmqpException(AmqpError.FramingError, SRClient.InvalidFrameSize(frameSize, this.maxFrameSize));
                }

                int sizeToWrite = Math.Min(frameSize, buffer.Length);
                this.currentFrameBuffer = ByteBuffer.Wrap(new byte[frameSize], 0, 0, frameSize);
                this.currentFrameBuffer.WriteBytes(buffer.Buffer, buffer.Offset, sizeToWrite);
                buffer.Complete(sizeToWrite);

                if (frameSize == sizeToWrite)
                {
                    bufferHandler.DoWork(this.currentFrameBuffer);
                    this.currentFrameBuffer = null;
                }
                else
                {
                    break;
                }
            }
        }
Exemple #11
0
 protected abstract void ParseFrameBuffers(ByteBuffer buffer, SerializedWorker <ByteBuffer> bufferHandler);
Exemple #12
0
 protected AmqpLink(AmqpSession session, AmqpLinkSettings linkSettings) : this("link", session, linkSettings)
 {
     this.inflightDeliveries = new SerializedWorker <Delivery>(this);
 }
Exemple #13
0
 protected override void ParseFrameBuffers(ByteBuffer buffer, SerializedWorker <ByteBuffer> bufferHandler)
 {
     this.decoder.ExtractFrameBuffers(buffer, bufferHandler);
 }
Exemple #14
0
 public Publisher(Container container, string node)
     : base(container, node)
 {
     this.sender = new SerializedWorker <AmqpMessage>(this.OnSend, null, false);
 }
 public SendingAmqpLink(AmqpSession session, AmqpLinkSettings settings) : base(session, settings)
 {
     this.pendingDeliveries   = new SerializedWorker <AmqpMessage>(this);
     this.inflightSends       = new WorkCollection <ArraySegment <byte>, SendingAmqpLink.SendAsyncResult, Outcome>(ByteArrayComparer.Instance);
     this.lastFlowRequestTime = DateTime.UtcNow;
 }
Exemple #16
0
 public SerializedWorker(IWorkDelegate <T> workProcessor)
 {
     this.workDelegate    = workProcessor;
     this.state           = SerializedWorker <T> .State.Idle;
     this.pendingWorkList = new LinkedList <T>();
 }