# ProxySelector

public abstract class **ProxySelector** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
Selects the proxy server to use, if any, when connecting to the
network resource referenced by a URL. A proxy selector is a
concrete sub-class of this class and is registered by invoking the
`https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#setDefault(java.net.ProxySelector)` method. The
currently registered proxy selector can be retrieved by calling
`https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#getDefault()` method.

When a proxy selector is registered, for instance, a subclass
of URLConnection class should call the `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#select(java.net.URI)`
method for each URL request so that the proxy selector can decide
if a direct, or proxied connection should be used. The `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#select(java.net.URI)` method returns an iterator over a collection with
the preferred connection approach.

If a connection cannot be established to a proxy (PROXY or
SOCKS) servers then the caller should call the proxy selector's
`https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#connectFailed(java.net.URI,%20java.net.SocketAddress,%20java.io.IOException)` method to notify the proxy
selector that the proxy server is unavailable.

The default proxy selector does enforce a
[set of System Properties](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/doc-files/net-properties#Proxies)
related to proxy settings.

<br />

### Public Constructor Summary

|---|---|
|   | [ProxySelector](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#ProxySelector())() |

### Public Method Summary

|---|---|
| abstract void | [connectFailed](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#connectFailed(java.net.URI,%20java.net.SocketAddress,%20java.io.IOException))([URI](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URI.html) uri, [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) sa, [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) ioe) Called to indicate that a connection could not be established to a proxy/socks server. |
| static [ProxySelector](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html) | [getDefault](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#getDefault())() Gets the system-wide proxy selector. |
| abstract [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[Proxy](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Proxy.html)\> | [select](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#select(java.net.URI))([URI](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URI.html) uri) Selects all the applicable proxies based on the protocol to access the resource with and a destination address to access the resource at. |
| static void | [setDefault](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#setDefault(java.net.ProxySelector))([ProxySelector](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html) ps) Sets (or unsets) the system-wide proxy selector. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Constructors

#### public
**ProxySelector**
()

<br />

## Public Methods

#### public abstract void
**connectFailed**
([URI](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URI.html) uri, [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) sa, [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) ioe)

Called to indicate that a connection could not be established
to a proxy/socks server. An implementation of this method can
temporarily remove the proxies or reorder the sequence of
proxies returned by `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#select(java.net.URI)`, using the address
and the IOException caught when trying to connect.

##### Parameters

| uri | The URI that the proxy at sa failed to serve. |
| sa | The socket address of the proxy/SOCKS server |
| ioe | The I/O exception thrown when the connect failed. |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if either argument is null |
|---|---|

#### public static [ProxySelector](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html)
**getDefault**
()

Gets the system-wide proxy selector.

##### Returns

- the system-wide `ProxySelector`

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and it denies `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetPermission.html``("getProxySelector")` |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#setDefault(java.net.ProxySelector)`

#### public abstract [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[Proxy](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Proxy.html)\>
**select**
([URI](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URI.html) uri)

Selects all the applicable proxies based on the protocol to
access the resource with and a destination address to access
the resource at.
The format of the URI is defined as follow:

- http URI for http connections
- https URI for https connections
- `socket://host:port`  
  for tcp client sockets connections

<br />

##### Parameters

| uri | The URI that a connection is required to |
|---|---|

##### Returns

- a List of Proxies. Each element in the the List is of type `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Proxy.html`; when no proxy is available, the list will contain one element of type `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Proxy.html` that represents a direct connection.

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the argument is null |
|---|---|

#### public static void
**setDefault**
([ProxySelector](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html) ps)

Sets (or unsets) the system-wide proxy selector.

Note: non-standard protocol handlers may ignore this setting.

##### Parameters

| ps | The HTTP proxy selector, or `null` to unset the proxy selector. |
|---|---|

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and it denies `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetPermission.html``("setProxySelector")` |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ProxySelector.html#getDefault()`