Build 1.0_r1(from source)

org.apache.http.conn
Class MultihomePlainSocketFactory

java.lang.Object
  extended by 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
 Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params)
          Attempts to connects the socket to any of the InetAddresses the given host name resolves to.
 Socket createSocket()
          Creates a new, unconnected socket.
 boolean equals(Object obj)
          Compares this factory with an object.
static MultihomePlainSocketFactory getSocketFactory()
          Gets the singleton instance of this class.
 int hashCode()
          Obtains a hash code for this object.
 boolean isSecure(Socket sock)
          Checks whether a socket connection is secure.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSocketFactory

public static MultihomePlainSocketFactory getSocketFactory()
Gets the singleton instance of this class.

Returns:
the one and only plain socket factory

createSocket

public Socket createSocket()
Description copied from interface: SocketFactory
Creates a new, unconnected socket. The socket should subsequently be passed to connectSocket.

Specified by:
createSocket in interface SocketFactory
Returns:
a new socket

connectSocket

public Socket connectSocket(Socket sock,
                            String host,
                            int port,
                            InetAddress localAddress,
                            int localPort,
                            HttpParams params)
                     throws IOException
Attempts to connects the socket to any of the InetAddresses the given host name resolves to. If connection to all addresses fail, the last I/O exception is propagated to the caller.

Specified by:
connectSocket in interface SocketFactory
Parameters:
sock - socket to connect to any of the given addresses
host - Host name to connect to
port - the port to connect to
localAddress - local address
localPort - local port
params - HTTP parameters
Returns:
the connected socket. The returned object may be different from the sock argument if this factory supports a layered protocol.
Throws:
IOException - if an error occurs during the connection
SocketTimeoutException - if timeout expires before connecting

isSecure

public final boolean isSecure(Socket sock)
                       throws IllegalArgumentException
Checks whether a socket connection is secure. This factory creates plain socket connections which are not considered secure.

Specified by:
isSecure in interface SocketFactory
Parameters:
sock - the connected socket
Returns:
false
Throws:
IllegalArgumentException - if the argument is invalid

equals

public boolean equals(Object obj)
Compares this factory with an object. There is only one instance of this class.

Overrides:
equals in class Object
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:
hashCode in class Object
Returns:
int the receiver's hash.
See Also:
Object.equals(java.lang.Object)

Build 1.0_r1(from source)

Please submit a feedback, bug or feature