    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class org.w3c.www.protocol.http.HttpManager

    java.lang.Object
       |
       +----org.w3c.www.protocol.http.HttpManager

public class HttpManager
extends Object
implements PropertyMonitoring

The client side HTTP request manager. This class is the user interface (along with the other public classes of this package) for the W3C client side library implementing HTTP. A typicall request is launched though the following sequence:

     HttpManager     manager = HttpManager.getManager() ;
     Request request = manager.createRequest() ;
     request.setMethod(HTTP.GET) ;
     request.setURL(new URL("http://www.w3.org/pub/WWW/"));
     Reply    reply = manager.runRequest(request) ;
     // Get the reply input stream that contains the actual data:
     InputStream in = reply.getInputStream() ;
     ...

##

ACCEPT_ENCODING_P
  Header properties - Set the accept encodings.
ACCEPT_LANGUAGE_P
  Header properties - Set the accept language.
ACCEPT_P
  Header properties - Set the accept header.
conn_count
conn_max
CONN_MAX_P
  The maximum number of simultaneous connectionlrus.
connectionsLru
  The LRU list of connections.
DEFAULT_ACCEPT
  The default value for the `Accept` header.
DEFAULT_USER_AGENT
  The default value for the `User-Agent` header.
FILTERS_PROP_P
  The name of the property containing the ProprequestFilter to launch.
MAX_STALE_P
  Header properties - The allowed drift for getting cached resources.
MIN_FRESH_P
  Header properties - The minium freshness required on cached resources.
ONLY_IF_CACHED_P
  Header properties - Set the only if cached flag on requests.
PROXY_HOST_P
  Header properties - What is the proxy host name.
PROXY_PORT_P
  Header properties - What is the proxy port number.
PROXY_SET_P
  Header properties - Should we use a proxy ?
SERVER_CLASS_P
  The name of the property indicating the class of HttpServer to use.
serverclass
  The class to instantiate to create new HttpServer instances.
servers
  The server this manager knows about, indexed by FQDN of target servers.
template
  The template request (the request we will clone to create new requests)
timeout
TIMEOUT_P
  The SO_TIMEOUT of the client socket.
USER_AGENT_P
  Header properties - Set the user agent.

##

HttpManager()
  Create a new HttpManager.

##

closeAnyConnection()
  Close some connections, but pickling the least recently used ones.
createRequest()
  Create a new default outgoing request.
decrConnCount(HttpServer)
  Decrement the number of established connections.
deleteConnection(HttpConnection)
  The given connection has been deleted.
getConnection(HttpServer)
  Try reusing one of the idle connection of that server, if any.
getGlobalFilter(Class)
  Find back an instance of a global filter.
getGlobalHeader(String)
  Global settings - Get a global request header default value.
getManager()
getManager(Properties)
  Get an instance of the HTTP manager.
getProperties()
  Get this manager properties.
getReplyFactory()
getServerKey(Request)
  Get the String key for the server instance handling that request.
incrConnCount(HttpServer)
  A new client connection has been established.
lookupServer(String, int)
  Get the appropriate server object for handling request to given target.
main(String[])
  DEBUGGING !
negotiateConnection(HttpServer)
  One of our server handler wants to open a connection.
notifyConnection(HttpConnection)
  The given connection has just been created.
notifyIdle(HttpConnection)
  The given connection can be reused, but is now idle.
notifyUse(HttpConnection)
  The given connection is about to be used.
propertyChanged(String)
  PropertyMonitoring implementation - Update properties on the fly !
runRequest(Request)
  Run the given request, in synchronous mode.
setAllowUserInteraction(boolean)
  Allow the manager to interact with the user if needed.
setFilter(RequestFilter)
  Add a global filter.
setFilter(URL[], URL[], RequestFilter)
  Add a new request filter.
setGlobalHeader(String, String)
  Global settings - Define a global request header.
setMaxConnections(int)
  Global settings - Set the max number of allowed connections.
setProxy(URL)
  Global settings - Set an optional proxy to use.
setRequestTimeout(int)
  Global settings - Set the request timeout.
setTimeout(int)
  Global settings - Set the timeout on the socket

  This value defaults to the value of the `org.w3c.www.http.Timeout` property.

sync()
  Dump all in-memory cached state to persistent storage.
tooManyConnections()
updateProxy()
  Update the proxy configuration to match current properties setting.
usingProxy()
  Does this manager uses a proxy to fulfill requests ?
waitForConnection(HttpServer)
  Wait for a connection to come up.

##

SERVER_CLASS_P

     public static final String SERVER_CLASS_P

  The name of the property indicating the class of HttpServer to use.

FILTERS_PROP_P

     public static final String FILTERS_PROP_P

  The name of the property containing the ProprequestFilter to launch.

CONN_MAX_P

     public static final String CONN_MAX_P

  The maximum number of simultaneous connectionlrus.

TIMEOUT_P

     public static final String TIMEOUT_P

  The SO_TIMEOUT of the client socket.

MAX_STALE_P

     public static final String MAX_STALE_P

  Header properties - The allowed drift for getting cached resources.

MIN_FRESH_P

     public static final String MIN_FRESH_P

  Header properties - The minium freshness required on cached resources.

ONLY_IF_CACHED_P

     public static final String ONLY_IF_CACHED_P

  Header properties - Set the only if cached flag on requests.

USER_AGENT_P

     public static final String USER_AGENT_P

  Header properties - Set the user agent.

ACCEPT_P

     public static final String ACCEPT_P

  Header properties - Set the accept header.

ACCEPT_LANGUAGE_P

     public static final String ACCEPT_LANGUAGE_P

  Header properties - Set the accept language.

ACCEPT_ENCODING_P

     public static final String ACCEPT_ENCODING_P

  Header properties - Set the accept encodings.

PROXY_SET_P

     public static final String PROXY_SET_P

  Header properties - Should we use a proxy ?

PROXY_HOST_P

     public static final String PROXY_HOST_P

  Header properties - What is the proxy host name.

PROXY_PORT_P

     public static final String PROXY_PORT_P

  Header properties - What is the proxy port number.

DEFAULT_ACCEPT

     public static final String DEFAULT_ACCEPT

  The default value for the `Accept` header.

DEFAULT_USER_AGENT

     public static final String DEFAULT_USER_AGENT

  The default value for the `User-Agent` header.

serverclass

     protected Class serverclass

  The class to instantiate to create new HttpServer instances.

servers

     protected Hashtable servers

  The server this manager knows about, indexed by FQDN of target servers.

template

     protected Request template

  The template request (the request we will clone to create new requests)

connectionsLru

     protected LRUList connectionsLru

  The LRU list of connections.

timeout

     protected int timeout

conn_count

     protected int conn_count

conn_max

     protected int conn_max

##

HttpManager

     protected HttpManager()

  Create a new HttpManager. FIXME Making this method protected breaks the static method to create HttpManager instances (should use a factory here)

  Parameters:
    props - The properties from which the manager should initialize itself, or null if none are available.

##

updateProxy

     protected boolean updateProxy()

  Update the proxy configuration to match current properties setting.

  Returns:
    A boolean, true if change was done, false otherwise.

getProperties

     public final ObservableProperties getProperties()

  Get this manager properties.

  Returns:
    An ObservableProperties instance.

propertyChanged

     public boolean propertyChanged(String name)

  PropertyMonitoring implementation - Update properties on the fly !

  Parameters:
    name - The name of the property that has changed.
  Returns:
    A boolean, true if change is accepted, false otherwise.

setAllowUserInteraction

     public void setAllowUserInteraction(boolean onoff)

  Allow the manager to interact with the user if needed. This will, for example, allow prompting for paswords, etc.

  Parameters:
    onoff - Turn interaction on or off.

getManager

     public static synchronized HttpManager getManager(Properties p)

  Get an instance of the HTTP manager. This method returns an actual instance of the HTTP manager. It may return different managers, if it decides to distribute the load on different managers (avoid the HttpManager being a bottleneck).

  Returns:
    An application wide instance of the HTTP manager.

getManager

     public static HttpManager getManager()

getServerKey

     public final String getServerKey(Request request)

  Get the String key for the server instance handling that request. This method takes care of any proxy setting (it will return the key to the proxy when required.)

  Returns:
    A uniq identifier for the handling server, as a String.

lookupServer

     protected synchronized HttpServer lookupServer(String host,
                                                    int port) throws HttpException

  Get the appropriate server object for handling request to given target.

  Parameters:
    key - The server's key, as returned by `getServerKey`.
  Returns:
    An object complying to the HttpServer interface.
  Throws: HttpException
    If the given host name couldn't be resolved.

notifyUse

     public void notifyUse(HttpConnection conn)

  The given connection is about to be used. Update our list of available servers.

  Parameters:
    conn - The idle connection.

notifyIdle

     public synchronized void notifyIdle(HttpConnection conn)

  The given connection can be reused, but is now idle.

  Parameters:
    conn - The connection that is now idle.

notifyConnection

     protected synchronized void notifyConnection(HttpConnection conn)

  The given connection has just been created.

  Parameters:
    conn - The newly created connection.

deleteConnection

     protected void deleteConnection(HttpConnection conn)

  The given connection has been deleted.

  Parameters:
    conn - The deleted connection.

tooManyConnections

     protected synchronized boolean tooManyConnections()

getConnection

     protected HttpConnection getConnection(HttpServer server)

  Try reusing one of the idle connection of that server, if any.

  Parameters:
    server - The target server.
  Returns:
    An currently idle connection to the given server.

waitForConnection

     protected synchronized void waitForConnection(HttpServer server) throws InterruptedException

  Wait for a connection to come up.

  Parameters:
    server, - the target server.
  Throws: InterruptedException
    If interrupted..

closeAnyConnection

     protected boolean closeAnyConnection()

  Close some connections, but pickling the least recently used ones. One third of the max number of connection is cut. This is done to eliminate the old connections that should be broken already. (no Socket.isAlive());

  Returns:
    A boolean, true if a connection was closed false otherwise.

negotiateConnection

     protected boolean negotiateConnection(HttpServer server)

  One of our server handler wants to open a connection.

  Parameters:
    block - A boolean indicating whether we should block the calling thread until a token is available (otherwise, the method will just peek at the connection count, and return the appropriate result).
  Returns:
    A boolean, true if the connection can be opened straight, false otherwise.

incrConnCount

     protected final synchronized void incrConnCount(HttpServer server)

  A new client connection has been established. This method will try to maintain a maximum number of established connections, by closing idle connections when possible.

  Parameters:
    server - The server that has established a new connection.

decrConnCount

     protected final synchronized void decrConnCount(HttpServer server)

  Decrement the number of established connections.

  Parameters:
    server - The server that has closed one connection to its target.

runRequest

     public Reply runRequest(Request request) throws HttpException

  Run the given request, in synchronous mode. This method will launch the given request, and block the calling thread until the response headers are available.

  Parameters:
    request - The request to run.
  Returns:
    An instance of Reply, containing all the reply informations.
  Throws: HttpException
    If something failed during request processing.

getReplyFactory

     public MimeParserFactory getReplyFactory()

setFilter

     public void setFilter(URL incs[],
                           URL exs[],
                           RequestFilter filter)

  Add a new request filter. Request filters are called before a request is launched, and after the reply headers are available. They allow applications to setup specific request headers (such as PICS, or PEP stuff) on the way in, and check the reply on the way out.

  Request filters are application wide: if their scope matches the current request, then they will always be aplied.

  Filter scopes are defined inclusively and exclusively

  Parameters:
    incs - The URL domains for which the filter should be triggered.
    exs - The URL domains for which the filter should not be triggered.
    filter - The request filter to add.

setFilter

     public void setFilter(RequestFilter filter)

  Add a global filter. The given filter will always be invoked.

  Parameters:
    filter - The filter to install.

getGlobalFilter

     public RequestFilter getGlobalFilter(Class cls)

  Find back an instance of a global filter. This methods allow external classes to get a pointer to installed filters of a given class.

  Parameters:
    cls - The class of the filter to look for.
  Returns:
    A RequestFilter instance, or null if not found.

createRequest

     public Request createRequest()

  Create a new default outgoing request. This method should always be used to create outgoing requests. It will initialize the request with appropriate default values for the various headers, and make sure that the request is enhanced by the registered request filters.

  Returns:
    An instance of Request, suitable to be launched.

setMaxConnections

     public synchronized void setMaxConnections(int max_conn)

  Global settings - Set the max number of allowed connections. Set the maximum number of simultaneous connections that can remain opened. The manager will take care of queuing requests if this number is reached.

  This value defaults to the value of the `org.w3c.www.http.maxConnections` property.

  Parameters:
    max_conn - The allowed maximum simultaneous open connections.

setTimeout

     public synchronized void setTimeout(int timeout)

  Global settings - Set the timeout on the socket

  This value defaults to the value of the `org.w3c.www.http.Timeout` property.

  Parameters:
    timeout - The allowed maximum microsecond before a timeout.

setProxy

     public void setProxy(URL proxy)

  Global settings - Set an optional proxy to use. Set the proxy to which all requests should be targeted. If the `org.w3c.www.http.proxy` property is defined, it will be used as the default value.

  Parameters:
    proxy - The URL for the proxy to use.

usingProxy

     public boolean usingProxy()

  Does this manager uses a proxy to fulfill requests ?

  Returns:
    A boolean.

setRequestTimeout

     public void setRequestTimeout(int ms)

  Global settings - Set the request timeout. Once a request has been emited, the HttpManager will sit for this given number of milliseconds before the request is declared to have timed-out.

  This timeout value defaults to the value of the `org.w3c.www.http.requestTimeout` property value.

  Parameters:
    ms - The timeout value in milliseconds.

setGlobalHeader

     public void setGlobalHeader(String name,
                                 String value)

  Global settings - Define a global request header. Set a default value for some request header. Once defined, the header will automatically be defined on all outgoing requests created through the `createRequest` request.

  Parameters:
    name - The name of the header, case insensitive.
    value - It's default value.

getGlobalHeader

     public String getGlobalHeader(String name)

  Global settings - Get a global request header default value.

  Parameters:
    name - The name of the header to get.
  Returns:
    The value for that header, as a String, or null if undefined.

sync

     public void sync()

  Dump all in-memory cached state to persistent storage.

main

     public static void main(String args[])

  DEBUGGING !

    All Packages  Class Hierarchy  This Package  Previous  Next  Index