ControllerThreadSocketFactory (HttpClient Library (Version 3.1))
Date: 2016-03-09

org.apache.commons.httpclient.protocol

## Class ControllerThreadSocketFactory

- java.lang.Object
- - org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory

-     public final class ControllerThreadSocketFactory
      extends java.lang.Object

  This helper class is intedned to help work around the limitation of older Java versions (older than 1.4) that prevents from specifying a connection timeout when creating a socket. This factory executes a controller thread overssing the process of socket initialisation. If the socket constructor cannot be created within the specified time limit, the controller terminates and throws an `ConnectTimeoutException`
  Since:
    3.0
  Author:
    Ortwin Glueck, Oleg Kalnichevski

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ControllerThreadSocketFactory.SocketTask` Helper class for wrapping socket based tasks.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.net.Socket` | `createSocket(ControllerThreadSocketFactory.SocketTask task, int timeout)`
    `static java.net.Socket` | `createSocket(ProtocolSocketFactory socketfactory, java.lang.String host, int port, java.net.InetAddress localAddress, int localPort, int timeout)` This method spawns a controller thread overseeing the process of socket initialisation.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### createSocket

          public static java.net.Socket createSocket(ProtocolSocketFactory socketfactory,
                                     java.lang.String host,
                                     int port,
                                     java.net.InetAddress localAddress,
                                     int localPort,
                                     int timeout)
                                              throws java.io.IOException,
                                                     java.net.UnknownHostException,
                                                     ConnectTimeoutException

      This method spawns a controller thread overseeing the process of socket initialisation. If the socket constructor cannot be created within the specified time limit, the controller terminates and throws an `ConnectTimeoutException`
      Parameters:
        `host` - the host name/IP
        `port` - the port on the host
        `localAddress` - the local host name/IP to bind the socket to
        `localPort` - the port on the local machine
        `timeout` - the timeout value to be used in milliseconds. If the socket cannot be completed within the given time limit, it will be abandoned
      Returns:
        a connected Socket
      Throws:
        `java.io.IOException` - if an I/O error occurs while creating the socket
        `java.net.UnknownHostException` - if the IP address of the host cannot be determined
        `ConnectTimeoutException` - if socket cannot be connected within the given time limit

    - #### createSocket

          public static java.net.Socket createSocket(ControllerThreadSocketFactory.SocketTask task,
                                     int timeout)
                                              throws java.io.IOException,
                                                     java.net.UnknownHostException,
                                                     ConnectTimeoutException

      Throws:
        `java.io.IOException`
        `java.net.UnknownHostException`
        `ConnectTimeoutException`

Copyright (c) 1999-2005 - Apache Software Foundation