Package dk.netarkivet.common.utils
Class ApplicationUtils
- java.lang.Object
-
- dk.netarkivet.common.utils.ApplicationUtils
-
public abstract class ApplicationUtils extends Object
This class provides functionality for starting applications.
-
-
Field Summary
Fields Modifier and Type Field Description 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 wrong arguments are given.
-
Constructor Summary
Constructors Constructor Description ApplicationUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
dirMustExist(File dir)
Ensure that a directory is available and writable.static void
startApp(LifeCycleComponent component)
Starts up an LifeCycleComponent.static void
startApp(Class c, String[] args)
Starts up an application.
-
-
-
Field Detail
-
WRONG_ARGUMENTS
public static final int WRONG_ARGUMENTS
System.exit() value for the case where wrong 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_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
-
-
Method Detail
-
startApp
public static void startApp(Class c, 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).
-
startApp
public static void startApp(LifeCycleComponent component)
Starts up an LifeCycleComponent.- Parameters:
component
- The component to start.
-
dirMustExist
public static void dirMustExist(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.
-
-