Package org.apache.http.conn
Class MultihomePlainSocketFactory
java.lang.Object
org.apache.http.conn.MultihomePlainSocketFactory
- All Implemented Interfaces:
SocketFactory
public final class MultihomePlainSocketFactory extends Object implements SocketFactory
Socket factory that implements a simple multi-home fail-over on connect failure,
provided the same hostname resolves to multiple
InetAddresses. Please note
the connectSocket(Socket, String, int, InetAddress, int, HttpParams)
method cannot be reliably interrupted by closing the socket returned by the
createSocket() method.-
Method Summary
Modifier and Type Method Description SocketconnectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params)Attempts to connects the socket to any of theInetAddresses the given host name resolves to.SocketcreateSocket()Creates a new, unconnected socket.booleanequals(Object obj)Compares this factory with an object.static MultihomePlainSocketFactorygetSocketFactory()Gets the singleton instance of this class.inthashCode()Obtains a hash code for this object.booleanisSecure(Socket sock)Checks whether a socket connection is secure.
-
Method Details
-
getSocketFactory
Gets the singleton instance of this class.- Returns:
- the one and only plain socket factory
-
createSocket
Description copied from interface:SocketFactoryCreates a new, unconnected socket. The socket should subsequently be passed toconnectSocket.- Specified by:
createSocketin interfaceSocketFactory- Returns:
- a new socket
-
connectSocket
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOExceptionAttempts to connects the socket to any of theInetAddresses the given host name resolves to. If connection to all addresses fail, the last I/O exception is propagated to the caller.- Specified by:
connectSocketin interfaceSocketFactory- Parameters:
sock- socket to connect to any of the given addresseshost- Host name to connect toport- the port to connect tolocalAddress- local addresslocalPort- local portparams- HTTP parameters- Returns:
- the connected socket. The returned object may be different
from the
sockargument if this factory supports a layered protocol. - Throws:
IOException- if an error occurs during the connectionSocketTimeoutException- if timeout expires before connecting
-
isSecure
Checks whether a socket connection is secure. This factory creates plain socket connections which are not considered secure.- Specified by:
isSecurein interfaceSocketFactory- Parameters:
sock- the connected socket- Returns:
false- Throws:
IllegalArgumentException- if the argument is invalid
-
equals
Compares this factory with an object. There is only one instance of this class.- Overrides:
equalsin classObject- Parameters:
obj- the object to compare with- Returns:
- iff the argument is this object
- See Also:
Object.hashCode()
-
hashCode
public int hashCode()Obtains a hash code for this object. All instances of this class have the same hash code. There is only one instance of this class.- Overrides:
hashCodein classObject- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-