ProxySelector implementation that
delegates proxy selection to a list of underlying ProxySelectors in a
distributed manner. It ensures that proxy selection is load-balanced
across the available ProxySelectors, and provides thread safety by
maintaining separate states for each thread.
The DistributedProxySelector class maintains a list of ProxySelectors,
a ThreadLocal variable for the current ProxySelector, and an AtomicInteger
to keep track of the shared index across all threads. When the select()
method is called, it delegates the proxy selection to the current
ProxySelector or the next available one in the list if the current one
returns an empty proxy list. Any exceptions that occur during proxy
selection are caught and ignored, and the next ProxySelector is tried.
The connectFailed() method notifies the active ProxySelector of a
connection failure, allowing the underlying ProxySelector to handle
connection failures according to its own logic.
| Modifier and Type | Field and Description |
|---|---|
| private final ThreadLocal | currentSelector
A |
| private static final Logger | |
| private final List | selectors
A list of |
| private final AtomicInteger | sharedIndex
An |
| Access | Constructor and Description |
|---|---|
| public | DistributedProxySelector(final List<ProxySelector>
the list of ProxySelectors to use. selectors)Constructs a DistributedProxySelector with the given list of |
| Modifier and Type | Method and Description |
|---|---|
| public void | connectFailed(final URI
the uri, final SocketAddress URI that failed to connect.the sa, final IOException SocketAddress of the proxy that failed to connect.the ioe)IOException that resulted from the failed connection.Implements abstract java. ProxySelector of a connection failure.
|
| private ProxySelector | Returns: the nextProxySelector in the list.Retrieves the next available |
| public List | Returns: a list of proxies for the givenURI.the uri)URI to select a proxy for.Implements abstract java. URI by delegating to the current
ProxySelector or the next available ProxySelector in the list if the current
one returns an empty proxy list.
|
| currentSelector | back to summary |
|---|---|
| private final ThreadLocal<ProxySelector> currentSelector A | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| selectors | back to summary |
|---|---|
| private final List<ProxySelector> selectors A list of | |
| sharedIndex | back to summary |
|---|---|
| private final AtomicInteger sharedIndex An | |
| DistributedProxySelector | back to summary |
|---|---|
| public DistributedProxySelector(final List<ProxySelector> selectors) Constructs a DistributedProxySelector with the given list of
| |
| connectFailed | back to summary |
|---|---|
| public void connectFailed(final URI uri, final SocketAddress sa, final IOException ioe) Implements abstract java. Notifies the active
| |
| nextSelector | back to summary |
|---|---|
| private ProxySelector nextSelector() Retrieves the next available
| |
| select | back to summary |
|---|---|
| public List Implements abstract java. Selects a list of proxies for the given | |