net.sf.spring.batch
Class BatchLauncher

java.lang.Object
  extended bynet.sf.spring.batch.BatchLauncher

public class BatchLauncher
extends Object

Advanced batch launcher.

Author:
willy
See Also:
CommandLineJobRunner

Field Summary
protected  LauncherConfiguration cfg
           
protected  ArgumentParser cmdParser
           
protected  Properties configurationProperties
           
protected  ConfigurableApplicationContext context
           
static int ERROR
           
protected  Logger log
           
protected  LogConfigurator logConfigurator
          instance in charge of configuring log4j.
static int OK
           
protected  PropertiesLoader propertiesLoader
          An instance used to load properties used in spring context.
static int STOP
           
 
Constructor Summary
BatchLauncher()
           
 
Method Summary
protected  File computeBatchHome()
          Computes the batch home directory.
protected  File computeConfDir()
          Computes the configuration directory.
 void exit(int status)
          Exit the batch, with the given code.
 int init(String[] args)
          parses the command line arguments and initializes logging, loads properties, and initializes spring context.
protected  void initContext()
          Initialize Spring context.
protected  void initLog4j()
          Initialize log4j.
protected  void loadProperties()
          Initialize properties.
static void main(String[] args)
          The entry point.
 int run()
          Manages operations according the command line parameters.
protected  int runJob()
          Run the spring job.
protected  int runResourceValidations()
          Run the resources validations.
protected  int runVersion()
          Print the batch version.
 void setExitCodeMapper(ExitCodeMapper exitCodeMapper)
          Injection setter for the ExitCodeMapper.
 void setJobLocator(JobLocator jobLocator)
          Injection setter for the JobLocator.
 void setJobParametersConverter(JobParametersConverter jobParametersConverter)
          Injection setter for the JobParametersConverter.
 void setLauncher(JobLauncher launcher)
          Injection setter for the JobLauncher.
 void setLog4jConfigurator(LogConfigurator logConfigurator)
          Setter for the LogConfigurator.
 void setPropertiesLoader(PropertiesLoader propertiesLoader)
          Setter for the PropertiesLoader.
 void setResourceValidationRunner(ResourceValidationRunner resourceValidationRunner)
          Injection setter for the ResourceValidationRunner.
 void setSystemExiter(SystemExiter systemExiter)
          Injection setter for the SystemExiter.
 void setVersionProvider(VersionProvider versionProvider)
          Injection setter for the VersionProvider.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OK

public static final int OK
See Also:
Constant Field Values

ERROR

public static final int ERROR
See Also:
Constant Field Values

STOP

public static final int STOP
See Also:
Constant Field Values

log

protected Logger log

logConfigurator

protected LogConfigurator logConfigurator
instance in charge of configuring log4j.


propertiesLoader

protected PropertiesLoader propertiesLoader
An instance used to load properties used in spring context.


cfg

protected LauncherConfiguration cfg

configurationProperties

protected Properties configurationProperties

context

protected ConfigurableApplicationContext context

cmdParser

protected ArgumentParser cmdParser
Constructor Detail

BatchLauncher

public BatchLauncher()
Method Detail

setLog4jConfigurator

public void setLog4jConfigurator(LogConfigurator logConfigurator)
Setter for the LogConfigurator. Instance of this class must not be wired by spring.

Parameters:
logConfigurator - the logConfigurator to set

setPropertiesLoader

public void setPropertiesLoader(PropertiesLoader propertiesLoader)
Setter for the PropertiesLoader. Instance of this class must not be wired by spring.

Parameters:
propertiesLoader - the propertiesLoader to set

setExitCodeMapper

public void setExitCodeMapper(ExitCodeMapper exitCodeMapper)
Injection setter for the ExitCodeMapper.

Parameters:
exitCodeMapper - the exitCodeMapper to set

setLauncher

public void setLauncher(JobLauncher launcher)
Injection setter for the JobLauncher.

Parameters:
launcher - the launcher to set

setJobLocator

public void setJobLocator(JobLocator jobLocator)
Injection setter for the JobLocator.

Parameters:
jobLocator - the jobLocator to set

setSystemExiter

public void setSystemExiter(SystemExiter systemExiter)
Injection setter for the SystemExiter.

Parameters:
systemExiter - the systemExiter to set

setJobParametersConverter

public void setJobParametersConverter(JobParametersConverter jobParametersConverter)
Injection setter for the JobParametersConverter.

Parameters:
jobParametersConverter - the jobParametersConverter to set

setResourceValidationRunner

public void setResourceValidationRunner(ResourceValidationRunner resourceValidationRunner)
Injection setter for the ResourceValidationRunner.

Parameters:
resourceValidationRunner - the resourceValidationRunner to set

setVersionProvider

public void setVersionProvider(VersionProvider versionProvider)
Injection setter for the VersionProvider.

Parameters:
versionProvider - the versionProvider to set

init

public int init(String[] args)
parses the command line arguments and initializes logging, loads properties, and initializes spring context.

Parameters:
args - the command line arguments.
Returns:
an exit status:
  • 0 if all is ok
  • 1 if there is an error
  • 2 if all is ok but we will stop processing before running the batch

initLog4j

protected void initLog4j()
Initialize log4j.


loadProperties

protected void loadProperties()
                       throws IOException
Initialize properties.

Throws:
IOException - when an io error occurs.

initContext

protected void initContext()
Initialize Spring context.


runJob

protected int runJob()
Run the spring job.

Returns:
an exit code from the job.

runResourceValidations

protected int runResourceValidations()
Run the resources validations.

Returns:
always 0.

runVersion

protected int runVersion()
Print the batch version.

Returns:
always 0.

computeBatchHome

protected File computeBatchHome()
Computes the batch home directory. Looks for the batch home parameter on the command line, then the system property: ${batch.name}.home, then for the environment variable: ${batch.name}.toUpperCase()_HOME, and finally the current directory.

Returns:
The batch home.

computeConfDir

protected File computeConfDir()
Computes the configuration directory. By default, ${batch.home}/conf is used, else the command line argument is used.

Returns:
the computed configuration directory.

run

public int run()
Manages operations according the command line parameters. Either launches resourceValidations, or displays version, or run the job.

Returns:
an exit code.

exit

public void exit(int status)
Exit the batch, with the given code.

Parameters:
status - an exit code value.

main

public static void main(String[] args)
The entry point.

Parameters:
args - the command line parameters.


Copyright © 2009. All Rights Reserved.