Beispiel #1
0
        public void OnDelivery(AmqpLink link, Delivery delivery)
        {
            var message = AnnotatedMessage.Decode(delivery.PayloadBuffer);
            var queue = linkNameToQueue[link.Name];
            queue.Enqueue(message);

            link.SetDeliveryTerminalState(delivery, new Accepted());
        }
Beispiel #2
0
        public bool CanAttachLink(AmqpLink newLink, Attach attach)
        {
            var queueName = "";

            if (attach.IsReceiver)
                queueName = attach.Source.Address.ToLowerInvariant();
            if (!attach.IsReceiver)
                queueName = attach.Target.Address.ToLowerInvariant();

            var queue = queues.GetOrAdd(queueName, x => new ConcurrentQueue(0, logWriter));

            return true;
        }
Beispiel #3
0
 public void OnLinkAttached(AmqpLink link)
 {
     if (link.IsReceiverLink)
     {
         link.SetLinkCredit(25);
         linkNameToQueue[link.Name] = queues[link.TargetAddress.ToLowerInvariant()];
     }
     if (link.IsSenderLink)
     {
         var queue = queues[link.SourceAddress.ToLowerInvariant()];
         linkNameToQueue[link.Name] = queue;
         linkToConsumer[link] = new LinkConsumer(queue, link);
     }
 }
Beispiel #4
0
 public LinkConsumer(ConcurrentQueue queue, AmqpLink link)
     : base(queue)
 {
     this.link = link;
     this.link.ReceivedFlow += LinkReceivedFlow;
 }
Beispiel #5
0
 public void OnLinkAttached(AmqpLink link)
 {
 }
Beispiel #6
0
 public void OnDelivery(AmqpLink link, Delivery delivery)
 {
 }
Beispiel #7
0
 public bool CanAttachLink(AmqpLink newLink, Attach attach)
 {
     return true;
 }
Beispiel #8
0
 internal void NotifyUnsettledIncomingDelivery(AmqpLink link, Delivery delivery)
 {
     incomingUnsettledMap.Add(delivery);
 }
Beispiel #9
0
 public bool CanAttachLink(AmqpLink newLink, Attach attach)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
        private void InterceptAttachFrame(Attach attach)
        {
            if (!State.CanReceiveFrames())
                throw new AmqpException(ErrorCode.IllegalState, $"Received Attach frame but session state is {State.ToString()}.");
            if (State == SessionStateEnum.DISCARDING)
                return;

            if (attach.Handle > sessionMaxHandle)
                throw new AmqpException(ErrorCode.NotAllowed, $"Cannot allocate more handles. The maximum number of handles is {sessionMaxHandle}.");

            // is this for an existing locally attached frame?
            for (uint i = 0; i < localLinks.Length; i++)
            {
                var existingLink = localLinks[i];
                if (existingLink != null && existingLink.State == LinkStateEnum.ATTACH_SENT && string.Compare(existingLink.Name, attach.Name, true) == 0)
                {
                    AttachRemoteLink(attach, existingLink);
                    // Link is expecting an attach frame
                    existingLink.HandleLinkFrame(attach);
                    return; // done
                }
            }

            // must be a new inbound attach
            var nextLocalHandle = localLinks.GetFirstNullIndexOrAdd(); // reuse existing handle, or just grab the next one
            var isLocalLinkReceiver = !attach.IsReceiver;
            var newLink = new AmqpLink(this, attach.Name, nextLocalHandle, isLocalLinkReceiver, false, attach.Handle);

            if (!Connection.Container.CanAttachLink(newLink, attach))
                throw new AmqpException(ErrorCode.PreconditionFailed, "Cannot Attach Link");

            var index = localLinks[nextLocalHandle] = newLink;
            AttachRemoteLink(attach, newLink);
            newLink.HandleLinkFrame(attach);
        }
Beispiel #11
0
 private void AttachRemoteLink(Attach attach, AmqpLink link)
 {
     if (remoteLinks[attach.Handle] != null)
     {
         throw new AmqpException(ErrorCode.HandleInUse, $"The handle '{attach.Handle}' is already allocated for '{remoteLinks[attach.Handle].Name}'");
     }
     remoteLinks[attach.Handle] = link;
 }
Beispiel #12
0
 internal void NotifyUnsettledIncomingDelivery(AmqpLink link, Delivery delivery)
 {
     incomingUnsettledMap.Add(delivery);
 }
Beispiel #13
0
 public void UnmapLink(AmqpLink link, bool destoryLink)
 {
     trace.Debug("Detached Link: LOC({0}) <-> RMT({1})", link.LocalHandle, link.RemoteHandle);
     localLinks[link.LocalHandle] = null;
     remoteLinks[link.RemoteHandle] = null;
     if (destoryLink)
         trace.Debug("Destroyed Link: LOC({0}) <-> RMT({1})", link.LocalHandle, link.RemoteHandle);
 }