コード例 #1
0
        Link IContainer.CreateLink(ListenerConnection connection, ListenerSession session, Attach attach)
        {
            ListenerLink link = new ListenerLink(session, attach);

            link.SafeAddClosed(this.onLinkClosed);
            return(link);
        }
コード例 #2
0
        async Task HandleTransportAsync(IAsyncTransport transport)
        {
            if (this.saslSettings != null)
            {
                ListenerSaslProfile profile = new ListenerSaslProfile(this);
                transport = await profile.OpenAsync(null, this.BufferManager, transport);
            }

            Connection connection  = new ListenerConnection(this, this.address, transport);
            bool       shouldClose = false;

            lock (this.connections)
            {
                if (!this.closed)
                {
                    connection.Closed += this.OnConnectionClosed;
                    this.connections.Add(connection);
                }
                else
                {
                    shouldClose = true;
                }
            }

            if (shouldClose)
            {
                await connection.CloseAsync();
            }
            else
            {
                AsyncPump pump = new AsyncPump(this.BufferManager, transport);
                pump.Start(connection);
            }
        }
コード例 #3
0
ファイル: ContainerHost.cs プロジェクト: mbassit/amqpnetlite
        bool IContainer.AttachLink(ListenerConnection connection, ListenerSession session, Link link, Attach attach)
        {
            var listenerLink = (ListenerLink)link;

            if (!this.linkCollection.TryAdd(listenerLink))
            {
                throw new AmqpException(ErrorCode.Stolen, string.Format("Link '{0}' has been attached already.", attach.LinkName));
            }

            string address = attach.Role ? ((Source)attach.Source).Address : ((Target)attach.Target).Address;

            MessageProcessor messageProcessor;

            if (TryGetProcessor(this.messageProcessors, address, out messageProcessor))
            {
                messageProcessor.AddLink(listenerLink, address);
                return(true);
            }

            RequestProcessor requestProcessor;

            if (TryGetProcessor(this.requestProcessors, address, out requestProcessor))
            {
                requestProcessor.AddLink(listenerLink, address, attach);
                return(true);
            }

            if (this.linkProcessor != null)
            {
                this.linkProcessor.Process(new AttachContext(listenerLink, attach));
                return(false);
            }

            throw new AmqpException(ErrorCode.NotFound, "No processor was found at " + address);
        }
コード例 #4
0
        bool IContainer.AttachLink(ListenerConnection connection, ListenerSession session, Link link, Attach attach)
        {
            string address      = attach.Role ? ((Source)attach.Source).Address : ((Target)attach.Target).Address;
            var    listenerLink = (ListenerLink)link;

            MessageProcessor messageProcessor;

            if (TryGetProcessor(this.messageProcessors, address, out messageProcessor))
            {
                messageProcessor.AddLink(listenerLink, address);
                return(true);
            }

            RequestProcessor requestProcessor;

            if (TryGetProcessor(this.requestProcessors, address, out requestProcessor))
            {
                requestProcessor.AddLink(listenerLink, address, attach);
                return(true);
            }

            if (this.linkProcessor != null)
            {
                this.linkProcessor.Process(new AttachContext(listenerLink, attach));
                return(false);
            }

            throw new AmqpException(ErrorCode.NotFound, "No processor was found at " + address);
        }
コード例 #5
0
        async Task HandleTransportAsync(IAsyncTransport transport, IHandler handler, object context)
        {
            IPrincipal principal = null;

            if (this.saslSettings != null)
            {
                ListenerSaslProfile profile = new ListenerSaslProfile(this);
                transport = await profile.NegotiateAsync(transport).ConfigureAwait(false);

                principal = profile.GetPrincipal();
            }

            var connection = new ListenerConnection(this, this.address, handler, transport);

            if (principal == null)
            {
                // SASL principal preferred. If not present, check transport.
                IAuthenticated authenticated = transport as IAuthenticated;
                if (authenticated != null)
                {
                    principal = authenticated.Principal;
                }
            }

            connection.Principal = principal;

            bool shouldClose = false;

            lock (this.connections)
            {
                if (!this.closed)
                {
                    connection.Closed += this.OnConnectionClosed;
                    this.connections.Add(connection);
                }
                else
                {
                    shouldClose = true;
                }
            }

            if (shouldClose)
            {
                await connection.CloseAsync().ConfigureAwait(false);
            }
            else
            {
                if (handler != null && handler.CanHandle(EventId.ConnectionAccept))
                {
                    handler.Handle(Event.Create(EventId.ConnectionAccept, connection, context: context));
                }

                AsyncPump pump = new AsyncPump(this.BufferManager, transport);
                pump.Start(connection);
            }
        }
コード例 #6
0
        async Task HandleTransportAsync(IAsyncTransport transport)
        {
            IPrincipal principal = null;

            if (this.saslSettings != null)
            {
                ListenerSaslProfile profile = new ListenerSaslProfile(this);
                transport = await profile.NegotiateAsync(transport);

                principal = profile.GetPrincipal();
            }

            IHandler handler    = this.HandlerFactory?.Invoke(this);
            var      connection = new ListenerConnection(this, this.address, handler, transport);

            if (principal == null)
            {
                // SASL principal preferred. If not present, check transport.
                IAuthenticated authenticated = transport as IAuthenticated;
                if (authenticated != null)
                {
                    principal = authenticated.Principal;
                }
            }

            connection.Principal = principal;

            bool shouldClose = false;

            lock (this.connections)
            {
                if (!this.closed)
                {
                    connection.Closed += this.OnConnectionClosed;
                    this.connections.Add(connection);
                }
                else
                {
                    shouldClose = true;
                }
            }

            if (shouldClose)
            {
                await connection.CloseAsync();
            }
            else
            {
                AsyncPump pump = new AsyncPump(this.BufferManager, transport);
                pump.Start(connection);
            }
        }
コード例 #7
0
        async Task HandleTransportAsync(IAsyncTransport transport)
        {
            if (this.saslMechanisms != null)
            {
                ListenerSasProfile profile = new ListenerSasProfile(this);
                transport = await profile.OpenAsync(null, transport);
            }

            Connection connection = new ListenerConnection(this, this.address, transport);

            connection.Closed += this.OnConnectionClosed;
            lock (this.connections)
            {
                this.connections.Add(connection);
            }

            AsyncPump pump = new AsyncPump(transport);

            pump.Start(connection);
        }
コード例 #8
0
        bool IContainer.AttachLink(ListenerConnection connection, ListenerSession session, Link link, Attach attach)
        {
            var listenerLink = (ListenerLink)link;

            if (!this.linkCollection.TryAdd(listenerLink))
            {
                throw new AmqpException(ErrorCode.Stolen, string.Format("Link '{0}' has been attached already.", attach.LinkName));
            }

            string address = null;

            if (this.AddressResolver != null)
            {
                address = this.AddressResolver(this, attach);
            }

            if (address == null)
            {
                address = attach.Role ? ((Source)attach.Source).Address : ((Target)attach.Target).Address;
            }

            if (address != null)
            {
                if (listenerLink.Role)
                {
                    MessageProcessor messageProcessor;
                    if (TryGetProcessor(this.messageProcessors, address, out messageProcessor))
                    {
                        messageProcessor.AddLink(listenerLink, address);
                        return(true);
                    }
                }
                else
                {
                    MessageSource messageSource;
                    if (TryGetProcessor(this.messageSources, address, out messageSource))
                    {
                        messageSource.AddLink(listenerLink, address);
                        return(true);
                    }
                }

                RequestProcessor requestProcessor;
                if (TryGetProcessor(this.requestProcessors, address, out requestProcessor))
                {
                    requestProcessor.AddLink(listenerLink, address, attach);
                    return(true);
                }
            }

            if (this.linkProcessor != null)
            {
                this.linkProcessor.Process(new AttachContext(listenerLink, attach));
                return(false);
            }

            if (string.IsNullOrWhiteSpace(address))
            {
                throw new AmqpException(ErrorCode.InvalidField, "The address field cannot be empty.");
            }

            throw new AmqpException(ErrorCode.NotFound, "No processor was found at " + address);
        }
コード例 #9
0
 internal ListenerSession(ListenerConnection connection, Begin begin)
     : base(connection, begin)
 {
 }
コード例 #10
0
        async Task HandleTransportAsync(IAsyncTransport transport)
        {
            if (this.saslSettings != null)
            {
                ListenerSaslProfile profile = new ListenerSaslProfile(this);
                transport = await profile.OpenAsync(null, transport);
            }

            Connection connection = new ListenerConnection(this, this.address, transport);
            connection.Closed += this.OnConnectionClosed;
            lock (this.connections)
            {
                this.connections.Add(connection);
            }

            AsyncPump pump = new AsyncPump(transport);
            pump.Start(connection);
        }
コード例 #11
0
        async Task HandleTransportAsync(IAsyncTransport transport)
        {
            IPrincipal principal = null;
            if (this.saslSettings != null)
            {
                ListenerSaslProfile profile = new ListenerSaslProfile(this);
                transport = await profile.OpenAsync(null, this.BufferManager, transport);
                principal = profile.GetPrincipal();
            }

            var connection = new ListenerConnection(this, this.address, transport);
            if (principal == null)
            {
                // SASL principal preferred. If not present, check transport.
                IAuthenticated authenticated = transport as IAuthenticated;
                if (authenticated != null)
                {
                    principal = authenticated.Principal;
                }
            }

            connection.Principal = principal;

            bool shouldClose = false;
            lock (this.connections)
            {
                if (!this.closed)
                {
                    connection.Closed += this.OnConnectionClosed;
                    this.connections.Add(connection);
                }
                else
                {
                    shouldClose = true;
                }
            }

            if (shouldClose)
            {
                await connection.CloseAsync();
            }
            else
            {
                AsyncPump pump = new AsyncPump(this.BufferManager, transport);
                pump.Start(connection);
            }
        }
コード例 #12
0
        async Task HandleTransportAsync(IAsyncTransport transport)
        {
            if (this.saslSettings != null)
            {
                ListenerSaslProfile profile = new ListenerSaslProfile(this);
                transport = await profile.OpenAsync(null, transport);
            }

            Connection connection = new ListenerConnection(this, this.address, transport);
            bool shouldClose = false;
            lock (this.connections)
            {
                if (!this.closed)
                {
                    connection.Closed += this.OnConnectionClosed;
                    this.connections.Add(connection);
                }
                else
                {
                    shouldClose = true;
                }
            }

            if (shouldClose)
            {
                await connection.CloseAsync();
            }
            else
            {
                AsyncPump pump = new AsyncPump(transport);
                pump.Start(connection);
            }
        }
コード例 #13
0
 Link IContainer.CreateLink(ListenerConnection connection, ListenerSession session, Attach attach)
 {
     return(new ListenerLink(session, attach));
 }
コード例 #14
0
 internal ListenerSession(ListenerConnection connection, Begin begin)
     : base(connection, begin)
 {
 }