Java Doc for HttpBasicServer.java in  » Web-Server » Jigsaw » org » w3c » www » protocol » http » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » Jigsaw » org.w3c.www.protocol.http 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.w3c.www.protocol.http.HttpServer
      org.w3c.www.protocol.http.HttpBasicServer

HttpBasicServer
public class HttpBasicServer extends HttpServer (Code)
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 org.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...



Field Summary
final protected static  intRQ_HTTP10
     Request mode - HTTP/1.0 with no keep-alive support.
final protected static  intRQ_HTTP10_KA
     Request mode - HTTP/1.0 with keep-alive support.
final protected static  intRQ_HTTP11
     Request mode - Full HTTP/1.1 compliant mode.
final protected static  intRQ_HTTP11_TS
     Request mode - Full two stage HTTP/1.1 compliant mode.
final protected static  intRQ_UNKNOWN
     Request mode - Unknown target server.
 intaddrptr
    
 InetAddressaddrs
    
protected  intconn_timeout
    
protected  intconnid
     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.
 booleancontacted
    
protected  Stringhost
     The host name of the server we handle.
 booleankeepalive
    
 DatelookupLimit
    
 shortmajor
    
protected  HttpManagermanager
     Our central HTTP manager.
 shortminor
    
protected  intport
     The port number of the server we handle.
protected  inttimeout
    

Constructor Summary
 HttpBasicServer()
    

Method Summary
protected  HttpBasicConnectionallocateConnection()
    
public  voiddeleteConnection(HttpConnection conn)
    
protected  ReplydoRequest(HttpBasicConnection conn, Request request)
     Exceute given request on given conection, according to server.
protected  HttpBasicConnectiongetConnection()
     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.
public  shortgetMajorVersion()
     HttpServer implementation - Get this server's major version number.
public  shortgetMinorVersion()
     HttpServer implementation - Get this server's minor version number.
public  StringgetProtocol()
     HttpServer implementation - Get this servers' protocol.
protected  intgetRequestMode(Request request)
     Get the current mode of running request for that server.
protected  Replyhttp10_ka_run(HttpBasicConnection conn, Request request)
     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.
Parameters:
  request - The request to run.
protected  Replyhttp10_run(HttpBasicConnection conn, Request request)
     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.
Parameters:
  request - The request to run.

protected  Replyhttp11_run(HttpBasicConnection conn, Request request)
     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.
Parameters:
  request - The request to run.
protected  Replyhttp11_ts_run(HttpBasicConnection conn, Request request)
     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.
Parameters:
  request - The request to run.
protected  Replyhttp_unknown(HttpBasicConnection conn, Request request)
     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.
Parameters:
  request - The request to run.
public  voidinitialize(HttpManager manager, HttpServerState state, String host, int port, int timeout)
     HttpServer implementation - Initialize this server to its target.
public  voidinitialize(HttpManager manager, HttpServerState state, String host, int port, int timeout, int conn_timeout)
     HttpServer implementation - Initialize this server to its target.
protected  voidinterruptRequest(Request request)
     Interrupt given request, that was launched by ourself.
protected  booleanisTwoStage_10(Request request)
     Is this request a two stage request.
protected  booleanisTwoStage_11(Request request)
     Is this request a two stage request.
protected  voidnotifyObserver(RequestObserver obs, Request request, int code)
    
protected  voidnotifyObserver(RequestObserver obs, RequestEvent evt)
    
public  voidregisterConnection(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.
public  ReplyrunRequest(Request request)
     Run the given request in synchronous mode.
Parameters:
  request - The request to run.
public synchronized  voidsetConnTimeout(int conn_timeout)
    
protected  voidsetHostAddr(InetAddress hostAddrs)
    
public synchronized  voidsetTimeout(int timeout)
    
public  StringtoString()
     Display this server into a String.
public synchronized  voidunregisterConnection(HttpConnection conn)
     Unregister a connection from the idle list. Unregistering a connection means that the server shouldn't keep track of it any more.
protected  voidupdateHostAddr()
    
protected synchronized  voidupdateServerInfo(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.

Field Detail
RQ_HTTP10
final protected static int RQ_HTTP10(Code)
Request mode - HTTP/1.0 with no keep-alive support.



RQ_HTTP10_KA
final protected static int RQ_HTTP10_KA(Code)
Request mode - HTTP/1.0 with keep-alive support.



RQ_HTTP11
final protected static int RQ_HTTP11(Code)
Request mode - Full HTTP/1.1 compliant mode.



RQ_HTTP11_TS
final protected static int RQ_HTTP11_TS(Code)
Request mode - Full two stage HTTP/1.1 compliant mode.



RQ_UNKNOWN
final protected static int RQ_UNKNOWN(Code)
Request mode - Unknown target server.



addrptr
int addrptr(Code)



addrs
InetAddress addrs(Code)



conn_timeout
protected int conn_timeout(Code)
The connectiontimeout for the socket



connid
protected int connid(Code)
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. A freshly allocated connection, inserted in the idle connectionlist.
exception:
  IOException - If the server is unreachable through all ofIts IP addresses.



contacted
boolean contacted(Code)



host
protected String host(Code)
The host name of the server we handle.



keepalive
boolean keepalive(Code)



lookupLimit
Date lookupLimit(Code)



major
short major(Code)



manager
protected HttpManager manager(Code)
Our central HTTP manager.



minor
short minor(Code)



port
protected int port(Code)
The port number of the server we handle.



timeout
protected int timeout(Code)
The timeout on the socket




Constructor Detail
HttpBasicServer
HttpBasicServer()(Code)




Method Detail
allocateConnection
protected HttpBasicConnection allocateConnection() throws IOException(Code)



deleteConnection
public void deleteConnection(HttpConnection conn)(Code)



doRequest
protected Reply doRequest(HttpBasicConnection conn, Request request) throws IOException, MimeParserException(Code)
Exceute given request on given conection, according to server.
Parameters:
  conn - The connection to use to run that request.
Parameters:
  request - The request to execute.
exception:
  IOException - If some IO error occurs, or if the request is interrupted.
exception:
  MimeParserException - If taregt server doesn't conform to the HTTP specification.



getConnection
protected HttpBasicConnection getConnection() throws IOException(Code)
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. A connection marked in use, and which should be marked asidle after the processing it is use for is done, or null if a fresh connection cannot be established.




getMajorVersion
public short getMajorVersion()(Code)
HttpServer implementation - Get this server's major version number. The server's major number version, or -1if still unknown.



getMinorVersion
public short getMinorVersion()(Code)
HttpServer implementation - Get this server's minor version number. The server's minor number version, or -1if still unknown.



getProtocol
public String getProtocol()(Code)
HttpServer implementation - Get this servers' protocol. A String encoding the protocol used to dialog with the targetserver.



getRequestMode
protected int getRequestMode(Request request)(Code)
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. An integer code, indicating the mode in which the request shouldbe 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.



http10_ka_run
protected Reply http10_ka_run(HttpBasicConnection conn, Request request) throws IOException, MimeParserException(Code)
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.
Parameters:
  request - The request to run. A Reply instance, if success; null if the request should be retried.
exception:
  IOException - If some IO error occured.
exception:
  MimeParserException - If some MIME parsing error occured.



http10_run
protected Reply http10_run(HttpBasicConnection conn, Request request) throws IOException, MimeParserException(Code)
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.
Parameters:
  request - The request to run. A Reply instance, if success; null if the request should be retried.
exception:
  IOException - If some IO error occured.
exception:
  MimeParserException - If some MIME parsing error occured.




http11_run
protected Reply http11_run(HttpBasicConnection conn, Request request) throws IOException, MimeParserException(Code)
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.
Parameters:
  request - The request to run. A Reply instance, if success; null if the request should be retried.
exception:
  IOException - If some IO error occured.
exception:
  MimeParserException - If some MIME parsing error occured.



http11_ts_run
protected Reply http11_ts_run(HttpBasicConnection conn, Request request) throws IOException, MimeParserException(Code)
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.
Parameters:
  request - The request to run. A Reply instance, if success; null if the request should be retried.
exception:
  IOException - If some IO error occured.
exception:
  MimeParserException - If some MIME parsing error occured.



http_unknown
protected Reply http_unknown(HttpBasicConnection conn, Request request) throws IOException, MimeParserException(Code)
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.
Parameters:
  request - The request to run. A Reply instance, if success; null if the request should be retried.
exception:
  IOException - If some IO error occured.
exception:
  MimeParserException - If some MIME parsing error occured.



initialize
public void initialize(HttpManager manager, HttpServerState state, String host, int port, int timeout) throws HttpException(Code)
HttpServer implementation - Initialize this server to its target.
Parameters:
  manager - The central HTTP manager.
Parameters:
  state - The manager's state for that server.
Parameters:
  host - The target server's host name.
Parameters:
  port - The target server's port number.
Parameters:
  timeout - The timeout for the connection handled by the server
exception:
  HttpException - If the server host couldn't be resolvedto one or more IP addresses.



initialize
public void initialize(HttpManager manager, HttpServerState state, String host, int port, int timeout, int conn_timeout) throws HttpException(Code)
HttpServer implementation - Initialize this server to its target.
Parameters:
  manager - The central HTTP manager.
Parameters:
  state - The manager's state for that server.
Parameters:
  host - The target server's host name.
Parameters:
  port - The target server's port number.
Parameters:
  timeout - The timeout for the connection handled by the server
Parameters:
  timeout - The connection timeout in millisecond for the sockets
exception:
  HttpException - If the server host couldn't be resolvedto one or more IP addresses.



interruptRequest
protected void interruptRequest(Request request)(Code)
Interrupt given request, that was launched by ourself.
Parameters:
  request - The request to interrupt.



isTwoStage_10
protected boolean isTwoStage_10(Request request)(Code)
Is this request a two stage request. A boolean, true if the request is twostage, false otherwise.



isTwoStage_11
protected boolean isTwoStage_11(Request request)(Code)
Is this request a two stage request. A boolean, true if the request is twostage, false otherwise.



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



notifyObserver
protected void notifyObserver(RequestObserver obs, RequestEvent evt)(Code)



registerConnection
public void registerConnection(HttpConnection conn)(Code)
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.



runRequest
public Reply runRequest(Request request) throws HttpException(Code)
Run the given request in synchronous mode.
Parameters:
  request - The request to run. A Reply instance, containing the reply headers, and the optional reply entity, to be read by the calling thread.
exception:
  HttpException - If the request processing failed.



setConnTimeout
public synchronized void setConnTimeout(int conn_timeout)(Code)
Set the connection timeout for the next connections
Parameters:
  timeout - The timeout in milliseconds



setHostAddr
protected void setHostAddr(InetAddress hostAddrs)(Code)
set the inet addresses of this host, and timestamp it to avoid caching IPs forever hostAddrs, an array of InetAddress



setTimeout
public synchronized void setTimeout(int timeout)(Code)
Set the timeout for the next connections
Parameters:
  timeout - The timeout in milliseconds



toString
public String toString()(Code)
Display this server into a String. A String based representation of the server object.



unregisterConnection
public synchronized void unregisterConnection(HttpConnection conn)(Code)
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.



updateHostAddr
protected void updateHostAddr() throws HttpException(Code)
check the validity of the host address if invalid, it will update the InetAddress associated with this host



updateServerInfo
protected synchronized void updateServerInfo(Reply reply)(Code)
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.



Fields inherited from org.w3c.www.protocol.http.HttpServer
protected HttpServerState state(Code)(Java Doc)

Methods inherited from org.w3c.www.protocol.http.HttpServer
abstract public short getMajorVersion()(Code)(Java Doc)
abstract public short getMinorVersion()(Code)(Java Doc)
abstract public String getProtocol()(Code)(Java Doc)
final protected HttpServerState getState()(Code)(Java Doc)
abstract public void initialize(HttpManager manager, HttpServerState state, String host, int port, int timeout) throws HttpException(Code)(Java Doc)
abstract public void initialize(HttpManager manager, HttpServerState state, String host, int port, int timeout, int connect_timeout) throws HttpException(Code)(Java Doc)
abstract protected void interruptRequest(Request request)(Code)(Java Doc)
abstract public Reply runRequest(Request request) throws HttpException(Code)(Java Doc)
abstract protected void setConnTimeout(int conn_timeout)(Code)(Java Doc)
abstract protected void setTimeout(int timeout)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.