org.iges.anagram
Class Server

java.lang.Object
  |
  +--org.iges.anagram.Server
All Implemented Interfaces:
Module

public class Server
extends java.lang.Object
implements Module

The top-level module of the Anagram framework. All other modules share a reference to a single Server instance.

The Server class performs four basic functions. It obtains Anagram properties from the enviroment, creates the modules that will make up the server, initiates the configuration process, and provides each module with access to the others.

Anagram properties are mostly intended to be set by the developer, not the user, and are guaranteed not to change during the life of the server (unlike configuration settings from the configuration file). They include basic things such as the name of the Anagram implementation, and its support home page.

The modules that will make up the Anagram implementation are created by the Server module at startup. Dynamic module creation may be supported in the future, but for now, the module structure of the server does not change over the lifetime of the Server.

In contrast, the server's configuration can change multiple times during the life of the server. Configuration is performed once when the server is created, but may also be triggered again by an administrative request. This allows the server's settings and data holdings to be updated without restarting the servlet or its container.

Configuration consists of parsing the XML configuration file specified by the Anagram property "anagram.config", and passing the appropriate portions of it to the configure() methods of the various modules.

Finally, each module can access other modules using its reference to the Server. Since modules remain constant for the lifetime of the server, it is safe for a module to save the references it obtains from the server.


Field Summary
protected  Catalog catalog
           
protected  java.io.File configFile
           
protected  java.lang.String implClass
           
protected  java.lang.String implHome
           
protected  java.lang.String implLongName
           
protected  java.lang.String implName
           
protected  java.lang.String implVersion
           
protected  long lastConfigTime
           
protected  Log log
           
protected  Mapper mapper
           
protected  int outputLevel
           
protected  PrivilegeMgr privilegeMgr
           
protected  java.lang.String serverHome
           
protected  java.lang.String serverName
           
protected  AnagramServlet servlet
           
protected  java.lang.String siteHome
           
protected  long startTime
           
protected  Store store
           
protected  ExclusiveLock synch
           
protected  Tool tool
           
 
Constructor Summary
Server(AnagramServlet servlet, ServletConfig servletConfig)
          Creates a new instance of the Anagram framework connected to the servlet specified .
 
Method Summary
protected  void configModule(Module module, Setting setting)
           
 void configure(Setting setting)
          This method should not be called from outside Server.
protected  void createModules()
          Creates the components of the server
 void destroy()
          Shuts down the server
protected  void fail(java.lang.String msg, java.lang.Throwable t)
           
 Catalog getCatalog()
          Returns a handle to the data object catalog
 java.lang.String getHome()
          Returns the home directory of the server installation.
 java.lang.String getImplHomePage()
          Returns a URL where more information can be obtained about this Anagram implementation, so that it can be included in web pages and user messages.
 java.lang.String getImplName()
          Returns the descriptive name of this Anagram implementation, so that it can be included in web pages and user messages.
 java.lang.String getImplVersion()
          Returns the version number for this Anagram implementation, so that it can be included in web pages and user messages.
 long getLastConfigTime()
          Returns the last time that the server's configuration changed, or else the time that the server was created.
 Log getLog()
          Returns a handle to the logger
 Mapper getMapper()
          Returns a handle to the service mapper
 java.lang.String getModuleID()
          The module ID of the server is determined by the Anagram property "anagram.impl".
 java.lang.String getModuleName()
          Because the server is the top-level module, its module name is identical to its module ID.
 PrivilegeMgr getPrivilegeMgr()
          Returns a handle to the privilege manager
protected  java.lang.String getProperty(ServletConfig config, java.lang.String name, java.lang.String defaultValue)
           
 java.lang.String getServerName()
          Returns the descriptive name of this server instance.
 AnagramServlet getServlet()
          Returns a handle to the servlet
 java.lang.String getSiteHomePage(java.lang.String defaultHome)
          Returns the home page for this server instance.
 Store getStore()
          Returns a handle to the temporary storage interface
 ExclusiveLock getSynch()
          Used to synchronize operations on the entire server.
 Tool getTool()
          Returns a handle to the data tool
 void init(Server server, Module parent)
          Does nothing for Server
protected  Setting loadConfig()
           
protected  void log(int level, java.lang.String msg)
           
 void reconfigure()
          Checks the configuration file, and if it has been modified, parses it and reconfigures the entire server to the new settings.
protected  void startLog(Setting setting)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

synch

protected ExclusiveLock synch

outputLevel

protected int outputLevel

implClass

protected java.lang.String implClass

implName

protected java.lang.String implName

implLongName

protected java.lang.String implLongName

implVersion

protected java.lang.String implVersion

implHome

protected java.lang.String implHome

serverName

protected java.lang.String serverName

siteHome

protected java.lang.String siteHome

serverHome

protected java.lang.String serverHome

configFile

protected java.io.File configFile

lastConfigTime

protected long lastConfigTime

startTime

protected long startTime

tool

protected Tool tool

mapper

protected Mapper mapper

log

protected Log log

store

protected Store store

catalog

protected Catalog catalog

privilegeMgr

protected PrivilegeMgr privilegeMgr

servlet

protected AnagramServlet servlet
Constructor Detail

Server

public Server(AnagramServlet servlet,
              ServletConfig servletConfig)
       throws ServletException
Creates a new instance of the Anagram framework connected to the servlet specified . This method is called by AnagramServlet.init().

Method Detail

getSynch

public ExclusiveLock getSynch()
Used to synchronize operations on the entire server. Each client request holds a non-exclusive lock on the server while it is being processed. The configuration process obtains an exclusive lock on the server, thus guaranteeing that no requests will be in-process while the server is re-configuring itself.


getModuleID

public java.lang.String getModuleID()
The module ID of the server is determined by the Anagram property "anagram.impl". This should be a short alpha-numeric abbrevation of the implementation name. For instance My Anagram Implementation might be condensed to "my_agm", or "mai". It must be a legal XML tag name.

Specified by:
getModuleID in interface Module

getModuleName

public java.lang.String getModuleName()
Because the server is the top-level module, its module name is identical to its module ID.

Specified by:
getModuleName in interface Module

getServerName

public java.lang.String getServerName()
Returns the descriptive name of this server instance. This is a configuration property, not an Anagram property.


getSiteHomePage

public java.lang.String getSiteHomePage(java.lang.String defaultHome)
Returns the home page for this server instance. This is a configuration property, not an Anagram property.


getHome

public java.lang.String getHome()
Returns the home directory of the server installation. This should be the base for resolving all relative file paths specified in the configuration file. This is should not be confused with getSiteHomePage() and getImplHomePage(), which are URLs. This is the Anagram property "anagram.home".

See Also:
FileResolver

getImplName

public java.lang.String getImplName()
Returns the descriptive name of this Anagram implementation, so that it can be included in web pages and user messages. This is Anagram property "anagram.impl_long".


getImplVersion

public java.lang.String getImplVersion()
Returns the version number for this Anagram implementation, so that it can be included in web pages and user messages. This is Anagram property "anagram.impl_version".


getImplHomePage

public java.lang.String getImplHomePage()
Returns a URL where more information can be obtained about this Anagram implementation, so that it can be included in web pages and user messages. This is Anagram property "anagram.impl_home".


fail

protected void fail(java.lang.String msg,
                    java.lang.Throwable t)
             throws ServletException
ServletException

init

public void init(Server server,
                 Module parent)
Does nothing for Server

Specified by:
init in interface Module

reconfigure

public void reconfigure()
                 throws ModuleException
Checks the configuration file, and if it has been modified, parses it and reconfigures the entire server to the new settings. This operation should only be performed by a thread that has an exclusive lock on the Server module.

ModuleException

configure

public void configure(Setting setting)
               throws ConfigException
This method should not be called from outside Server. Configures all the server modules except the log module, which is handled separately so that it can be initialized immediately on startup.

Specified by:
configure in interface Module
Throws:
ConfigException - If the module is unable to operate using the settings provided. This will halt the server's operation, and thus should only be thrown if there is no reasonable default that can be used in place of a missing or invalid setting.

getLastConfigTime

public long getLastConfigTime()
Returns the last time that the server's configuration changed, or else the time that the server was created.


getMapper

public Mapper getMapper()
Returns a handle to the service mapper


getServlet

public AnagramServlet getServlet()
Returns a handle to the servlet


getTool

public Tool getTool()
Returns a handle to the data tool


getLog

public Log getLog()
Returns a handle to the logger


getStore

public Store getStore()
Returns a handle to the temporary storage interface


getCatalog

public Catalog getCatalog()
Returns a handle to the data object catalog


getPrivilegeMgr

public PrivilegeMgr getPrivilegeMgr()
Returns a handle to the privilege manager


destroy

public void destroy()
Shuts down the server


getProperty

protected java.lang.String getProperty(ServletConfig config,
                                       java.lang.String name,
                                       java.lang.String defaultValue)

loadConfig

protected Setting loadConfig()
                      throws ConfigException
ConfigException

startLog

protected void startLog(Setting setting)
                 throws ConfigException
ConfigException

createModules

protected void createModules()
                      throws ConfigException
Creates the components of the server

ConfigException

configModule

protected void configModule(Module module,
                            Setting setting)
                     throws ConfigException
ConfigException

log

protected void log(int level,
                   java.lang.String msg)