All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class w3c.www.protocol.http.HttpManager

java.lang.Object
   |
   +----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.makeRequest() ;
 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() ;
 ...
 


Variable Index

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

Constructor Index

 o HttpManager()
Create a new HttpManager.

Method Index

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

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

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

Variables

 o SERVER_CLASS_P
 public static final String SERVER_CLASS_P
The name of the property indicating the class of HttpServer to use.

 o FILTERS_PROP_P
 public static final String FILTERS_PROP_P
The name of the property containing the ProprequestFilter to launch.

 o CONN_MAX_P
 public static final String CONN_MAX_P
The maximum number of simultaneous connections.

 o TIMEOUT_P
 public static final String TIMEOUT_P
The SO_TIMEOUT of the client socket.

 o MAX_STALE_P
 public static final String MAX_STALE_P
Header properties - The allowed drift for getting cached resources.

 o MIN_FRESH_P
 public static final String MIN_FRESH_P
Header properties - The minium freshness required on cached resources.

 o ONLY_IF_CACHED_P
 public static final String ONLY_IF_CACHED_P
Header properties - Set the only if cached flag on requests.

 o USER_AGENT_P
 public static final String USER_AGENT_P
Header properties - Set the user agent.

 o ACCEPT_P
 public static final String ACCEPT_P
Header properties - Set the accept header.

 o ACCEPT_LANGUAGE_P
 public static final String ACCEPT_LANGUAGE_P
Header properties - Set the accept language.

 o ACCEPT_ENCODING_P
 public static final String ACCEPT_ENCODING_P
Header properties - Set the accept encodings.

 o PROXY_SET_P
 public static final String PROXY_SET_P
Header properties - Should we use a proxy ?

 o PROXY_HOST_P
 public static final String PROXY_HOST_P
Header properties - What is the proxy host name.

 o PROXY_PORT_P
 public static final String PROXY_PORT_P
Header properties - What is the proxy port number.

 o DEFAULT_ACCEPT
 public static final String DEFAULT_ACCEPT
The default value for the Accept header.

 o DEFAULT_USER_AGENT
 public static final String DEFAULT_USER_AGENT
The default value for the User-Agent header.

 o serverclass
 protected Class serverclass
The class to instantiate to create new HttpServer instances.

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

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

 o connectionsLru
 protected LRUList connectionsLru
The LRU list of connections.

 o timeout
 protected int timeout
 o conn_count
 protected int conn_count
 o conn_max
 protected int conn_max

Constructors

 o 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.

Methods

 o updateProxy
 protected boolean updateProxy()
Update the proxy configuration to match current properties setting.

Returns:
A boolean, true if change was done, false otherwise.
 o getProperties
 public final ObservableProperties getProperties()
Get this manager properties.

Returns:
An ObservableProperties instance.
 o 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.
 o 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.
 o 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.
 o getManager
 public static HttpManager getManager()
 o 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.
 o 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.
 o 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.
 o notifyIdle
 public void notifyIdle(HttpConnection conn)
The given connection can be reused, but is now idle.

Parameters:
conn - The connection that is now idle.
 o notifyConnection
 protected synchronized void notifyConnection(HttpConnection conn)
The given connection has just been created.

Parameters:
conn - The newly created connection.
 o deleteConnection
 protected void deleteConnection(HttpConnection conn)
The given connection has been deleted.

Parameters:
conn - The deleted connection.
 o tooManyConnections
 protected synchronized boolean tooManyConnections()
 o 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.
 o waitForConnection
 protected synchronized void waitForConnection(HttpServer server) throws InterruptedException
 o closeAnyConnection
 protected boolean closeAnyConnection()
Close one connection, but pickling the least recently used one.

Returns:
A boolean, true if a connection was closed false otherwise.
 o 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.
 o 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.
 o 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.
 o 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.
 o getReplyFactory
 public MimeParserFactory getReplyFactory()
 o 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.
 o setFilter
 public void setFilter(RequestFilter filter)
Add a global filter. The given filter will always be invoked.

Parameters:
filter - The filter to install.
 o 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.
 o 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.
 o 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 w3c.www.http.maxConnections property.

Parameters:
max_conn - The allowed maximum simultaneous open connections.
 o setTimeout
 public synchronized void setTimeout(int timeout)
Global settings - Set the timeout on the socket

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

Parameters:
timeout - The allowed maximum microsecond before a timeout.
 o 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 w3c.www.http.proxy property is defined, it will be used as the default value.

Parameters:
proxy - The URL for the proxy to use.
 o usingProxy
 public boolean usingProxy()
Does this manager uses a proxy to fulfill requests ?

Returns:
A boolean.
 o 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 w3c.www.http.requestTimeout property value.

Parameters:
ms - The timeout value in milliseconds.
 o 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.
 o 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.
 o sync
 public void sync()
Dump all in-memory cached state to persistent storage.

 o main
 public static void main(String args[])
DEBUGGING !


All Packages  Class Hierarchy  This Package  Previous  Next  Index