org.opensubsystems.core.application
Class Server

java.lang.Object
  extended by org.opensubsystems.core.application.Server
Direct Known Subclasses:
ThickClient

public abstract class Server
extends java.lang.Object

Base class for all servers and applications developed by project OpenSubsystems. TODO: Improve: At present moment this server is tightly integrated with Jetty HTTP server mainly because it is easily embeddble. Once there is a need to support multiple servers, it can be abstracted through an intermediate interface with multiple imlementations. That's the main reason why is this class not derived from the Jetty server class but it is using it instead. The lifecycle of the server is Constructor, init(), start(). The derived classes should just declare their own main method, construct the derived Server object and call startServer on it: ExampleServer srvServer; srvServer = new ExampleServer(); startServer(srvServer); The web applications which should be run on the server should be configured by overriding addWebApplications method.

Version:
$Id: Server.java,v 1.10 2007/01/07 06:14:39 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Miro Halas
Code reviewed:
1.6 2006/04/05 04:56:30 bastafidli

Field Summary
protected  boolean m_bStarted
          This flag is true if the server is started.
protected  org.mortbay.http.HttpServer m_hsServer
          Web container used by this server.
protected  int m_iWebServerPort
          Port where this web server should start.
protected static int s_iMaxServerStartRetry
          How many try we will try to restart the server if specified port cannot be used as initialized from configuration file.
static java.lang.String SERVER_START_RETRYCOUNT
          Name of the property specifying how many times we should try to restart the embedded web server if it cannot be started at the port specified by oss.webserver.port.
static int SERVER_START_RETRYCOUNT_DEFAULT
          How many try we will try to restart the server if specified port cannot be used.
 
Constructor Summary
Server(ProductInfo product)
          Create new instance of the server.
 
Method Summary
protected abstract  void addWebApplications(org.mortbay.http.HttpServer hsServer)
          Install web applications which should be run on the server.
protected static int generateNewWebPort(int iOldPort)
          Generate new port number where to start the server if the old one failed.
 int getWebServerPort()
          Get the web server port.
 void init()
          Initialize the server.
protected  void initContext(java.lang.String strURLPrefix, org.mortbay.jetty.servlet.WebApplicationContext wacContext)
          Initialize context (URL subtree) starting with given prefix.
 boolean isStarted()
          Test if the server is started.
 void setWebServerPort(int iWebServerPort)
          Set the web server port.
 void start()
          Start the server.
protected static void startServer(Server srvServer)
          Start specified server.
 void stop()
          Stop the server.
protected static void stopServer(Server srvServer)
          Stop specified server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVER_START_RETRYCOUNT

public static final java.lang.String SERVER_START_RETRYCOUNT
Name of the property specifying how many times we should try to restart the embedded web server if it cannot be started at the port specified by oss.webserver.port. If the port specified is the standard HTTP port 80, the server will try port 8080 and then other ports above it until an available port is found or until the specified value is reached. If the port specified is not port 80, the port number will be increased by 1 until an available port is found or until the specified value is reached. If the value is 0, the system will not attempt to restart the embedded web server if it cannot be started on the originally specified port.

See Also:
s_iMaxServerStartRetry, SERVER_START_RETRYCOUNT_DEFAULT, Constant Field Values

SERVER_START_RETRYCOUNT_DEFAULT

public static final int SERVER_START_RETRYCOUNT_DEFAULT
How many try we will try to restart the server if specified port cannot be used.

See Also:
SERVER_START_RETRYCOUNT, s_iMaxServerStartRetry, Constant Field Values

m_iWebServerPort

protected int m_iWebServerPort
Port where this web server should start.


m_hsServer

protected org.mortbay.http.HttpServer m_hsServer
Web container used by this server.


m_bStarted

protected boolean m_bStarted
This flag is true if the server is started.


s_iMaxServerStartRetry

protected static int s_iMaxServerStartRetry
How many try we will try to restart the server if specified port cannot be used as initialized from configuration file.

See Also:
SERVER_START_RETRYCOUNT, SERVER_START_RETRYCOUNT_DEFAULT, s_iMaxServerStartRetry
Constructor Detail

Server

public Server(ProductInfo product)
Create new instance of the server. The initialization should be done in a separate step so we can have more control over error handling.

Parameters:
product - - information about product which is running this server, this way we will force every application to create and publish this information in uniform way
Method Detail

getWebServerPort

public int getWebServerPort()
Get the web server port.

Returns:
int

setWebServerPort

public void setWebServerPort(int iWebServerPort)
Set the web server port.

Parameters:
iWebServerPort - - new web server port

init

public void init()
          throws OSSException,
                 java.io.IOException
Initialize the server. All initializeation should be done in this method so that we can call it repetitevely with changed parameters if initialization fails.

Throws:
OSSException - - if there was an error starting persistance store
java.io.IOException - - if there was an error accessing database properties

start

public void start()
           throws org.mortbay.util.MultiException,
                  OSSException
Start the server.

Throws:
org.mortbay.util.MultiException - - if there was an error starting the server
OSSException - - if there was an error starting the server

isStarted

public boolean isStarted()
Test if the server is started.

Returns:
boolean - true if started

stop

public void stop()
          throws OSSException,
                 java.lang.InterruptedException
Stop the server.

Throws:
OSSException - - if there was en error stopping persistance store
java.lang.InterruptedException - - if the server was stopped

startServer

protected static void startServer(Server srvServer)
                           throws OSSException
Start specified server. The functionality to start server was separated to this method so that derived classes can pass different kind of server to start.

Parameters:
srvServer - - server to start
Throws:
OSSException - - problem starting server
OSSException - - problem initializing the server

stopServer

protected static void stopServer(Server srvServer)
                          throws OSSException
Stop specified server.

Parameters:
srvServer - - server to stop
Throws:
OSSException - - problem stopping server

generateNewWebPort

protected static int generateNewWebPort(int iOldPort)
Generate new port number where to start the server if the old one failed.

Parameters:
iOldPort - - old port number which cannot be used
Returns:
int - new port number to try

addWebApplications

protected abstract void addWebApplications(org.mortbay.http.HttpServer hsServer)
Install web applications which should be run on the server.

Parameters:
hsServer - - HTTP server to install the applications to

initContext

protected void initContext(java.lang.String strURLPrefix,
                           org.mortbay.jetty.servlet.WebApplicationContext wacContext)
Initialize context (URL subtree) starting with given prefix. Default implementation setup JSP servlet and resource handler which will server files from the directory under webroot mathing the URL prefix and request URL. Overriding classes can e.g. setup it's own servlets, but it should do it before it calls the overriden method, because order matters.

Parameters:
strURLPrefix - - URL prefix which all requests to resources in this context will have.
wacContext - - context to setup


Copyright © 2003 - 2006 OpenSubsystems s.r.o.