Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.opencyc.webserver
Class WebServer

    java.lang.Object
      |
      +--java.lang.Thread
            |
            +--org.opencyc.webserver.WebServer

All Implemented Interfaces:
  java.lang.Runnable

public class WebServer
extends java.lang.Thread

Inner Class Summary
`protected class` | `WebServer.Task` Class Task processes a single HTTP request.

Field Summary
`protected static int` | `CACHE_CAPACITY` File cache capacity.
`static WebServer` | `current` Singleton WebServer instance.
`protected java.lang.String` | `cycHost` Cyc HTML host.
`protected int` | `cycPort` Cyc HTML port.
`protected static int` | `DEFAULT_CYC_PORT` Default Cyc base port.
`protected static java.lang.String` | `DEFAULT_DIR` Default directory to serve files from on non-Windows OS.
`protected static int` | `DEFAULT_PORT` Default HTTP port.
`protected static java.lang.String` | `DEFAULT_WIN_DIR` Default directory to serve files from on Windows.
`protected java.util.ArrayList` | `dirs` Directories to serve files from.
`protected static java.util.Hashtable` | `fileCache` File cache to improve file serving performance.
`protected java.util.HashMap` | `map` Map from String (jar root) to JarFile[] (jar class path).
`protected static long` | `nbrCacheHits` Number of files served from this web server that were found in the cache.
`protected static long` | `nbrFilesServed` Number of files served from this web server.
`protected int` | `port` Webserver HTTP port.
`protected java.net.ServerSocket` | `server` Server socket for accepting connections.
`protected boolean` | `traceRequests` Requests flag.
`protected boolean` | `trees` Expand jar tress.

Fields inherited from class java.lang.Thread
`MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

Constructor Summary
`WebServer()` Constructs a WebServer object.

Method Summary
`void` | `clearFileCache()` Administrative method that clears the file cache.
`java.util.ArrayList` | `getDirs()` Administrative accessor method that obtains list of directories from which files are served.
`long` | `getNbrCacheHits()` Administrative accessor method that obtains number of files served from cache.
`long` | `getNbrFilesServed()` Administrative accessor method that obtains number of files served.
`static void` | `main(java.lang.String[] args)` Provides the command line interface for creating an HTTP server.
`void` | `run()` Just keep looping, spawning a new thread for each incoming request.
`void` | `setDirs(java.util.ArrayList dirs)` Administrative method that updates the list of directories from which files are served.

Methods inherited from class java.lang.Thread
`activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, 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
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### current

    public static WebServer current

  Singleton WebServer instance.

### DEFAULT_PORT

    protected static int DEFAULT_PORT

  Default HTTP port.

### DEFAULT_CYC_PORT

    protected static int DEFAULT_CYC_PORT

  Default Cyc base port.

### DEFAULT_DIR

    protected static java.lang.String DEFAULT_DIR

  Default directory to serve files from on non-Windows OS.

### DEFAULT_WIN_DIR

    protected static java.lang.String DEFAULT_WIN_DIR

  Default directory to serve files from on Windows.

### CACHE_CAPACITY

    protected static final int CACHE_CAPACITY

  File cache capacity.

### fileCache

    protected static java.util.Hashtable fileCache

  File cache to improve file serving performance.

### nbrFilesServed

    protected static long nbrFilesServed

  Number of files served from this web server.

### nbrCacheHits

    protected static long nbrCacheHits

  Number of files served from this web server that were found in the cache.

### server

    protected java.net.ServerSocket server

  Server socket for accepting connections.

### dirs

    protected java.util.ArrayList dirs

  Directories to serve files from.

### map

    protected java.util.HashMap map

  Map from String (jar root) to JarFile[] (jar class path).

### port

    protected int port

  Webserver HTTP port.

### cycHost

    protected java.lang.String cycHost

  Cyc HTML host.

### cycPort

    protected int cycPort

  Cyc HTML port.

### trees

    protected boolean trees

  Expand jar tress.

### traceRequests

    protected boolean traceRequests

  Requests flag.

Constructor Detail

### WebServer

    public WebServer()
              throws java.io.IOException

  Constructs a WebServer object.
  Parameters:
    `port` - the port to use
    `directories` - the directory to serve files from
    `trees` - true if files within jar files should be served up
    `traceRequests` - true if client's request text should be logged.
  Throws:
    `java.io.IOException` - if the listening socket cannot be opened, or problem opening jar files.

Method Detail

### getDirs

    public java.util.ArrayList getDirs()

  Administrative accessor method that obtains list of directories from which files are served.

### setDirs

    public void setDirs(java.util.ArrayList dirs)
                 throws java.io.IOException

  Administrative method that updates the list of directories from which files are served.

### getNbrFilesServed

    public long getNbrFilesServed()

  Administrative accessor method that obtains number of files served.
  Returns:
    The number of files served.

### getNbrCacheHits

    public long getNbrCacheHits()

  Administrative accessor method that obtains number of files served from cache.
  Returns:
    The number of files served from the cache.

### clearFileCache

    public void clearFileCache()

  Administrative method that clears the file cache.

### main

    public static void main(java.lang.String[] args)

  Provides the command line interface for creating an HTTP server. The properties are:

       org.opencyc.webserver.port=

  which defaults to 80.

       org.opencyc.webserver.cycPort=

  which defaults to 3600.

       org.opencyc.webserver.dirs=; ... ;

  with the argument enclosed in quotes if any path contains an embedded space. The default directory on Windows is C: and the default on other systems is / the default can be overridden with this property. By default, all files under this directory (including all subdirectories) are served up via HTTP. If the pathname of a file is path relative to the top-level directory, then the file can be downloaded using the URL

       http://host:port/path

  Caching of file contents is performed.

       org.opencyc.util.log=all

  If the all value is given, then all attempts to download files are output.

       org.opencyc.webserver.traceRequests

  If this property has any value, then the client HTTP requests are output.

       org.opencyc.webserver.trees

  This property can be used to serve up individual files stored within jar files in addition to the files that are served up by default. If the property has any value, the server finds all jar files in the top-level directory (not in subdirectories). For each jar file, if the name of the jar file is name.jar, then any individual file named file within that jar file (or within the jar or zip files referenced transitively in the Class-Path manifest attribute, can be downloaded using a URL of the form:

       http://host:port/name/file

  When this property has any value, an open file descriptor and cached information are held for each jar file, for the life of the process.
  Parameters:
    `args` - an unused array of command line arguments.

### run

    public void run()

  Just keep looping, spawning a new thread for each incoming request.
  Overrides:
    `run` in class `java.lang.Thread`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD