| 
 |   | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
  |
  +--java.lang.Thread
        |
        +--sunlabs.brazil.server.Server
Yet another HTTP/1.1 server.
 This class is the core of a light weight Web Server.  This server
 is started as a Thread listening on the supplied port, and
 dispatches to an implementation of
 a Handler to service http requests.  If no handler is
 supplied, then the FileHandler is used.
 A ChainHandler is provided to allow multiple handlers in one server.
 
Limitations:
| Field Summary | |
|  int | acceptCountCount of accepted connections so far. | 
|  int | bufsizeDefault buffer size for copies to and from client sockets. | 
|  int | errorCountCount of errors that occurred so far. | 
|  Handler | handler | 
|  String | hostNameThe hostname that this Server should use to identify itself in an HTTP Redirect. | 
|  boolean | initFailureIf set, the server will terminate with an initialization failure just before creating the listen socket. | 
|  ServerSocket | listenThe listening socket. | 
| static int | LOG_DIAGNOSTIC | 
| static int | LOG_ERROR | 
| static int | LOG_INFORMATIONAL | 
| static int | LOG_LOG | 
| static int | LOG_WARNING | 
|  int | logLevelThe diagnostic level. | 
|  int | maxPostMaximum amout of POST data allowed per request (in bytes) (default = 2Meg). | 
|  int | maxRequestsMaximum number of consecutive requests allowed on a single kept-alive socket. | 
|  int | maxThreadsThe max number of threads allowed for the entire VM (default is 250). | 
|  String | nameThe string to return as the value for the "Server:" line in the HTTP response header. | 
|  String | prefixThe handler is passed a prefix to identify which items in the properties object are relevent. | 
|  Properties | propsHashtable containing arbitrary information that may be of interest to a Handler. | 
|  String | protocolThe protocol used to access this resource. | 
|  int | requestCountCount of HTTP requests received so far. | 
|  InetAddress[] | restrictIf non-null, restrict connections to just the specified ip addresses. | 
|  int | timeoutTime in milliseconds before this Server closes an idle socket or in-progress request. | 
| Fields inherited from class java.lang.Thread | 
| MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY | 
| Constructor Summary | |
| Server()Set up the server. | |
| Server(ServerSocket listen,
       String handlerName,
       Properties props)Create a server using the provided listener socket. | |
| Method Summary | |
|  void | close()Stop the server, and kill all pending requests | 
|  boolean | init() | 
|  void | log(int level,
    Object obj,
    String message)Logs information about the socket to System.out. | 
|  boolean | restart(String newHandler)Restart the server with a new handler. | 
|  void | run()Loops, accepting socket connections and replying to HTTP requests. | 
|  boolean | setup(ServerSocket listen,
      String handlerName,
      Properties props) | 
| Methods inherited from class java.lang.Thread | 
| activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield | 
| Methods inherited from class java.lang.Object | 
| equals, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
public ServerSocket listen
public Handler handler
public Properties props
Handler interface, as props in the
 Handler.init(Server, String)
 method, and as the default properties of
 Request.props in the Handler.respond(Request)
 method.
public String hostName
null, the hostname is derived
 by calling InetAddress.getHostAddress.
 
 InetAddress.getHostName would generally be the wrong
 thing to return because it returns only the base machine name
 xxx and not the machine name as it needs to appear
 to the rest of the network, such as xxx.yyy.com.
 
 The default value is null.
public String protocol
http, but
 can be changed for ssl to https
public InetAddress[] restrict
 The default value is null.
public String name
null, then no "Server:" line is
 returned.
public String prefix
public int timeout
 The default value is 30000.
public int maxRequests
 The default value is 25.
public int maxThreads
public int maxPost
public int bufsize
public int acceptCount
public int requestCount
public int errorCount
public int logLevel
public boolean initFailure
public static final int LOG_ERROR
public static final int LOG_WARNING
public static final int LOG_LOG
public static final int LOG_INFORMATIONAL
public static final int LOG_DIAGNOSTIC
| Constructor Detail | 
public Server(ServerSocket listen,
              String handlerName,
              Properties props)
 This server will call the Handler.respond method
 of the specified handler.  The specified handler should either
 respond to the request or perform further dispatches to other
 handlers.
listen - The socket this server should listen to.
		For ordinary sockets, this is simply: 
		new ServerSocket(port), where port
		is the network port to listen on.  Alternate implementations
		of ServerSocket, such as ssl versions
		may be used instead.handlerName - The name of the handler used to process http requests.
		It must implement the Handler interface.props - Arbitrary information made available to the handler.
		May be null.FileHandler, 
ChainHandlerpublic Server()
| Method Detail | 
public boolean setup(ServerSocket listen,
                     String handlerName,
                     Properties props)
public boolean init()
public boolean restart(String newHandler)
newHandler - Name of the handler to restart the server withpublic void run()
 Many things in the server are not initialized until this point,
 because the user may have set some related configuration options
 between the time this server was allocated and the time it was
 started.  For instance, the main Handler is not
 initialized until now, because its Handler.init method
 may have wanted to examine server member variables such as
 hostName or bufsize.
run in interface Runnablerun in class Threadpublic void close()
public void log(int level,
                Object obj,
                String message)
System.out.
level - Controls the verbosity (0=least 5=most)obj - The object that the message relates to.message - The message to be logged.| 
 | Version 2.1, Generated 12/30/04 Copyright (c) 2001-2004, Sun Microsystems. | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||