Example #1
0
 AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings sessionSettings)
 {
     return(new AmqpSession(this, sessionSettings, this.amqpSettings.RuntimeProvider));
 }
Example #2
0
            protected override IEnumerator <AsyncStep> GetAsyncSteps()
            {
                string address = CbsConstants.CbsAddress;

                while (this.RemainingTime() > TimeSpan.Zero)
                {
                    try
                    {
                        AmqpSessionSettings sessionSettings = new AmqpSessionSettings()
                        {
                            Properties = new Fields()
                        };
                        this.session = new AmqpSession(this.connection, sessionSettings, this);
                        connection.AddSession(session, null);
                    }
                    catch (InvalidOperationException exception)
                    {
                        this.Complete(exception);
                        yield break;
                    }

                    yield return(this.CallAsync(
                                     (thisPtr, t, c, s) => thisPtr.session.BeginOpen(t, c, s),
                                     (thisPtr, r) => thisPtr.session.EndOpen(r),
                                     ExceptionPolicy.Continue));

                    Exception lastException = this.LastAsyncStepException;
                    if (lastException != null)
                    {
                        AmqpTrace.Provider.AmqpOpenEntityFailed(this.connection, this.session, string.Empty, address, lastException.Message);
                        this.session.Abort();
                        this.Complete(lastException);
                        yield break;
                    }

                    Fields properties = new Fields();
                    properties.Add(CbsConstants.TimeoutName, (uint)this.RemainingTime().TotalMilliseconds);
                    this.Link = new RequestResponseAmqpLink("cbs", this.session, address, properties);
                    yield return(this.CallAsync(
                                     (thisPtr, t, c, s) => thisPtr.Link.BeginOpen(t, c, s),
                                     (thisPtr, r) => thisPtr.Link.EndOpen(r),
                                     ExceptionPolicy.Continue));

                    lastException = this.LastAsyncStepException;
                    if (lastException != null)
                    {
                        AmqpTrace.Provider.AmqpOpenEntityFailed(this.connection, this.Link, this.Link.Name, address, lastException.Message);
                        this.session.SafeClose();
                        this.Link = null;
                        this.Complete(lastException);
                        yield break;
                    }

                    AmqpTrace.Provider.AmqpOpenEntitySucceeded(this.connection, this.Link, this.Link.Name, address);
                    yield break;
                }

                if (this.session != null)
                {
                    this.session.SafeClose();
                }

                this.Complete(new TimeoutException(AmqpResources.GetString(AmqpResources.AmqpTimeout, this.OriginalTimeout, address)));
            }
Example #3
0
 /// <summary>
 /// Initializes the session object.
 /// </summary>
 /// <param name="connection">The connection in which the session is created.</param>
 /// <param name="settings">The session settings.</param>
 /// <param name="linkFactory">The factory to create <see cref="AmqpLink"/> objects when an <see cref="Attach"/> frame is received.</param>
 public AmqpSession(AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory)
     : this("session", connection, settings, linkFactory)
 {
 }