arturobernalg commented on code in PR #430:
URL: 
https://github.com/apache/httpcomponents-client/pull/430#discussion_r1160748793


##########
httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/FailoverProxySelector.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.client5.http.impl.routing;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.SocketAddress;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * A ProxySelector implementation that selects proxies using a failover 
strategy.
+ * <p>
+ * This implementation maintains a list of other ProxySelectors, and selects a 
proxy
+ * by delegating to the next available ProxySelector in the list, until a 
non-empty
+ * proxy list is returned. If a ProxySelector fails with an exception, the next
+ * ProxySelector in the list is tried. Once a non-empty proxy list is returned 
by
+ * a ProxySelector, it becomes the active ProxySelector and is used for 
subsequent
+ * calls to select(). If a connection fails, connectFailed() is called on the
+ * active ProxySelector.
+ * <p>
+ * This implementation is useful in environments where multiple proxy servers 
may be
+ * used, and where it is desirable to failover to a different proxy if the 
current
+ * one fails.
+ *
+ * @since 5.3
+ */
+public class FailoverProxySelector extends ProxySelector {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(FailoverProxySelector.class);
+
+    private final List<ProxySelector> selectors;
+    private final AtomicInteger currentIndex;
+
+
+    /**
+     * Constructs a FailoverProxySelector from the given list of 
ProxySelectors.
+     *
+     * @param selectors the list of ProxySelectors to use.
+     * @throws IllegalArgumentException if the list is null or empty.
+     */
+    public FailoverProxySelector(final List<ProxySelector> selectors) {
+        if (selectors == null || selectors.isEmpty()) {
+            throw new IllegalArgumentException("At least one ProxySelector is 
required");
+        }
+        this.selectors = new ArrayList<>(selectors);
+        currentIndex = new AtomicInteger(0);
+
+    }
+
+    /**
+     * Selects a list of proxies for the given URI by delegating to the next
+     * available ProxySelector in the list, until a non-empty proxy list is
+     * returned. Once a non-empty proxy list is returned, it becomes the active
+     * ProxySelector and is used for subsequent calls to select().
+     *
+     * @param uri the URI to select a proxy for.
+     * @return a list of proxies for the given URI.
+     */
+    @Override
+    public List<Proxy> select(final URI uri) {

Review Comment:
   Is to select a list of proxies for the given URI by delegating to the next 
available ProxySelector in the list, until a non-empty proxy list is returned. 
It does not necessarily pick a backup selector in case the primary selector 
fails to produce a result, but rather rotates through the list of selectors 
until a non-empty proxy list is obtained



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to