sunlabs.brazil.util.http
Class HttpRequest.SimpleHttpSocketPool

java.lang.Object
  extended by sunlabs.brazil.util.http.HttpRequest.SimpleHttpSocketPool
All Implemented Interfaces:
Runnable, HttpRequest.HttpSocketPool
Enclosing class:
HttpRequest

public static class HttpRequest.SimpleHttpSocketPool
extends Object
implements Runnable, HttpRequest.HttpSocketPool


Field Summary
 int maxAge
           
 int maxIdle
           
 int reapInterval
           
 
Constructor Summary
HttpRequest.SimpleHttpSocketPool()
          Use the default pool settings
HttpRequest.SimpleHttpSocketPool(int maxIdle, int maxAge, int reapInterval)
          Create a socket pool.
 
Method Summary
 void close(HttpRequest.HttpSocket hs, boolean reuse)
          Releases an HttpSocket to this pool when it is not in use any more.
 HttpRequest.HttpSocket get(String host, int port, boolean reuse)
          Get a potentially "pooled" target object.
 int getDefaultPort()
          Return the default port (this doesn't belong here)
 boolean isMine(URL url)
          Return true if this is one of the url's my pool can handle
 void run()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

maxIdle

public int maxIdle

maxAge

public int maxAge

reapInterval

public int reapInterval
Constructor Detail

HttpRequest.SimpleHttpSocketPool

public HttpRequest.SimpleHttpSocketPool(int maxIdle,
                                        int maxAge,
                                        int reapInterval)
Create a socket pool. A socket pool is responsible for providing the underlying "socket" like transport for the http protocol, and managing the lifetimes of the connections.

Parameters:
maxIdle - (ms) Max number of idle connections
maxAge - (ms) Max idle time for a connection
reapInterval - (ms) How often to check for expired sockets

HttpRequest.SimpleHttpSocketPool

public HttpRequest.SimpleHttpSocketPool()
Use the default pool settings

Method Detail

isMine

public boolean isMine(URL url)
Description copied from interface: HttpRequest.HttpSocketPool
Return true if this is one of the url's my pool can handle

Specified by:
isMine in interface HttpRequest.HttpSocketPool

getDefaultPort

public int getDefaultPort()
Description copied from interface: HttpRequest.HttpSocketPool
Return the default port (this doesn't belong here)

Specified by:
getDefaultPort in interface HttpRequest.HttpSocketPool

get

public HttpRequest.HttpSocket get(String host,
                                  int port,
                                  boolean reuse)
                           throws IOException,
                                  UnknownHostException
Get a potentially "pooled" target object. Call this instead of the constructor to use the pool.

Specified by:
get in interface HttpRequest.HttpSocketPool
Parameters:
host - the target content server (or web proxy)
port - target web server port
reuse - true to request that this pool attempt to find and reuse an existing idle connection, false to request that this pool establish a new connection to the named host.
Returns:
The HttpSocket.
Throws:
IOException - if there is a problem connecting the specified port on the named host. The IOExceptions (and subclasses) that might be thrown depend upon how the socket connection is established. See the socket documentation for further details. Some subclasses that might be thrown are as follows:
InterruptedIOException - if the connection times out or this thread is interrupted by Thread.interrupt.
UnknownHostException

close

public void close(HttpRequest.HttpSocket hs,
                  boolean reuse)
Description copied from interface: HttpRequest.HttpSocketPool
Releases an HttpSocket to this pool when it is not in use any more.

It is this method's responsibility to release resources used by the HttpSocket, e.g. closing the underlying socket.

After calling this method, the user should not refer to the specified HttpSocket any more.

Specified by:
close in interface HttpRequest.HttpSocketPool
Parameters:
hs - The HttpSocket to release.
reuse - true: the specified HttpSocket should be put back into the idle pool, false if it should be released immediately.

run

public void run()
Specified by:
run in interface Runnable

toString

public String toString()
Overrides:
toString in class Object

Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.