SK.gnome.dwarf.main
Class Main

java.lang.Object
  extended bySK.gnome.dwarf.main.Main

public class Main
extends java.lang.Object

The main executable class.

It constructs, starts and shuts down the main server object. Only one main server per JVM can be mantained by this class. The server object must be an instance of the MainServer class. The XMLConfiguration class is used to instantiate and configure the main server object.

Thread safety note: Both start(String) and shutdown(boolean) methods are thread safe and may be called simultaneously.


Constructor Summary
Main()
           
 
Method Summary
static java.lang.String getConfigurationURL()
          Returns the configuration URL.
static MainServer getMainServer()
          Returns the main server.
static boolean checkDwarfVersion(java.lang.String version)
          Checks the framework specification version.
static void main(java.lang.String[] args)
          Starts the main server.
static void shutdown(boolean exit)
          Shuts down the main server.
static void start(java.lang.String url)
          Starts the main server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Main

public Main()
Method Detail

main

public static void main(java.lang.String[] args)
                 throws XMLConfigurationException,
                        ServiceException
Starts the main server.

This method requires one argument which must be an URL from which the XMLConfiguration instance will load the server configuration.

This method calls start method to do the actual job.

Parameters:
args - the command-line arguments
Throws:
XMLConfigurationException - if an error occured in the XML configuration
ServiceException - if an error occured while initializing or starting the application

start

public static void start(java.lang.String url)
                  throws XMLConfigurationException,
                         ServiceException
Starts the main server.

The url argument must be an URL from which the XMLConfiguration instance will load the server configuration.

This method returns silently if an instance of the main server is already running, or either the starting or the shutdown process is already in a progress.

The service being constructed from the XML must be an instance of the MainServer class.

If a security manager is installed, the ServicePermission "startMainServer" is checked first.

The following code snippet illustrates restarting of the main server without changing its current configuration:

   Main.shutdown(false);
   Main.start(Main.getConfigurationURL());
 

This method adds a custom shutdown hook to the current Runtime object for correct shutting down of the main server instance in the case of an unexpected JVM shutdown. It is added only if the SK.gnome.dwarf.main.disableShutdownHook system property is not set.

Parameters:
url - URL of the XML-based configuration
Throws:
XMLConfigurationException - if an error occured in the XML configuration
ServiceException - if an error occured while initializing or starting the server

shutdown

public static void shutdown(boolean exit)
Shuts down the main server.

The method returns silently if either the starting or the shutdown process is already in the progress.

If the exit argument is true the method forces JVM to exit by calling System.exit(0). This is done even if there is no main server instance available, , i.e. the start(String) method has never been executed successfully.

If a security manager is installed, the ServicePermission "shutdownMainServer" is checked first.

Parameters:
exit - whether to terminate the JVM

getConfigurationURL

public static java.lang.String getConfigurationURL()
Returns the configuration URL.

It returns the configuration URL of the current main server instance.

Returns:
the url

getMainServer

public static MainServer getMainServer()
Returns the main server.

Returns a reference to the current main server instance. The server instance may be in any transition state, therefore the Service.getState(int) method must be called on it in order to get its actual state.

If a security manager is installed, the ServicePermission "getMainServer" is checked prior to returning the object.

See Also:
MainServer

checkDwarfVersion

public static boolean checkDwarfVersion(java.lang.String version)
Checks the framework specification version.

For example, a Dwarf Mail Server version 1.0.0. may require the Dwarf Server Framework version 1.2 or higher. This method may be used to check the framework specification version against the given version argument. The version argument must be given as a sequence of two or more numbers separated by dots.

Parameters:
version - desired version number
Returns:
true if the framework version is equal or higher than the desired one


Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.