public class ServiceLauncher<S extends org.apache.hadoop.service.Service> extends Object implements LauncherExitCodes, IrqHandler.Interrupted, Thread.UncaughtExceptionHandler
| Modifier and Type | Class and Description |
|---|---|
protected class |
ServiceLauncher.ServiceForcedShutdown
forced shutdown runnable.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
ARG_CONF
Name of the "--conf" argument.
|
static String |
NAME |
protected static int |
PRIORITY |
static String |
USAGE_MESSAGE |
EXIT_CLIENT_INITIATED_SHUTDOWN, EXIT_COMMAND_ARGUMENT_ERROR, EXIT_CONFLICT, EXIT_CONNECTIVITY_PROBLEM, EXIT_EXCEPTION_THROWN, EXIT_FALSE, EXIT_FORBIDDEN, EXIT_FOUND, EXIT_INTERNAL_ERROR, EXIT_INTERRUPTED, EXIT_MOVED, EXIT_NOT_ACCEPTABLE, EXIT_NOT_FOUND, EXIT_NOT_MODIFIED, EXIT_OPERATION_NOT_ALLOWED, EXIT_OTHER_FAILURE, EXIT_SERVICE_UNAVAILABLE, EXIT_SUCCESS, EXIT_TASK_LAUNCH_FAILURE, EXIT_UNAUTHORIZE, EXIT_UNIMPLEMENTED, EXIT_UNSUPPORTED_VERSION, EXIT_USAGE| Constructor and Description |
|---|
ServiceLauncher(String serviceClassName)
Create an instance of the launcher
|
| Modifier and Type | Method and Description |
|---|---|
protected org.apache.hadoop.util.ExitUtil.ExitException |
convertToExitException(Throwable thrown)
Convert the exception to one that can be handed off to ExitUtils;
if it is of the write type it is passed throw as is.
|
protected void |
error(String message,
Throwable thrown)
Report an error.
|
protected void |
exit(org.apache.hadoop.util.ExitUtil.ExitException ee)
Exit off an exception.
|
protected void |
exit(int exitCode,
String message)
Exit the code.
|
static String[] |
extractConfigurationArgs(org.apache.hadoop.conf.Configuration conf,
List<String> args)
Extract the configuration arguments and apply them to the configuration,
building an array of processed arguments to hand down to the service.
|
org.apache.hadoop.conf.Configuration |
getConfiguration()
Get the configuration constructed from the command line arguments
|
S |
getService()
Get the service.
|
int |
getServiceExitCode()
The exit code from a successful service execution
|
String |
getServiceName()
Get the service name via
Service.getName(). |
org.apache.hadoop.service.Service |
instantiateService(org.apache.hadoop.conf.Configuration conf)
Instantiate the service defined in
serviceClassName
. |
void |
interrupted(IrqHandler.InterruptData interruptData)
The service has been interrupted -try to shut down the service.
|
int |
launchService(org.apache.hadoop.conf.Configuration conf,
String[] processedArgs,
boolean addProcessHooks)
Launch the service, by creating it, initing it, starting it and then
maybe running it.
|
void |
launchServiceAndExit(List<String> args)
Parse the command line, building a configuration from it, then
launch the service and wait for it to finish.
|
org.apache.hadoop.util.ExitUtil.ExitException |
launchServiceRobustly(org.apache.hadoop.conf.Configuration conf,
String[] processedArgs)
Launch a service catching all exceptions and downgrading them to exit codes
after logging.
|
static void |
main(String[] args)
This is the main entry point for the service launcher.
|
protected void |
registerInterruptHandler()
Register this class as the handler for the control-C interrupt.
|
static void |
serviceMain(List<String> argsList)
The real main function, which takes the arguments as a list
arg 0 must be the service classname
|
static String |
startupShutdownMessage(String classname,
List<String> args)
Build a log message for starting up and shutting down.
|
String |
toString() |
void |
uncaughtException(Thread thread,
Throwable exception)
Uncaught exception handler.
|
protected void |
warn(String text)
Print a warning: currently this goes to stderr
|
protected static final int PRIORITY
public static final String NAME
public static final String ARG_CONF
public static final String USAGE_MESSAGE
public ServiceLauncher(String serviceClassName)
serviceClassName - classname of the servicepublic S getService()
launchService(Configuration, String[], boolean) has completedpublic org.apache.hadoop.conf.Configuration getConfiguration()
public int getServiceExitCode()
public int launchService(org.apache.hadoop.conf.Configuration conf,
String[] processedArgs,
boolean addProcessHooks)
throws Throwable
RunService.bindArgs(Configuration, String...) is invoked
on the service between creation and init.
All exceptions that occur are propagated upwards.
If the method returns a status code, it means that it got as far starting
the service, and if it implements RunService, that the
method RunService.runService() has completed.
At this point, the service is returned by getService().conf - configurationprocessedArgs - arguments after the configuration parameters
have been stripped out.addProcessHooks - should process failure handlers be added to
terminate this service on shutdown. Tests should set this to false.ClassNotFoundException - classname not on the classpathIllegalAccessException - not allowed at the classInstantiationException - not allowed to instantiate itInterruptedException - thread interruptedThrowable - any other failurepublic org.apache.hadoop.service.Service instantiateService(org.apache.hadoop.conf.Configuration conf)
throws ClassNotFoundException,
InstantiationException,
IllegalAccessException,
org.apache.hadoop.util.ExitUtil.ExitException,
NoSuchMethodException,
InvocationTargetException
serviceClassName
. Sets the configuration field
to the configuration, and service to the service.conf - configuration to useClassNotFoundException - classname not on the classpathIllegalAccessException - not allowed at the classInstantiationException - not allowed to instantiate itorg.apache.hadoop.util.ExitUtil.ExitExceptionNoSuchMethodExceptionInvocationTargetExceptionprotected void registerInterruptHandler()
public void interrupted(IrqHandler.InterruptData interruptData)
interrupted in interface IrqHandler.InterruptedinterruptData - the interrupted data.public void uncaughtException(Thread thread, Throwable exception)
uncaughtException in interface Thread.UncaughtExceptionHandlerthread - thread that failedexception - exceptionprotected void warn(String text)
text - protected void error(String message, Throwable thrown)
message - message for the userthrown - the exception thrownprotected void exit(int exitCode,
String message)
ExitUtil.ExitException instance.
The service launcher code assumes that after this method is invoked,
no other code in the same method is called.exitCode - code to exitprotected void exit(org.apache.hadoop.util.ExitUtil.ExitException ee)
ee - exit exceptionpublic String getServiceName()
Service.getName().
If the service is not instantiated, the classname is returned instead.public void launchServiceAndExit(List<String> args)
args - arguments to the service. arg[0] is
assumed to be the service classname and is automaticallypublic static String[] extractConfigurationArgs(org.apache.hadoop.conf.Configuration conf, List<String> args)
conf - configuration to updateargs - main arguments. args[0] is assumed to be the service
classname and is skippedpublic org.apache.hadoop.util.ExitUtil.ExitException launchServiceRobustly(org.apache.hadoop.conf.Configuration conf,
String[] processedArgs)
conf - configuration to useprocessedArgs - command line after the launcher-specific arguments have
been stripped outprotected org.apache.hadoop.util.ExitUtil.ExitException convertToExitException(Throwable thrown)
LauncherExitCodes.EXIT_EXCEPTION_THROWN
is created, with the argument thrown as the inner causethrown - the exception thrownpublic static String startupShutdownMessage(String classname, List<String> args)
classname - the class of the serverargs - argumentspublic static void serviceMain(List<String> argsList)
argsList - the list of argumentspublic static void main(String[] args)
args - command line arguments.Copyright © 2014–2015 The Apache Software Foundation. All rights reserved.