public IFrameHandler CreateFrameHandler()
        {
            IProtocol p = Protocols.DefaultProtocol;

            return(p.CreateFrameHandler(Endpoint,
                                        SocketFactory,
                                        RequestedConnectionTimeout));
        }
Пример #2
0
        protected virtual IConnection FollowRedirectChain
            (int maxRedirects,
            IDictionary connectionAttempts,
            IDictionary connectionErrors,
            ref AmqpTcpEndpoint[] mostRecentKnownHosts,
            AmqpTcpEndpoint endpoint)
        {
            AmqpTcpEndpoint candidate = endpoint;

            try {
                while (true)
                {
                    int attemptCount =
                        connectionAttempts.Contains(candidate)
                        ? (int)connectionAttempts[candidate]
                        : 0;
                    connectionAttempts[candidate] = attemptCount + 1;
                    bool insist = attemptCount >= maxRedirects;

                    try {
                        IProtocol     p  = candidate.Protocol;
                        IFrameHandler fh = p.CreateFrameHandler(candidate);
                        // At this point, we may be able to create
                        // and fully open a successful connection,
                        // in which case we're done, and the
                        // connection should be returned.
                        return(p.CreateConnection(m_parameters, insist, fh));
                    } catch (RedirectException re) {
                        if (insist)
                        {
                            // We've been redirected, but we insisted that
                            // we shouldn't be redirected! Well-behaved
                            // brokers should never do this.
                            string message = string.Format("Server {0} ignored 'insist' flag, redirecting us to {1}",
                                                           candidate,
                                                           re.Host);
                            throw new ProtocolViolationException(message);
                        }
                        else
                        {
                            // We've been redirected. Follow this new link
                            // in the chain, by setting
                            // mostRecentKnownHosts (in case the chain
                            // runs out), and updating candidate for the
                            // next time round the loop.
                            connectionErrors[candidate] = re;
                            mostRecentKnownHosts        = re.KnownHosts;
                            candidate = re.Host;
                        }
                    }
                }
            } catch (Exception e) {
                connectionErrors[candidate] = e;
                return(null);
            }
        }