Spring for Apache Hadoop

org.springframework.yarn.launch
Class AbstractCommandLineRunner<T>

java.lang.Object
  extended by org.springframework.yarn.launch.AbstractCommandLineRunner<T>
Type Parameters:
T - the type of bean to run
Direct Known Subclasses:
CommandLineAppmasterRunner, CommandLineClientRunner, CommandLineContainerRunner

public abstract class AbstractCommandLineRunner<T>
extends java.lang.Object

Base implementation used for launching a Spring Application Context and executing a bean using a command line. This command line runner is meant to be used from a subclass.

The general idea of this launcher concept is to provide a way to define context config location, bean name for execution handling, options and a arguments. Possible examples are:

 contextConfig
 contextConfig,childContextConfig beanIdentifier
 contextConfig beanIdentifier <arguments>
 contextConfig <options> beanIdentifier
 contextConfig <options> beanIdentifier <arguments>
 <options> contextConfig <options> beanIdentifier <arguments>
 

Author:
Janne Valkealahti

Constructor Summary
AbstractCommandLineRunner()
           
 
Method Summary
protected  void doMain(java.lang.String[] args)
          Main method visible to sub-classes.
 void exit(int status)
          Exit method wrapping handling through SystemExiter.
protected  org.springframework.context.ConfigurableApplicationContext getApplicationContext(java.lang.String configLocation)
          Gets the Application Context.
protected  org.springframework.context.ConfigurableApplicationContext getChildApplicationContext(java.lang.String configLocation, org.springframework.context.ConfigurableApplicationContext parent)
          Gets the Application Context.
protected  java.lang.String getChildContextConfigPath(java.lang.String path)
          Allows subclass to modify parsed context configuration path.
protected  java.lang.String getContextConfigPath(java.lang.String path)
          Allows subclass to modify parsed context configuration path.
protected abstract  java.lang.String getDefaultBeanIdentifier()
          Gets a default bean id which is used to resolve the instance from an Application Context.
static java.lang.String getErrorMessage()
          Gets the static error message set for this class.
protected  java.util.List<java.lang.String> getValidOpts()
          Gets the list of valid option arguments.
protected abstract  ExitStatus handleBeanRun(T bean, java.lang.String[] parameters, java.util.Set<java.lang.String> opts)
          Handles the execution of a bean after Application Context(s) has been initialized.
static void presetSystemExiter(SystemExiter systemExiter)
          Sets the SystemExiter.
protected  int start(java.lang.String configLocation, java.lang.String masterIdentifier, java.lang.String childConfigLocation, java.lang.String[] parameters, java.util.Set<java.lang.String> opts)
          Builds the Application Context(s) and handles 'execution' of a bean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCommandLineRunner

public AbstractCommandLineRunner()
Method Detail

getErrorMessage

public static java.lang.String getErrorMessage()
Gets the static error message set for this class. This is useful for tests.

Returns:
the static error message

presetSystemExiter

public static void presetSystemExiter(SystemExiter systemExiter)
Sets the SystemExiter. Useful for testing.

Parameters:
systemExiter - the system exiter

handleBeanRun

protected abstract ExitStatus handleBeanRun(T bean,
                                            java.lang.String[] parameters,
                                            java.util.Set<java.lang.String> opts)
Handles the execution of a bean after Application Context(s) has been initialized. This is considered to be a main entry point what the application will do after initialization.

It is implementors responsibility to decide what to do with the given bean since this class only knows the typed bean instance.

Parameters:
bean - the bean instance
parameters - the parameters
opts - the options
Returns:
the exit status

getDefaultBeanIdentifier

protected abstract java.lang.String getDefaultBeanIdentifier()
Gets a default bean id which is used to resolve the instance from an Application Context.

Returns:
the id of the bean

getValidOpts

protected java.util.List<java.lang.String> getValidOpts()
Gets the list of valid option arguments. Default implementation returns null thus not allowing any options exist on a command line.

When overriding valid options make sure that options doesn't match anything else planned to be used in a command line. i.e. usually it's advised to prefix options with '-' character.

Returns:
the list of option arguments

getContextConfigPath

protected java.lang.String getContextConfigPath(java.lang.String path)
Allows subclass to modify parsed context configuration path. Effectively path returned from this method is used internally for the Application Context config location.

Default implementation just returns the given without modifying it.

Parameters:
path - the parsed config path
Returns:
the config path

getChildContextConfigPath

protected java.lang.String getChildContextConfigPath(java.lang.String path)
Allows subclass to modify parsed context configuration path. Effectively path returned from this method is used internally for the Application Context config location.

Default implementation just returns the given without modifying it.

Parameters:
path - the parsed config path
Returns:
the config path

start

protected int start(java.lang.String configLocation,
                    java.lang.String masterIdentifier,
                    java.lang.String childConfigLocation,
                    java.lang.String[] parameters,
                    java.util.Set<java.lang.String> opts)
Builds the Application Context(s) and handles 'execution' of a bean.

Parameters:
configLocation - the main context config location
masterIdentifier - the bean identifier
childConfigLocation - the child context config location
parameters - the parameters
opts - the options
Returns:
the status of the execution

getApplicationContext

protected org.springframework.context.ConfigurableApplicationContext getApplicationContext(java.lang.String configLocation)
Gets the Application Context.

Parameters:
configLocation - the context config location
Returns:
the configured context

getChildApplicationContext

protected org.springframework.context.ConfigurableApplicationContext getChildApplicationContext(java.lang.String configLocation,
                                                                                                org.springframework.context.ConfigurableApplicationContext parent)
Gets the Application Context.

Parameters:
configLocation - the context config location
parent - the parent context
Returns:
the configured context

exit

public void exit(int status)
Exit method wrapping handling through SystemExiter. This method mostly exist order to not do a real exit on a unit tests.

Parameters:
status - the exit code

doMain

protected void doMain(java.lang.String[] args)
Main method visible to sub-classes.

Parameters:
args - the Arguments

Spring for Apache Hadoop