void OnAcceptTransport(TransportAsyncCallbackArgs args)
        {
            Fx.Assert(args.Exception == null, "Should not be failed.");
            Fx.Assert(args.Transport != null, "Should have a transport");

            AmqpConnectionSettings settings = this.connectionSettings.Clone();

            settings.OnOpenCallback = this.OnReceiveConnectionOpen;
            AmqpConnection connection = null;

            try
            {
                connection = this.CreateConnection(
                    args.Transport,
                    (ProtocolHeader)args.UserToken,
                    false,
                    this.amqpSettings.Clone(),
                    settings);
                connection.BeginOpen(connection.DefaultOpenTimeout, this.onConnectionOpenComplete, connection);
            }
            catch (Exception ex)
            {
                if (Fx.IsFatal(ex))
                {
                    throw;
                }

                if (connection != null)
                {
                    connection.TryClose(ExceptionHelper.ToAmqpException(ex));
                }
            }
        }
Beispiel #2
0
        public void AddSession(AmqpSession session, ushort?channel)
        {
            int?nullable1;

            session.Closed += new EventHandler(this.OnSessionClosed);
            lock (base.ThisLock)
            {
                session.LocalChannel = (ushort)this.sessionsByLocalHandle.Add(session);
                ushort?nullable2 = channel;
                if (nullable2.HasValue)
                {
                    nullable1 = new int?((int)nullable2.GetValueOrDefault());
                }
                else
                {
                    nullable1 = null;
                }
                if (nullable1.HasValue)
                {
                    this.sessionsByRemoteHandle.Add(channel.Value, session);
                }
            }
            MessagingClientEtwProvider.TraceClient <AmqpConnection, AmqpSession, ushort?>((AmqpConnection source, AmqpSession sess, ushort?ch) => {
                MessagingClientEventSource provider = MessagingClientEtwProvider.Provider;
                AmqpConnection amqpConnection       = source;
                AmqpSession amqpSession             = sess;
                ushort localChannel = sess.LocalChannel;
                ushort?nullable     = ch;
                provider.EventWriteAmqpAddSession(amqpConnection, amqpSession, localChannel, (nullable.HasValue ? nullable.GetValueOrDefault() : 0));
            }, this, session, channel);
        }
Beispiel #3
0
        static void OnHeartBeatTimer(object state)
        {
            AmqpConnection thisPtr   = (AmqpConnection)state;
            bool           wasActive = thisPtr.active;

            thisPtr.active = false;
            if (thisPtr.State != AmqpObjectState.Opened)
            {
                return;
            }

            try
            {
                if (!wasActive)
                {
                    thisPtr.AsyncIO.Writer.WriteBuffer(Frame.Empty.Buffer, null, null, null);
                }

                thisPtr.heartBeatTimer.Set(thisPtr.heartBeatInterval);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                Utils.Trace(TraceLevel.Warning, "{0}: OnHeartBeatTimer failed with exception {1}", thisPtr, exception);
            }
        }
        public AmqpSession CreateSession(AmqpConnection connection, AmqpSessionSettings settings)
        {
            settings.DispositionInterval = TimeSpan.Zero;
            AmqpSession amqpSession = new AmqpSession(connection, settings, this);

            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteAmqpLogOperation(this, TraceOperation.Create, amqpSession));
            amqpSession.BeginOpen(this.OpenTimeout, AmqpTransportManager.sessionOpenCallback, amqpSession);
            return(amqpSession);
        }
        public AmqpConnection CreateConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings)
        {
            AmqpConnection amqpConnection = new AmqpConnection(transport, protocolHeader, isInitiator, amqpSettings, connectionSettings)
            {
                SessionFactory = this
            };

            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteAmqpLogOperation(this, TraceOperation.Connect, amqpConnection));
            return(amqpConnection);
        }
        public AmqpConnection CreateConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings)
        {
            if (this.amqpSettings.RequireSecureTransport && !transport.IsSecure)
            {
                throw new AmqpException(AmqpError.NotAllowed, SR.AmqpTransportNotSecure);
            }

            AmqpConnection connection = new AmqpConnection(transport, protocolHeader, isInitiator, amqpSettings, connectionSettings);

            Utils.Trace(TraceLevel.Info, "{0}: Created {1}", this, connection);
            return(connection);
        }
Beispiel #7
0
 void EnsureConnectionOpen()
 {
     if (this.connection == null)
     {
         lock (this.syncRoot)
         {
             if (this.connection == null)
             {
                 this.connection = OpenContainerAsyncResult.End(new OpenContainerAsyncResult(this, null, null));
             }
         }
     }
 }
Beispiel #8
0
                private void OnTransportCallback(TransportAsyncCallbackArgs args)
                {
                    if (args.Exception != null)
                    {
                        base.Complete(args.CompletedSynchronously, args.Exception);
                        return;
                    }
                    AmqpConnectionSettings amqpConnectionSetting = new AmqpConnectionSettings()
                    {
                        ContainerId = Guid.NewGuid().ToString("N")
                    };

                    this.AmqpConnection = new AmqpConnection(args.Transport, this.amqpSettings, amqpConnectionSetting);
                    base.Complete(args.CompletedSynchronously);
                }
Beispiel #9
0
 public AmqpSession(AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory)
 {
     Fx.Assert(connection != null, "connection must not be null");
     Fx.Assert(settings != null, "settings must not be null");
     this.connection = connection;
     this.settings = settings;
     this.linkFactory = linkFactory;
     this.State = AmqpObjectState.Start;
     this.links = new Dictionary<string, AmqpLink>();
     this.linksByLocalHandle = new HandleTable<AmqpLink>(uint.MaxValue);
     this.linksByRemoteHandle = new HandleTable<AmqpLink>(uint.MaxValue);
     this.outgoingChannel = new OutgoingSessionChannel(this);
     this.incomingChannel = new IncomingSessionChannel(this);
     this.diagnostics = new Diagnostics();
 }
Beispiel #10
0
 public AmqpSession(AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory)
 {
     Fx.Assert(connection != null, "connection must not be null");
     Fx.Assert(settings != null, "settings must not be null");
     this.connection          = connection;
     this.settings            = settings;
     this.linkFactory         = linkFactory;
     this.State               = AmqpObjectState.Start;
     this.links               = new Dictionary <string, AmqpLink>();
     this.linksByLocalHandle  = new HandleTable <AmqpLink>(uint.MaxValue);
     this.linksByRemoteHandle = new HandleTable <AmqpLink>(uint.MaxValue);
     this.outgoingChannel     = new OutgoingSessionChannel(this);
     this.incomingChannel     = new IncomingSessionChannel(this);
     this.diagnostics         = new Diagnostics();
 }
Beispiel #11
0
            protected override void OnClosing()
            {
                SendingAmqpLink link = this.Link;

                if (link != null)
                {
                    link.Closed -= this.onAmqpObjectClosed;
                }
                AmqpConnection connection = this.Connection;

                if (connection != null)
                {
                    connection.Closed -= this.onAmqpObjectClosed;
                }
                base.OnClosing();
            }
Beispiel #12
0
            void OnAcceptTransport(TransportAsyncCallbackArgs args)
            {
                if (args.Exception != null)
                {
                    return;
                }

                AmqpConnection connection = new AmqpConnection(args.Transport, this.settings, new AmqpConnectionSettings()
                {
                    ContainerId = this.container.id
                });

                connection.Closed += new EventHandler(connection_Closed);
                lock (this.syncRoot)
                {
                    this.connections.Add(connection);
                }

                connection.Open();
            }
        void OnConnectionOpenComplete(IAsyncResult result)
        {
            AmqpConnection connection = (AmqpConnection)result.AsyncState;

            try
            {
                connection.EndOpen(result);

                this.HandleConnection(connection);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                connection.TryClose(ExceptionHelper.ToAmqpException(exception));
            }
        }
Beispiel #14
0
        private static void OnHeartBeatTimer(object state)
        {
            AmqpConnection amqpConnection = (AmqpConnection)state;

            if (amqpConnection.State != AmqpObjectState.Opened)
            {
                return;
            }
            bool     flag      = false;
            DateTime dateTime  = amqpConnection.lastSendTime;
            DateTime utcNow    = DateTime.UtcNow;
            DateTime dateTime1 = utcNow;

            if (utcNow.Subtract(dateTime) < TimeSpan.FromMilliseconds((double)amqpConnection.heartBeatInterval))
            {
                flag      = true;
                dateTime1 = dateTime;
            }
            try
            {
                if (!flag)
                {
                    amqpConnection.SendBuffer(Frame.EncodeCommand(FrameType.Amqp, 0, null, 0));
                }
                IOThreadTimer oThreadTimer = amqpConnection.heartBeatTimer;
                DateTime      dateTime2    = dateTime1.AddMilliseconds((double)amqpConnection.heartBeatInterval);
                oThreadTimer.Set(dateTime2.Subtract(utcNow));
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                MessagingClientEtwProvider.TraceClient <AmqpConnection, Exception>((AmqpConnection source, Exception ex) => MessagingClientEtwProvider.Provider.EventWriteAmqpLogError(source, "OnHeartBeatTimer", ex.Message), amqpConnection, exception);
            }
        }
            protected override void HandleConnection(AmqpConnection connection)
            {
                try
                {
                    Fx.Assert(connection.Settings.RemoteHostName != null, "RemoteHostName cannot be null. It has been validated in OnConnectionOpen.");
                    IConnectionHandler handler = null;
                    if (!this.connectionHandlers.TryGetValue(connection.Settings.RemoteHostName, out handler))
                    {
                        throw new AmqpException(AmqpError.NotFound, SR.AmqpConnectionHandlerNotFound(connection.Settings.RemoteHostName));
                    }

                    handler.HandleConnection(connection);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }

                    throw ExceptionHelper.ToAmqpException(exception);
                }
            }
Beispiel #16
0
        public AmqpSession(AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory) : base("session")
        {
            uint valueOrDefault;
            uint num;

            this.connection  = connection;
            this.settings    = settings;
            this.linkFactory = linkFactory;
            base.State       = AmqpObjectState.Start;
            this.links       = new Dictionary <string, AmqpLink>();
            uint?handleMax = settings.HandleMax;

            if (handleMax.HasValue)
            {
                valueOrDefault = handleMax.GetValueOrDefault();
            }
            else
            {
                valueOrDefault = -1;
            }
            this.linksByLocalHandle = new HandleTable <AmqpLink>(valueOrDefault);
            uint?nullable = settings.HandleMax;

            if (nullable.HasValue)
            {
                num = nullable.GetValueOrDefault();
            }
            else
            {
                num = -1;
            }
            this.linksByRemoteHandle = new HandleTable <AmqpLink>(num);
            this.outgoingChannel     = new AmqpSession.OutgoingSessionChannel(this);
            this.incomingChannel     = new AmqpSession.IncomingSessionChannel(this);
            this.upgraded            = true;
        }
        private void OnAcceptTransport(TransportAsyncCallbackArgs args)
        {
            AmqpConnectionSettings amqpConnectionSetting = this.amqpConnectionSettings;
            AmqpConnection         amqpConnection        = null;

            try
            {
                amqpConnection = this.CreateConnection(args.Transport, (ProtocolHeader)args.UserToken, false, this.amqpSettings, amqpConnectionSetting);
                (new AmqpTransportManager.ConnectionHandler(amqpConnection, this.OpenTimeout)).Start();
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                Fx.Exception.TraceHandled(exception, "AmqpTransportManager.OnAcceptTransport", null);
                if (amqpConnection != null)
                {
                    amqpConnection.SafeClose(exception);
                }
            }
        }
 protected abstract void HandleConnection(AmqpConnection connection);
 protected override void HandleConnection(AmqpConnection connection)
 {
     this.connectionHandler.HandleConnection(connection);
 }
Beispiel #20
0
 void EnsureConnectionOpen()
 {
     if (this.connection == null)
     {
         lock (this.syncRoot)
         {
             if (this.connection == null)
             {
                 this.connection = OpenContainerAsyncResult.End(new OpenContainerAsyncResult(this, null, null));
             }
         }
     }
 }
Beispiel #21
0
 AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings settings)
 {
     throw new NotImplementedException();
 }
Beispiel #22
0
        public AmqpConnection CreateConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings)
        {
            if (this.amqpSettings.RequireSecureTransport && !transport.IsSecure)
            {
                throw new AmqpException(AmqpError.NotAllowed, SR.AmqpTransportNotSecure);
            }

            AmqpConnection connection = new AmqpConnection(transport, protocolHeader, isInitiator, amqpSettings, connectionSettings);
            Utils.Trace(TraceLevel.Info, "{0}: Created {1}", this, connection);
            return connection;
        }
Beispiel #23
0
 AmqpSession Microsoft.ServiceBus.Messaging.Amqp.ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings sessionSettings)
 {
     return(new AmqpSession(this, sessionSettings, this.amqpSettings.RuntimeProvider));
 }
Beispiel #24
0
 AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings sessionSettings)
 {
     return new AmqpSession(this, sessionSettings, this.amqpSettings.RuntimeProvider);
 }
Beispiel #25
0
 protected abstract void HandleConnection(AmqpConnection connection);
Beispiel #26
0
 protected AmqpSession(string type, AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory) : base(type)
 {
     this.connection  = connection;
     this.settings    = settings;
     this.linkFactory = linkFactory;
 }
Beispiel #27
0
 protected AmqpSession(string type, AmqpConnection connection, AmqpSessionSettings settings) : this(type, connection, settings, null)
 {
 }
Beispiel #28
0
 AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings sessionSettings)
 {
     return(new AmqpSession(this, sessionSettings, this.amqpSettings.RuntimeProvider));
 }
Beispiel #29
0
 protected override void HandleConnection(AmqpConnection connection)
 {
     this.connectionHandler.HandleConnection(connection);
 }
 public ConnectionHandler(AmqpConnection connection, TimeSpan openTimeout)
 {
     this.connection  = connection;
     this.openTimeout = openTimeout;
 }
Beispiel #31
0
 AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings settings)
 {
     throw new NotImplementedException();
 }
Beispiel #32
0
 protected AmqpSession(AmqpConnection connection, AmqpSessionSettings settings)
 {
     this.connection = connection;
     this.settings = settings;
 }
Beispiel #33
0
            void OnAcceptTransport(TransportAsyncCallbackArgs args)
            {
                if (args.Exception != null)
                {
                    return;
                }

                AmqpConnection connection = new AmqpConnection(args.Transport, this.settings, new AmqpConnectionSettings() { ContainerId = this.container.id });
                connection.Closed += new EventHandler(connection_Closed);
                lock (this.syncRoot)
                {
                    this.connections.Add(connection);
                }

                connection.Open();
            }
Beispiel #34
0
 protected AmqpSession(AmqpConnection connection, AmqpSessionSettings settings)
 {
     this.connection = connection;
     this.settings   = settings;
 }
Beispiel #35
0
            protected override void HandleConnection(AmqpConnection connection)
            {
                try
                {
                    Fx.Assert(connection.Settings.RemoteHostName != null, "RemoteHostName cannot be null. It has been validated in OnConnectionOpen.");
                    IConnectionHandler handler = null;
                    if (!this.connectionHandlers.TryGetValue(connection.Settings.RemoteHostName, out handler))
                    {
                        throw new AmqpException(AmqpError.NotFound, SR.AmqpConnectionHandlerNotFound(connection.Settings.RemoteHostName));
                    }

                    handler.HandleConnection(connection);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }

                    throw ExceptionHelper.ToAmqpException(exception);
                }
            }