Exemplo n.º 1
0
        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));
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 void EnsureConnectionOpen()
 {
     if (this.connection == null)
     {
         lock (this.syncRoot)
         {
             if (this.connection == null)
             {
                 this.connection = OpenContainerAsyncResult.End(new OpenContainerAsyncResult(this, null, null));
             }
         }
     }
 }
Exemplo n.º 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);
                }
Exemplo n.º 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();
 }
Exemplo n.º 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();
 }
Exemplo n.º 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();
            }
Exemplo n.º 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();
            }
Exemplo n.º 13
0
        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));
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 15
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);
                }
            }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 18
0
 protected abstract void HandleConnection(AmqpConnection connection);
Exemplo n.º 19
0
 protected override void HandleConnection(AmqpConnection connection)
 {
     this.connectionHandler.HandleConnection(connection);
 }
Exemplo n.º 20
0
 void EnsureConnectionOpen()
 {
     if (this.connection == null)
     {
         lock (this.syncRoot)
         {
             if (this.connection == null)
             {
                 this.connection = OpenContainerAsyncResult.End(new OpenContainerAsyncResult(this, null, null));
             }
         }
     }
 }
Exemplo n.º 21
0
 AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings settings)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 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;
        }
Exemplo n.º 23
0
 AmqpSession Microsoft.ServiceBus.Messaging.Amqp.ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings sessionSettings)
 {
     return(new AmqpSession(this, sessionSettings, this.amqpSettings.RuntimeProvider));
 }
Exemplo n.º 24
0
 AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings sessionSettings)
 {
     return new AmqpSession(this, sessionSettings, this.amqpSettings.RuntimeProvider);
 }
Exemplo n.º 25
0
 protected abstract void HandleConnection(AmqpConnection connection);
Exemplo n.º 26
0
 protected AmqpSession(string type, AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory) : base(type)
 {
     this.connection  = connection;
     this.settings    = settings;
     this.linkFactory = linkFactory;
 }
Exemplo n.º 27
0
 protected AmqpSession(string type, AmqpConnection connection, AmqpSessionSettings settings) : this(type, connection, settings, null)
 {
 }
Exemplo n.º 28
0
 AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings sessionSettings)
 {
     return(new AmqpSession(this, sessionSettings, this.amqpSettings.RuntimeProvider));
 }
Exemplo n.º 29
0
 protected override void HandleConnection(AmqpConnection connection)
 {
     this.connectionHandler.HandleConnection(connection);
 }
 public ConnectionHandler(AmqpConnection connection, TimeSpan openTimeout)
 {
     this.connection  = connection;
     this.openTimeout = openTimeout;
 }
Exemplo n.º 31
0
 AmqpSession ISessionFactory.CreateSession(AmqpConnection connection, AmqpSessionSettings settings)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 32
0
 protected AmqpSession(AmqpConnection connection, AmqpSessionSettings settings)
 {
     this.connection = connection;
     this.settings = settings;
 }
Exemplo n.º 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();
            }
Exemplo n.º 34
0
 protected AmqpSession(AmqpConnection connection, AmqpSessionSettings settings)
 {
     this.connection = connection;
     this.settings   = settings;
 }
Exemplo n.º 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);
                }
            }