|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwt.util.AppStarter
Dynamically instantiates a specified implementation of ExecutableApp
and runs it's execute method.The AppStarter, creates a log in the
directory specified by the property wt.temp
into which all output to System.out
and System.err
is redirected. The AppStarter also ensures that wt.properties
and tools.properties
are loaded before instantiating the
ExecutableApp.
If a classpath other than the one specified in the environment is
desired, the caller be provide the name of a wt.properties
or tools.properties
property named in the option
-classpathProperty
. The property
value should contain the paths of all elements to be included in the
classpath
Examples
String class_name = "com.acme.Foo"; Hashtable options = new Hashtable(5); options.put(AppStarter.CLASSPATH_PROPERTY_OPT, "com.acme.foo.classpath"); String[] args = new String[]{ "bar", "baz", "baha" }; new AppStarter(class_name, options, args).startApp();Invocation from the command line is expected to look like:
java wt.util.AppStarter [-tee] [-logPrefix prefix] [-logBase baseName] [-append] [-classpathProperty prop-name] class-to-start [args-to-pass-to-app] e.g. java wt.util.AppStarter -append -classpathProperty com.acme.foo.classpath com.acme.Foo bar baz bahaProcess Termination
main(String[])
it is assumed that
the started ExecutableApp will exit the process
by calling System.exit(int)
or by exiting all non-daemon
Threads
when it is done.
Field Summary | |
private static String |
APPEND_TO_LOG_OPT
|
private String[] |
argsToPass
|
private String |
className
|
private static String |
CLASSPATH_PROPERTY_OPT
Name of option for providing an alternative classpath specified in the wt.properties or tools.properties files. |
private static boolean |
failOnExit
|
private static String |
HELP_OPT
|
private static String |
HIDE_CLASSPATH_OPT
|
private boolean |
isLogFileSetup
|
private boolean |
isOutputVisibleOnScreen
|
private static String |
LOG_BASE_OPT
|
private static String |
LOG_PREFIX_OPT
|
private String |
logFileBase
|
private String |
logFileName
|
private String |
logFilePrefix
|
private Hashtable |
options
|
private static String |
TEE_LOG_OUTPUT_OPT
|
private static String |
USAGE_MESSAGE
|
Constructor Summary | |
AppStarter(String class_name,
Hashtable options,
String[] args_to_pass)
Create an instance that will load and execute an instance of the class specified by class_name. |
Method Summary | |
private static String |
asOptString(String opt_name)
Returns a string that is '-' followed by the opt name. |
private void |
buildLogFileName()
Derive the location of the log file from the property wt.logs.dir and the name of the ExecutableApp class. |
private static void |
displayUsage()
Issue the usage message to the screen. |
static void |
failOnExit()
Will trigger System.exit(1) upon application completion. |
static void |
failOnExit(String message)
Will trigger System.exit(1) upon application completion. |
private ClassLoader |
getClassLoader(String classpath_prop_name)
Returns the appropriate class loader for instantiating the ExecutableApp. |
private static boolean |
isOptString(String value,
String opt_name)
Determines if the string value is a command-line options specifier for the supplied option name. |
private static boolean |
looksLikeOptString(String value)
True if the string value starts with '-'. |
static void |
main(String[] args)
Main entry point for the AppStarter. |
private void |
printClasspath(ClassLoader class_loader)
Prints the classpath being used by the class_loader, to System.out. |
private void |
printErrorMessage(Throwable t)
Perform the ugly logic to give the most useful error message... |
private static void |
processOptions(String[] args,
Hashtable options,
Vector args_to_pass)
Pick options out of args array. |
private String[] |
rebuildArgsToPass()
Create a new String[] containing the command line arguments needed to relaunch the AppStarter in a new classloader. |
private void |
setupLog()
Creates a log for the process using the name of the class to launch. |
private void |
setupProperties()
Initializes the WTContext and WTProperties including properties in tools.properties. |
static void |
setupProperties(String[] args)
Initializes the WTContext and WTProperties including properties in tools.properties. |
protected void |
startApp()
Loads properties then dynamically load and start the executable app. |
private void |
startAppWithCurrentClassLoader()
Dynamically instantiates the class from its name and whatever classloader we were loaded with, ensures that it implements ExecutableApp, casts it and calls its execute() method passing through all necessary arguments. |
private void |
startAppWithCustomClassLoader(String classpath_prop_name)
Relaunches AppStarter with a new classloader passing all arguments except those for specifying the classpathProperty. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final String CLASSPATH_PROPERTY_OPT
private static final String APPEND_TO_LOG_OPT
private static final String LOG_PREFIX_OPT
private static final String LOG_BASE_OPT
private static final String TEE_LOG_OUTPUT_OPT
private static final String HIDE_CLASSPATH_OPT
private static final String HELP_OPT
private static final String USAGE_MESSAGE
private Hashtable options
private String className
private String[] argsToPass
private boolean isOutputVisibleOnScreen
private boolean isLogFileSetup
private String logFilePrefix
private String logFileBase
private String logFileName
private static boolean failOnExit
Constructor Detail |
public AppStarter(String class_name, Hashtable options, String[] args_to_pass)
options
will be used to configure the classpath, and
the args_to_pass
will be passed to the ExecutableApp when
started.
Method Detail |
protected void startApp() throws Exception
If the option -classpathProperty is specified, the property will be looked up, a class loader will be created from the paths specified in the property value, and the AppStarter will be reinvoked sans the -classpathProperty option using the new classloader rather than the primordial classloader.
Exception
- if the class cannot found, loaded, cast to an ExecutableApp, or if it throws an unhandled exception when executedprivate void setupProperties() throws Exception
Exception
private void setupLog() throws Exception
Exception
private void buildLogFileName()
private void startAppWithCustomClassLoader(String classpath_prop_name) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException
Exception
- if the class cannot be found, loaded, cast to an ExecutableApp, or if it throws an unhandled exception
IOException
ClassNotFoundException
NoSuchMethodException
IllegalAccessException
InvocationTargetException
private void startAppWithCurrentClassLoader() throws ClassNotFoundException, IllegalAccessException, InstantiationException, WTException
private ClassLoader getClassLoader(String classpath_prop_name) throws IOException, MalformedURLException
IOException
MalformedURLException
private String[] rebuildArgsToPass()
private void printClasspath(ClassLoader class_loader)
private void printErrorMessage(Throwable t)
public static void main(String[] args)
AppStarter
private static void processOptions(String[] args, Hashtable options, Vector args_to_pass)
WTRuntimeException
- if help was asked for or if an unexpected option was encountered before the class nameprivate static boolean isOptString(String value, String opt_name)
private static boolean looksLikeOptString(String value)
private static String asOptString(String opt_name)
private static void displayUsage()
public static void setupProperties(String[] args) throws Exception
Exception
public static void failOnExit()
public static void failOnExit(String message)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |