org.apache.commons.httpclient.protocol

Class 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
Authors:
Ortwin Glueck
Oleg Kalnichevski
Since:
3.0

Nested Class Summary

static class
ControllerThreadSocketFactory.SocketTask
Helper class for wrapping socket based tasks.

Method Summary

static Socket
createSocket(ControllerThreadSocketFactory.SocketTask task, int timeout)
static Socket
createSocket(ProtocolSocketFactory socketfactory, String host, int port, InetAddress localAddress, int localPort, int timeout)
This method spawns a controller thread overseeing the process of socket initialisation.

Method Details

createSocket

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

createSocket

public static Socket createSocket(ProtocolSocketFactory socketfactory,
                                  String host,
                                  int port,
                                  InetAddress localAddress,
                                  int localPort,
                                  int timeout)
            throws IOException,
                   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:
ConnectTimeoutException - if socket cannot be connected within the given time limit

Copyright (c) 1999-2005 - Apache Software Foundation