public final class Launcher extends Object
Component
instance.
The Launcher
class provides the main(String...)
method for instantiating,
starting and stopping a Component
instance, which is configured via system properties
and command line arguments.
The Launcher
class is meant to be used in shell scripts provided by application
developers whose goal is to run a service. With respect to application developers, the
behaviour of the Launcher
can be configured by supplying a number of system properties
(can be easily done when invoking the JVM in scripts). The following (optional) system
properties are supported:
launcher.executable
- the name of the command line executable / script, used for
logging and generating the help message;launcher.description
- a description telling what the program does, used for
generating the help message;launcher.config
- default location of configuration file / resource;launcher.logging
- default location of Logback configuration file (to be used in
case the location in the configuration is missing or wrong)
The end user is instead supposed to interact with the Launcher
via command line options
and by supplying a configuration file that controls how the component should be instantiated.
The following command line options are recognized and documented to end user:
-c, --config
- the location of the configuration file / resource (if not supplied,
the default is used);-v, --version
- causes the program to display version and copyright information,
and then terminate;-h, --help
- causes the program to display the help message, and then terminate.
Concerning the configuration, it must be supplied in an RDF file (any syntax supported by
Sesame is fine) whose content is fed to Factory
to instantiate the Component
and its dependencies. Inside the configuration file, triples having as subject
<obj:launcher>
are specified by the user to control details of the execution
environment (threading, logging) and to specify which component to instantiate. More in
details, the following triples are recognized:
<obj:launcher> <java:logConfig> "LOCATION"
- supplies the location of the logback
configuration file;<obj:launcher> <java:threadName> "PATTERN"
- supplies the pattern for thread names
(default is worker-%02d
);<obj:launcher> <java:threadCount> "COUNT"^^^xsd:int
- supplies the number of
threads in the pool (default is 32);<obj:launcher> <java:component> <java:....>
- specifies the component to
instantiate and run as service.
The main()
method retrieves system properties and command line options. It then handles
-v
and -h
requests, if supplied, otherwise proceeds with loading the
configuration and launching the component. Two operation modes are supported:
q
/ SIGING (CTRL-C) causes the component to
be stopped and the program to terminate. Key r
/ SIGUSR2 causes the component to be
stopped and reinstantiated / restarted, with the configuration being reloaded. Key i
causes status information to be displayed on STDOUT. Status information includes uptime,
memory, GC and threads statistics; in addition, ThreadMXBean.findDeadlockedThreads()
is
used to detect and report possible thread deadlocks.org.apache.commons.daemon.support.DaemonWrapper
and configuring it to lanch this class,
supplying additional arguments __start
to start the application and __stop
to
stop it. In this case no signal handling or console monitoring is performed, relying on
Commons-Daemon for managing the lifecycle of the program.
The main()
method returns as exit codes the following 'pseudo' standard values (see
sysexit.h
):
public static void main(String... args)
args
- command line argumentsCopyright © 2015–2016 FBK-irst. All rights reserved.