Ejemplo n.º 1
0
        /// <summary>
        /// Get a service client from pool and make sure it is workable.
        /// </summary>
        /// <remarks>
        /// Notice: Call ReleaseProxyClient when you're done with ServiceClient.
        /// </remarks>
        /// <returns>service client</returns>
        public AzureServiceClient GetProxyClient()
        {
            while (true)
            {
                AzureServiceClient client = this.InternalGetProxyClient();

                if (client.ServiceClient.State == CommunicationState.Closed ||
                    client.ServiceClient.State == CommunicationState.Closing ||
                    client.ServiceClient.State == CommunicationState.Faulted)
                {
                    BrokerTracing.TraceVerbose(
                        "[ProxyClientPool].GetProxyClient: Client is not ready for use, remove it, {0}, {1}",
                        client,
                        client.ServiceClient.Endpoint.Address);

                    this.RemoveProxyClient(client);

                    if (client.ServiceClient.State == CommunicationState.Faulted)
                    {
                        client.AsyncClose();
                    }
                }
                else
                {
                    BrokerTracing.TraceVerbose(
                        "[ProxyClientPool].GetProxyClient: Get a client ready for use, {0}, {1}",
                        client,
                        client.ServiceClient.Endpoint.Address);

                    return(client);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle client failure
        /// </summary>
        /// <param name="client">targeted client</param>
        private static void HandleClientFailure(AzureServiceClient client)
        {
            try
            {
                BrokerTracing.TraceWarning(
                    "[AzureDispatcher] HandleClientFailure: Handle invalid client, {0}, {1}",
                    client,
                    client.ServiceClient.Endpoint.Address);

                Dictionary <EndpointAddress, ProxyClientPool> .ValueCollection pools;

                lock (LockProxyClientPoolDic)
                {
                    pools = ProxyClientPoolDic.Values;
                }

                foreach (var pool in pools)
                {
                    bool existInPool = false;

                    lock (pool)
                    {
                        BrokerTracing.TraceVerbose(
                            "[AzureDispatcher] HandleClientFailure: Remove client {0} from pool.", client);

                        existInPool = pool.RemoveProxyClient(client);
                    }

                    if (existInPool)
                    {
                        BrokerTracing.TraceVerbose(
                            "[AzureDispatcher] HandleClientFailure: Close client {0}", client);

                        // Close the proxy client if any exception is encountered.
                        // As a result, async pending callback on clients will be
                        // invoked (with exception).
                        client.AsyncClose();

                        return;
                    }
                }
            }
            catch (Exception e)
            {
                BrokerTracing.TraceError(
                    "[AzureDispatcher] HandleClientFailure: Error occurs, {0}", e);
            }
        }