    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class w3c.www.protocol.http.HttpBasicServer

    java.lang.Object
       |
       +----w3c.www.protocol.http.HttpServer
               |
               +----w3c.www.protocol.http.HttpBasicServer

public class HttpBasicServer
extends HttpServer

The basic server class, to run requests. A server instance (ie an object conforming to the `HttpServer` interface is resposnsible for running all requests to a given host.

To do so, it manages a connnnection pool (ie a set of available connections) which it negotiates with the global HTTP manager. It keeps track of the connections it creates in order to serialize requests to the target server (when possible). In order to avoid deadlock due to implicit ordering of requests, a server that manages persistent (ie > 1.0) connections will always be able to open at least two connections to the same target.

Connections are kept track of by the server instance, which maintains at all point in time a list of idle connections. The way this is done may seem quite tricky, but beleive me, it's the best way I have found to handle it (there is here a typical deadlock situation - the same which is found in w3c.jigsaw.http.Client - due to the fact that the server instances need to be locked in order to change the connection pool, and at the same time each connection of the pool might have to notify the pool of some events. This can easily produce a deadlock...This situation is avoided here, by having the server locked only when appropriate...

##

connid
  Connections management - Allocate a new connection for this server.
host
  The host name of the server we handle.
manager
  Our central HTTP manager.
port
  The port number of the server we handle.
RQ_HTTP10
  Request mode - HTTP/1.0 with no keep-alive support.
RQ_HTTP10_KA
  Request mode - HTTP/1.0 with keep-alive support.
RQ_HTTP11
  Request mode - Full HTTP/1.1 compliant mode.
RQ_HTTP11_TS
  Request mode - Full two stage HTTP/1.1 compliant mode.
RQ_UNKNOWN
  Request mode - Unknown target server.
timeout
  The timeout on the socket

##

allocateConnection()
deleteConnection(HttpConnection)
doRequest(HttpBasicConnection, Request)
  Exceute given request on given conection, according to server.
getConnection()
  Connections management - Get an idle connection to run a request.
getMajorVersion()
  HttpServer implementation - Get this server's major version number.
getMinorVersion()
  HttpServer implementation - Get this server's minor version number.
getProtocol()
  HttpServer implementation - Get this servers' protocol.
getRequestMode(Request)
  Get the current mode of running request for that server.
http10_ka_run(HttpBasicConnection, Request)
  Run an HTTP/1.0 request that has support for keep alive.
http10_run(HttpBasicConnection, Request)
  Run a simple HTTP/1.0 request.
http11_run(HttpBasicConnection, Request)
  Run a fully HTTP/1.1 compliant request.
http11_ts_run(HttpBasicConnection, Request)
  Run a two stage HTTP/1.1 compliant request.
http_unknown(HttpBasicConnection, Request)
  Run that request, we don't know what server we have at the other end.
initialize(HttpManager, HttpServerState, String, int, int)
  HttpServer implementation - Initialize this server to its target.
interruptRequest(Request)
  Interrupt given request, that was launched by ourself.
isTwoStage_10(Request)
  Is this request a two stage request.
isTwoStage_11(Request)
  Is this request a two stage request.
notifyObserver(RequestObserver, Request, int)
notifyObserver(RequestObserver, RequestEvent)
registerConnection(HttpConnection)
  Connections management - Register a connection as being idle.
runRequest(Request)
  Run the given request in synchronous mode.
setTimeout(int)
  Set the timeout for the next connections
toString()
  Display this server into a String.
unregisterConnection(HttpConnection)
  Unregister a connection from the idle list.
updateServerInfo(Reply)
  A full round-trip has been run with the target server, update infos.

##

RQ_HTTP11

     protected static final int RQ_HTTP11

  Request mode - Full HTTP/1.1 compliant mode.

RQ_HTTP11_TS

     protected static final int RQ_HTTP11_TS

  Request mode - Full two stage HTTP/1.1 compliant mode.

RQ_HTTP10

     protected static final int RQ_HTTP10

  Request mode - HTTP/1.0 with no keep-alive support.

RQ_HTTP10_KA

     protected static final int RQ_HTTP10_KA

  Request mode - HTTP/1.0 with keep-alive support.

RQ_UNKNOWN

     protected static final int RQ_UNKNOWN

  Request mode - Unknown target server.

manager

     protected HttpManager manager

  Our central HTTP manager.

host

     protected String host

  The host name of the server we handle.

port

     protected int port

  The port number of the server we handle.

timeout

     protected int timeout

  The timeout on the socket

connid

     protected int connid

  Connections management - Allocate a new connection for this server. The connection is bound to the next available IP address, so that we are able to round-robin on them. If one of the DNS advertized IP address fails, we just try the next one, until one of them succeed or all of them fail.

##

getProtocol

     public String getProtocol()

  HttpServer implementation - Get this servers' protocol.

  Returns:
    A String encoding the protocol used to dialog with the target server.
  Overrides:
    getProtocol in class HttpServer

getMajorVersion

     public short getMajorVersion()

  HttpServer implementation - Get this server's major version number.

  Returns:
    The server's major number version, or -1 if still unknown.
  Overrides:
    getMajorVersion in class HttpServer

getMinorVersion

     public short getMinorVersion()

  HttpServer implementation - Get this server's minor version number.

  Returns:
    The server's minor number version, or -1 if still unknown.
  Overrides:
    getMinorVersion in class HttpServer

setTimeout

     public synchronized void setTimeout(int timeout)

  Set the timeout for the next connections

  Parameters:
    timeout - The timeout in milliseconds
  Overrides:
    setTimeout in class HttpServer

allocateConnection

     protected synchronized HttpBasicConnection allocateConnection() throws IOException

registerConnection

     public void registerConnection(HttpConnection conn)

  Connections management - Register a connection as being idle. When a connection is created, or when it becomes idle again (after having been used to handle a request), it has to be registered back to the idle list of connection for the server. All connections contained in this idle list are candidates for being elected to handle some pending or incoming request to the host we manager.

  Parameters:
    conn - The connection that is now idle.

unregisterConnection

     public synchronized void unregisterConnection(HttpConnection conn)

  Unregister a connection from the idle list. Unregistering a connection means that the server shouldn't keep track of it any more. This can happen in two situations:
  - The connection won't be reusable, so there is no point for the server to try to keep track of it. In this case, the connection is forgotten, and the caller will terminate it by invoking the connection's input stream close method.
  - The connection has successfully handle a connection, and the connection is about to be reused. During the time of the request processing, the server looses track of this connection, which will register itself again when back to idle.

  Parameters:
    conn - The connection to unregister from the idle list.

deleteConnection

     public void deleteConnection(HttpConnection conn)

getConnection

     protected HttpBasicConnection getConnection() throws IOException

  Connections management - Get an idle connection to run a request. The server has been asked to run a new request, and it now wants a connection to run it on. This method will try various ways of aqcuiring a connection:
  - It will look for an idle connection.
  - It will then try to negotiate with the HTTP manager the creation of a new connection to the target server.
  - If this fails too, it will just wait until a connection becomes available.
  The connection returned is marked for use (ie it is unregistered from the idle connection list), it is up to the caller to make sure that if possible, the connection registers itself again to the idle list after the processing is done.

  This method can return null to indicate to the caller that it should try again, in the hope that the target server has multiple (different) IP addresses.

  Returns:
    A connection marked in use, and which should be marked as idle after the processing it is use for is done, or null if a fresh connection cannot be established.

toString

     public String toString()

  Display this server into a String.

  Returns:
    A String based representation of the server object.
  Overrides:
    toString in class Object

updateServerInfo

     protected synchronized void updateServerInfo(Reply reply)

  A full round-trip has been run with the target server, update infos. Each server instance maintains a set of informations to be reused if needed when recontacting the server later. After a full round trip has been performed with the server, it is time to update the target server version number, and keeps-alive flag.

  Parameters:
    reply - The first reply we got from this server.

initialize

     public void initialize(HttpManager manager,
                            HttpServerState state,
                            String host,
                            int port,
                            int timeout) throws HttpException

  HttpServer implementation - Initialize this server to its target.

  Parameters:
    manager - The central HTTP manager.
    state - The manager's state for that server.
    host - The target server's host name.
    port - The target server's port number.
    timeout - The timeout for the connection handled by the server
  Throws: HttpException
    If the server host couldn't be resolved to one or more IP addresses.
  Overrides:
    initialize in class HttpServer

notifyObserver

     protected void notifyObserver(RequestObserver obs,
                                   Request request,
                                   int code)

notifyObserver

     protected void notifyObserver(RequestObserver obs,
                                   RequestEvent evt)

isTwoStage_10

     protected boolean isTwoStage_10(Request request)

  Is this request a two stage request.

  Returns:
    A boolean, true if the request is two stage, false otherwise.

isTwoStage_11

     protected boolean isTwoStage_11(Request request)

  Is this request a two stage request.

  Returns:
    A boolean, true if the request is two stage, false otherwise.

getRequestMode

     protected int getRequestMode(Request request)

  Get the current mode of running request for that server. This method check our knowledge of the target server, and deduce the mode in which the given request should be run.

  Returns:
    An integer code, indicating the mode in which the request should be run:
    RQ_HTTP11
    The request should be run as an HTTP/1.1 request.
    RQ_HTTP10
    The request should be run as an HTTP/1.0 request.
    RQ_HTTP10_KA
    HTTP/1.0 with keep-alive support.
    RQ_UNKNOWN
    This is the first request, we don't know yet.
  http11_run

       protected Reply http11_run(HttpBasicConnection conn,
                                  Request request) throws IOException, MimeParserException

    Run a fully HTTP/1.1 compliant request. This request has no body, so we can do whatever we want with it, and retry as many time as we want.

    Parameters:
      conn - The connection to run the request on.
      request - The request to run.
    Returns:
      A Reply instance, if success; null if the request should be retried.
    Throws: IOException
      If some IO error occured.
    Throws: MimeParserException
      If some MIME parsing error occured.
  http11_ts_run

       protected Reply http11_ts_run(HttpBasicConnection conn,
                                     Request request) throws IOException, MimeParserException

    Run a two stage HTTP/1.1 compliant request. The neat thing about this sort of request is that as they support 100 status codes, we know when we have to retry them.

    Parameters:
      conn - The connection to run the request on.
      request - The request to run.
    Returns:
      A Reply instance, if success; null if the request should be retried.
    Throws: IOException
      If some IO error occured.
    Throws: MimeParserException
      If some MIME parsing error occured.
  http10_ka_run

       protected Reply http10_ka_run(HttpBasicConnection conn,
                                     Request request) throws IOException, MimeParserException

    Run an HTTP/1.0 request that has support for keep alive. This kind of request are the worst one with regard to the retry strategy we can adopt.

    Parameters:
      conn - The connection to run the request on.
      request - The request to run.
    Returns:
      A Reply instance, if success; null if the request should be retried.
    Throws: IOException
      If some IO error occured.
    Throws: MimeParserException
      If some MIME parsing error occured.
  http10_run

       protected Reply http10_run(HttpBasicConnection conn,
                                  Request request) throws IOException, MimeParserException

    Run a simple HTTP/1.0 request. This server doesn't support keep-alive, we know the connection is always fresh, we don't need to go into the retry buisness.

    That's cool !

    Parameters:
      conn - The connection to run the request on.
      request - The request to run.
    Returns:
      A Reply instance, if success; null if the request should be retried.
    Throws: IOException
      If some IO error occured.
    Throws: MimeParserException
      If some MIME parsing error occured.
  http_unknown

       protected Reply http_unknown(HttpBasicConnection conn,
                                    Request request) throws IOException, MimeParserException

    Run that request, we don't know what server we have at the other end. We know the connection is fresh, we use the `http10_run` and update the server infos by the end of processing.

    Parameters:
      conn - The connection to run the request on.
      request - The request to run.
    Returns:
      A Reply instance, if success; null if the request should be retried.
    Throws: IOException
      If some IO error occured.
    Throws: MimeParserException
      If some MIME parsing error occured.
  doRequest

       protected Reply doRequest(HttpBasicConnection conn,
                                 Request request) throws IOException, MimeParserException

    Exceute given request on given conection, according to server.

    Parameters:
      conn - The connection to use to run that request.
      request - The request to execute.
    Throws: IOException
      If some IO error occurs, or if the request is interrupted.
    Throws: MimeParserException
      If taregt server doesn't conform to the HTTP specification.
  interruptRequest

       protected void interruptRequest(Request request)

    Interrupt given request, that was launched by ourself.

    Parameters:
      request - The request to interrupt.
    Overrides:
      interruptRequest in class HttpServer
  runRequest

       public Reply runRequest(Request request) throws HttpException

    Run the given request in synchronous mode.

    Parameters:
      request - The request to run.
    Returns:
      A Reply instance, containing the reply headers, and the optional reply entity, to be read by the calling thread.
    Throws: HttpException
      If the request processing failed.
    Overrides:
      runRequest in class HttpServer

      All Packages  Class Hierarchy  This Package  Previous  Next  Index