dk.netarkivet.common.utils
Class ApplicationUtils

java.lang.Object
  extended by dk.netarkivet.common.utils.ApplicationUtils

public abstract class ApplicationUtils
extends java.lang.Object

This class provides functionality for starting applications.


Field Summary
static int EXCEPTION_WHEN_ADDING_LIVENESSLOGGER
          System.exit() value for the case where the liveness logger for the application could not be started.
static int EXCEPTION_WHEN_ADDING_MANAGEMENT
          System.exit() value for the case where the management registration for the application could not be started.
static int EXCEPTION_WHEN_ADDING_SHUTDOWN_HOOK
          System.exit() value for the case where the Shutdown Hook for the application could not be added.
static int EXCEPTION_WHILE_INSTANTIATING
          System.exit() value for the case where the application class could not be instantiated.
static int NO_FACTORY_METHOD
          System.exit() value for the case where the application does not have a factory method.
static int WRONG_ARGUMENTS
          System.exit() value for the case where arguments are given.
 
Constructor Summary
ApplicationUtils()
           
 
Method Summary
static void dirMustExist(java.io.File dir)
          Ensure that a directory is available and writable.
static void startApp(java.lang.Class c, java.lang.String[] args)
          Starts up an application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WRONG_ARGUMENTS

public static final int WRONG_ARGUMENTS
System.exit() value for the case where arguments are given.

See Also:
Constant Field Values

NO_FACTORY_METHOD

public static final int NO_FACTORY_METHOD
System.exit() value for the case where the application does not have a factory method.

See Also:
Constant Field Values

EXCEPTION_WHILE_INSTANTIATING

public static final int EXCEPTION_WHILE_INSTANTIATING
System.exit() value for the case where the application class could not be instantiated.

See Also:
Constant Field Values

EXCEPTION_WHEN_ADDING_SHUTDOWN_HOOK

public static final int EXCEPTION_WHEN_ADDING_SHUTDOWN_HOOK
System.exit() value for the case where the Shutdown Hook for the application could not be added.

See Also:
Constant Field Values

EXCEPTION_WHEN_ADDING_LIVENESSLOGGER

public static final int EXCEPTION_WHEN_ADDING_LIVENESSLOGGER
System.exit() value for the case where the liveness logger for the application could not be started.

See Also:
Constant Field Values

EXCEPTION_WHEN_ADDING_MANAGEMENT

public static final int EXCEPTION_WHEN_ADDING_MANAGEMENT
System.exit() value for the case where the management registration for the application could not be started.

See Also:
Constant Field Values
Constructor Detail

ApplicationUtils

public ApplicationUtils()
Method Detail

startApp

public static void startApp(java.lang.Class c,
                            java.lang.String[] args)
Starts up an application. The applications class must: (i) Have a static getInstance() method which returns a an instance of itself (ii) Implement CleanupIF If the class cannot be started and a shutdown hook added, the JVM exits with a return code depending on the problem: 1 means wrong arguments 2 means no factory method exists for class 3 means couldn't instantiate class 4 means couldn't add shutdown hook 5 means couldn't add liveness logger 6 means couldn't add remote management

Parameters:
c - The class to be started
args - The arguments to the application (should be empty)

dirMustExist

public static void dirMustExist(java.io.File dir)
Ensure that a directory is available and writable. Will warn if the directory doesn't already exist (it ought to be created by the install script) and throws a PermissionDenied exception if the directory cannot be created.

Parameters:
dir - A File object denoting a directory
Throws:
PermissionDenied - if the directory doesn't exist and cannot be created/written to, or if the File object indicates an existing non-directory.