public Endpoint GetNextEndpoint()

in RESTProxy/Models/TenantEndpointCollection.cs [106:141]


        public Endpoint GetNextEndpoint(EndpointType endpointType)
        {
            try
            {
                this.semaphore.Wait();

                List<Endpoint> endpoints;
                if (this.EndpointsByType.TryGetValue(endpointType, out endpoints))
                {
                    int nextIndex = this.NextEndpointIndex[endpointType];
                    Endpoint endpoint = endpoints[nextIndex];

                    // Careful not to do a post-increment here, as the increment would happen _after_ the assignment.
                    // A pre-increment would work, but I'd argue that expliclty adding 1 here is more clear.
                    this.NextEndpointIndex[endpointType] = nextIndex + 1;
                    if (this.NextEndpointIndex[endpointType] >= endpoints.Count)
                    {
                        this.NextEndpointIndex[endpointType] = 0;
                    }

                    return endpoint;
                }
                else
                {
                    throw new KeyNotFoundException(string.Format(
                        "This Proxy is not configured to handle requests for Tenant [{0} ({1})] with the endpoint type of [{2}].",
                        this.TenantId,
                        this.TenantFriendlyName,
                        endpointType.ToString()));
                }
            }
            finally
            {
                this.semaphore.Release();
            }
        }