Beispiel #1
0
        public static AmqpLinkSettings Create(Attach attach)
        {
            AmqpLinkSettings settings = new AmqpLinkSettings();
            settings.LinkName = attach.LinkName;
            settings.Role = !attach.Role.Value;
            settings.Source = attach.Source;
            settings.Target = attach.Target;
            settings.SndSettleMode = attach.SndSettleMode;
            settings.RcvSettleMode = attach.RcvSettleMode;
            settings.MaxMessageSize = attach.MaxMessageSize;
            settings.Properties = attach.Properties;
            if (settings.Role.Value)
            {
                settings.TransferLimit = AmqpConstants.DefaultLinkCredit;
            }
            else
            {
                settings.InitialDeliveryCount = 0;
            }

            return settings;
        }
Beispiel #2
0
        public static Attach Clone(this Attach attach)
        {
            Attach clone = new Attach();
            clone.LinkName = attach.LinkName;
            clone.Role = attach.Role;
            clone.SndSettleMode = attach.SndSettleMode;
            clone.RcvSettleMode = attach.RcvSettleMode;
            clone.Source = attach.Source;
            clone.Target = attach.Target;
            clone.Unsettled = attach.Unsettled;
            clone.IncompleteUnsettled = attach.IncompleteUnsettled;
            clone.InitialDeliveryCount = attach.InitialDeliveryCount;
            clone.MaxMessageSize = attach.MaxMessageSize;
            clone.OfferedCapabilities = attach.OfferedCapabilities;
            clone.DesiredCapabilities = attach.DesiredCapabilities;
            clone.Properties = attach.Properties;

            return clone;
        }
Beispiel #3
0
        bool TryCreateRemoteLink(Attach attach, out AmqpLink link)
        {
            link = null;
            AmqpLinkSettings linkSettings = AmqpLinkSettings.Create(attach);

            try
            {
                link = this.linkFactory.CreateLink(this, linkSettings);
                link.RemoteHandle = attach.Handle;
                this.linksByRemoteHandle.Add(attach.Handle.Value, link);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                attach.Source = null;
                attach.Target = null;
                this.SendCommand(attach);

                if (link != null)
                {
                    link.TryClose(exception);
                }

                return false;
            }

            return true;
        }
Beispiel #4
0
        Error Negotiate(Attach attach)
        {
            if (attach.MaxMessageSize.HasValue && attach.MaxMessageSize.Value != 0)
            {
                this.settings.MaxMessageSize = this.settings.MaxMessageSize.HasValue ?
                    Math.Min(this.settings.MaxMessageSize.Value, attach.MaxMessageSize.Value) :
                    attach.MaxMessageSize.Value;
            }

            return null;
        }
Beispiel #5
0
        void OnReceiveAttach(Attach attach)
        {
            StateTransition stateTransition;
            this.TransitState("R:ATTACH", StateTransition.ReceiveOpen, out stateTransition);

            Error error = this.Negotiate(attach);
            if (error != null)
            {
                this.OnLinkOpenFailed(new AmqpException(error));
                return;
            }

            if (stateTransition.From == AmqpObjectState.OpenSent)
            {
                if (this.IsReceiver)
                {
                    Source source = this.settings.Source as Source;
                    if (source != null && source.Dynamic())
                    {
                        source.Address = ((Source)attach.Source).Address;
                    }
                }
                else
                {
                    Target target = this.settings.Target as Target;
                    if (target != null && target.Dynamic())
                    {
                        target.Address = ((Target)attach.Target).Address;
                    }
                }
            }
            
            if (stateTransition.To == AmqpObjectState.Opened)
            {
                if ((this.IsReceiver && attach.Source == null) ||
                    (!this.IsReceiver && attach.Target == null))
                {
                    // not linkendpoint was created on the remote side
                    // a detach should be sent immediately by peer with error
                    return;
                }

                if (this.IsReceiver)
                {
                    this.deliveryCount = attach.InitialDeliveryCount.Value;
                    this.settings.Source = attach.Source;
                }
                else
                {
                    this.settings.Target = attach.Target;
                }

                this.CompleteOpen(false, null);
            }
            else if (stateTransition.To == AmqpObjectState.OpenReceived)
            {
                Utils.Trace(TraceLevel.Verbose, "{0}: opending.", this);
                try
                {
                    this.Session.Connection.AmqpSettings.RuntimeProvider.BeginOpenLink(this, this.DefaultOpenTimeout, this.OnProviderLinkOpened, null);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }

                    this.OnLinkOpenFailed(exception);
                }
            }
        }