org.ceryle.util.http
Class HTTPServer

java.lang.Object
  extended by org.ceryle.util.http.HTTPServer

public class HTTPServer
extends Object

Provides a shell under which a Jetty HTTP server is run. This is a singleton class, as there is only one HTTP server per running instance of Ceryle (indeed, per machine).

To obtain the instance of this class and start the server:

     HTTPServer httpserver = HTTPServer.getInstance();
        httpserver.start();
 

Version:
$Id: HTTPServer.java,v 3.10 2007-06-15 12:10:00 altheim Exp $
Author:
Murray Altheim

Field Summary
static String DEFAULT_HOST
          The default hostname to use for communications.
static int DEFAULT_PORT
          The default socket to use for communications.
protected static String m_base
          The web server's virtual base context path.
protected static String m_host
          The hostname to use for communications.
protected static int m_port
          The current socket to use for communications.
protected static File m_root
          The web server's virtual root/context path.
protected static String m_rootURL
          The root HTTP URL of the running server.
protected  MessageHandler mh
           
protected  PropertyManager pm
           
static String SERVER_VERSION
          HTTP Server version.
protected  Services srvs
           
 
Method Summary
protected  void doStop()
          Actually performs the stop server action.
protected  void fireEvent()
          Fires a ChangeEvent to all registered listeners, indicating some significant change in server status.
static String getBaseContext()
          Returns the base context, whose default is "/".
static HTTPServer getInstance()
          As this is a singleton class, this returns the single instance of this class using the defaults provided by the application properties file and settings.
 int getPort()
          Returns the currently-used HTTP port.
 String getRootURL()
          Returns the root HTTP URL of the server.
static String getSampleBaseURL(String hostname, int port)
          A simple utility that returns a sample base URL based on the supplied hostname and port.
 WikiUtils getWikiUtils()
          Return the WikiUtils if there is a wiki installation, null if not.
 void halt()
          Halts the HTTP server.
static boolean hasInstance()
          Returns true if there is an HTTP server instance (running or not).
static boolean isRunning()
          Returns true if the HTTP server is running and accepting new service requests.
 void kill()
          Immediately stops the HTTP server.
 void loadProperties()
          Loads server properties from the PropertyManager.
 void presetServices()
          Preset the Wiki listener so that when the WikiEngine starts the initialization events will be captured.
 void serverIsRunning()
          Called by the start process after the server is running.
 void start()
          Starts up the HTTP server.
protected  void writeLog(String s)
          Write the String s to the log file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVER_VERSION

public static final String SERVER_VERSION
HTTP Server version.

See Also:
Constant Field Values

DEFAULT_HOST

public static final String DEFAULT_HOST
The default hostname to use for communications. The default is "localhost".

See Also:
Constant Field Values

m_host

protected static String m_host
The hostname to use for communications. The default is "localhost." The property for this setting is: http://purl.org/ceryle/prop/#HTTPhost.


DEFAULT_PORT

public static final int DEFAULT_PORT
The default socket to use for communications. The default is 9099.

See Also:
Constant Field Values

m_port

protected static int m_port
The current socket to use for communications. The default is DEFAULT_PORT. The property for this setting is: http://purl.org/ceryle/prop/#HTTPport.


m_root

protected static File m_root
The web server's virtual root/context path. The property for this setting is: http://purl.org/ceryle/prop/#HTTProot.


m_rootURL

protected static String m_rootURL
The root HTTP URL of the running server. The default is http://localhost:9099/ceryle/.


m_base

protected static String m_base
The web server's virtual base context path. The default value is "/". The property for this setting is: http://purl.org/ceryle/prop/#HTTPbaseContext.


srvs

protected Services srvs

mh

protected MessageHandler mh

pm

protected PropertyManager pm
Method Detail

getInstance

public static HTTPServer getInstance()
As this is a singleton class, this returns the single instance of this class using the defaults provided by the application properties file and settings. If the HTTPServer object has already been created, this method returns it. Note that this doesn't actually start the server, just creates the shell object.


getBaseContext

public static String getBaseContext()
Returns the base context, whose default is "/".


getRootURL

public String getRootURL()
Returns the root HTTP URL of the server.


getPort

public int getPort()
Returns the currently-used HTTP port.


start

public void start()
Starts up the HTTP server. This is ignored if already running.


getWikiUtils

public WikiUtils getWikiUtils()
Return the WikiUtils if there is a wiki installation, null if not. This is not an indication that the server or service is running.


presetServices

public void presetServices()
Preset the Wiki listener so that when the WikiEngine starts the initialization events will be captured.


serverIsRunning

public void serverIsRunning()
Called by the start process after the server is running. This is where any post-start services are started.


loadProperties

public void loadProperties()
                    throws IOException
Loads server properties from the PropertyManager.

Throws:
IOException

isRunning

public static boolean isRunning()
Returns true if the HTTP server is running and accepting new service requests.


hasInstance

public static boolean hasInstance()
Returns true if there is an HTTP server instance (running or not).


halt

public void halt()
Halts the HTTP server. This does not kill active threads, but ends idle ones, and keeps new ones from being started.


kill

public void kill()
Immediately stops the HTTP server. This sends a message to the parent server to immediately attempt to kill off all of its children. Then the parent itself exits. Any requests in progress are terminated, and no further requests are served.


doStop

protected void doStop()
Actually performs the stop server action.


writeLog

protected void writeLog(String s)
Write the String s to the log file.


getSampleBaseURL

public static String getSampleBaseURL(String hostname,
                                      int port)
A simple utility that returns a sample base URL based on the supplied hostname and port. If the port is negative or 80 it is not included/ignored.


fireEvent

protected final void fireEvent()
Fires a ChangeEvent to all registered listeners, indicating some significant change in server status.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.