## org.mortbay.jetty.client
Class HttpClient

    java.lang.Object
      org.mortbay.component.AbstractLifeCycle
          org.mortbay.jetty.AbstractBuffers
              org.mortbay.jetty.client.HttpClient

All Implemented Interfaces:
  LifeCycle, Buffers

    public class HttpClient

extends AbstractBuffers

Http Client. HttpClient is the main active component of the client API implementation. It is the opposite of the Connectors in standard Jetty, in that it listens for responses rather than requests. Just like the connectors, there is a blocking socket version and a non-blocking NIO version (implemented as nested classes selected by `setConnectorType(int)`). The an instance of `HttpExchange` is passed to the `send(HttpExchange)` method to send a request. The exchange contains both the headers and content (source) of the request plus the callbacks to handle responses. A HttpClient can have many exchanges outstanding and they may be queued on the `HttpDestination` waiting for a `HttpConnection`, queued in the `HttpConnection` waiting to be transmitted or pipelined on the actual TCP/IP connection waiting for a response. The `HttpDestination` class is an aggregation of `HttpConnection`s for the same host, port and protocol. A destination may limit the number of connections open and they provide a pool of open connections that may be reused. Connections may also be allocated from a destination, so that multiple request sources are not multiplexed over the same connection.

Author:
  Greg Wilkins, Matthew Purland, Guillaume Nodet
See Also:
  `HttpExchange}`, `HttpDestination}`

Field Summary
`static int` `CONNECTOR_SELECT_CHANNEL`
`static int` `CONNECTOR_SOCKET`

Fields inherited from class org.mortbay.jetty.AbstractBuffers
`_loss, BUFFER_LOSS_RATE`

Constructor Summary
`HttpClient()`

Method Summary
`void` `cancel(Timeout.Task task)`
`protected void` `doStart()`
`protected void` `doStop()`
`int` `getConnectorType()` Get the type of connector (socket, blocking or select) in use.
`HttpDestination` `getDestination(InetSocketAddress remote, boolean ssl)`
`long` `getIdleTimeout()`
`int` `getMaxConnectionsPerAddress()`
`int` `getSoTimeout()`
`ThreadPool` `getThreadPool()`
`long` `getTimeout()`
`boolean` `getUseDirectBuffers()` Get whether the connector can use direct NIO buffers.
`protected Buffer` `newBuffer(int size)` Create a new NIO buffer.
`void` `schedule(Timeout.Task task)`
`void` `send(HttpExchange exchange)`
`void` `setConnectorType(int connectorType)`
`void` `setIdleTimeout(long ms)`
`void` `setMaxConnectionsPerAddress(int maxConnectionsPerAddress)`
`void` `setSoTimeout(int so)`
`void` `setThreadPool(ThreadPool threadPool)`
`void` `setTimeout(long ms)`
`void` `setUseDirectBuffers(boolean direct)` Set to use NIO direct buffers.

Methods inherited from class org.mortbay.jetty.AbstractBuffers
`getBuffer, getHeaderBufferSize, getRequestBufferSize, getResponseBufferSize, returnBuffer, setHeaderBufferSize, setRequestBufferSize, setResponseBufferSize`

Methods inherited from class org.mortbay.component.AbstractLifeCycle
`isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, start, stop`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### CONNECTOR_SOCKET

    public static final int CONNECTOR_SOCKET

See Also:
  Constant Field Values

### CONNECTOR_SELECT_CHANNEL

    public static final int CONNECTOR_SELECT_CHANNEL

See Also:
  Constant Field Values

Constructor Detail

### HttpClient

    public HttpClient()

Method Detail

### send

    public void send(HttpExchange exchange)
              throws IOException

  Throws:
    `IOException`

### getThreadPool

    public ThreadPool getThreadPool()

  Returns:
    the threadPool

### setThreadPool

    public void setThreadPool(ThreadPool threadPool)

  Parameters:
    `threadPool` - the threadPool to set

### getDestination

    public HttpDestination getDestination(InetSocketAddress remote,
                                          boolean ssl)
                                   throws UnknownHostException,
                                          IOException

  Throws:
    `UnknownHostException`
    `IOException`

### schedule

    public void schedule(Timeout.Task task)

### cancel

    public void cancel(Timeout.Task task)

### getUseDirectBuffers

    public boolean getUseDirectBuffers()

  Get whether the connector can use direct NIO buffers.

### setUseDirectBuffers

    public void setUseDirectBuffers(boolean direct)

  Set to use NIO direct buffers.

  Parameters:
    `direct` - If True (the default), the connector can use NIO direct buffers. Some JVMs have memory management issues (bugs) with direct buffers.

### getConnectorType

    public int getConnectorType()

  Get the type of connector (socket, blocking or select) in use.

### setConnectorType

    public void setConnectorType(int connectorType)

### newBuffer

    protected Buffer newBuffer(int size)

  Create a new NIO buffer. If using direct buffers, it will create a direct NIO buffer, other than an indirect buffer.

  Specified by:
    `newBuffer` in class `AbstractBuffers`

### getMaxConnectionsPerAddress

    public int getMaxConnectionsPerAddress()

### setMaxConnectionsPerAddress

    public void setMaxConnectionsPerAddress(int maxConnectionsPerAddress)

### doStart

    protected void doStart()
                    throws Exception

  Overrides:
    `doStart` in class `AbstractBuffers`
  Throws:
    `Exception`

### doStop

    protected void doStop()
                   throws Exception

  Overrides:
    `doStop` in class `AbstractLifeCycle`
  Throws:
    `Exception`

### getIdleTimeout

    public long getIdleTimeout()

  Returns:
    the period in milliseconds a `HttpConnection` can be idle for before it is closed.

### setIdleTimeout

    public void setIdleTimeout(long ms)

  Parameters:
    `ms` - the period in milliseconds a `HttpConnection` can be idle for before it is closed.

### getSoTimeout

    public int getSoTimeout()

### setSoTimeout

    public void setSoTimeout(int so)

### getTimeout

    public long getTimeout()

  Returns:
    the period in ms that an exchange will wait for a response from the server.

### setTimeout

    public void setTimeout(long ms)

  Parameters:
    `ms` - the period in ms that an exchange will wait for a response from the server.

Copyright © 2008 Mort Bay Consulting. All Rights Reserved.