Exemplo n.º 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());
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 4
0
 public LinkConsumer(ConcurrentQueue queue, AmqpLink link)
     : base(queue)
 {
     this.link = link;
     this.link.ReceivedFlow += LinkReceivedFlow;
 }
Exemplo n.º 5
0
 public void OnLinkAttached(AmqpLink link)
 {
 }
Exemplo n.º 6
0
 public void OnDelivery(AmqpLink link, Delivery delivery)
 {
 }
Exemplo n.º 7
0
 public bool CanAttachLink(AmqpLink newLink, Attach attach)
 {
     return true;
 }
Exemplo n.º 8
0
 internal void NotifyUnsettledIncomingDelivery(AmqpLink link, Delivery delivery)
 {
     incomingUnsettledMap.Add(delivery);
 }
Exemplo n.º 9
0
 public bool CanAttachLink(AmqpLink newLink, Attach attach)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 12
0
 internal void NotifyUnsettledIncomingDelivery(AmqpLink link, Delivery delivery)
 {
     incomingUnsettledMap.Add(delivery);
 }
Exemplo n.º 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);
 }