net.sf.mybatchfwk
Class BatchService

java.lang.Object
  extended by net.sf.mybatchfwk.BatchService

public class BatchService
extends java.lang.Object

The class used to launch the batch.

Automatic launching:
- define configuration into the file 'my-batch-fwk.properties'
- call the main method

Manual launching:
- build an instance of BatchConfiguration
- call the init method
- call the launch method

Note: the BatchConfiguration instance can be build from the properties of the configuration file (see PropertiesLoader.getProperties).

The execution of the batch can be managed through JMX (ObjectName=net.sf.mybatchfwk:type=BatchService).

Author:
Jérôme Bertèche (cyberteche@users.sourceforge.net)

Nested Class Summary
static class BatchService.STATE
          The state of the batch
 
Constructor Summary
BatchService()
           
 
Method Summary
protected  void afterExecute(ITask task, java.lang.Throwable throwable)
          Report an execution termination
protected  void awaitServiceTermination(java.util.concurrent.ExecutorService service)
          Wait for the termination of the service
 boolean canBeExecuted(ITask task)
          Determine if a task can be executed or not
protected  void executeBatch()
          Method in which the batch is executed
 ExecutionReport getExecutionReport()
           
static BatchService getInstance()
          In standalone mode the instance is referenced as a static member
 BatchService.STATE getState()
           
 ITaskExecutor getThreadPoolExecutor()
           
 void init(BatchConfiguration conf)
          Initialization method.
 void launch()
          Launch the batch
static void main(java.lang.String[] args)
          Main method to start the batch service in standalone mode.
 void manageFatalError(java.lang.Throwable throwable)
          Manage a fatal error during the batch execution that cause a crash
 void pause()
          Suspends the execution of the batch/executor/schedule services.
 void prepareForLaunch()
          Called just before the execution of the batch.
 void restart()
          Restart the execution of the batch.
 void resume()
          Resume the execution of the batch/executor/schedule services.
 void setBatch(IBatch batch)
           
protected  void setState(BatchService.STATE newState)
          Set the new state of the batch and process to the notification of the new state if jmx is enable
 void shutdown(boolean waitForSubmittedTasks)
          Stop the execution of the batch.
protected  void shutdownScheduleService()
          Shutdown the schedule service
protected  void sleepBatchService()
          Put the batch service on the sleep mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BatchService

public BatchService()
Method Detail

getInstance

public static BatchService getInstance()
In standalone mode the instance is referenced as a static member

Returns:

main

public static void main(java.lang.String[] args)
Main method to start the batch service in standalone mode. Configuration is load from the config file.

Parameters:
args - no args

init

public void init(BatchConfiguration conf)
          throws BatchException
Initialization method.
Build the batch object if needed and initialize it.

Parameters:
config - the configuration
Throws:
BatchException

prepareForLaunch

public void prepareForLaunch()
                      throws BatchException
Called just before the execution of the batch.
Check the consistency of the configuration and build the executor service.

Throws:
BatchException

launch

public void launch()
            throws BatchException
Launch the batch

Throws:
BatchException

executeBatch

protected void executeBatch()
                     throws BatchException
Method in which the batch is executed

Throws:
BatchException

shutdownScheduleService

protected void shutdownScheduleService()
Shutdown the schedule service


sleepBatchService

protected void sleepBatchService()
                          throws BatchException
Put the batch service on the sleep mode.

Throws:
BatchException

awaitServiceTermination

protected void awaitServiceTermination(java.util.concurrent.ExecutorService service)
                                throws BatchException
Wait for the termination of the service

Parameters:
service -
Throws:
BatchException

setState

protected void setState(BatchService.STATE newState)
Set the new state of the batch and process to the notification of the new state if jmx is enable

Parameters:
newState -

canBeExecuted

public boolean canBeExecuted(ITask task)
                      throws BatchException
Determine if a task can be executed or not

Parameters:
task -
Returns:
Throws:
BatchException

afterExecute

protected void afterExecute(ITask task,
                            java.lang.Throwable throwable)
Report an execution termination

Parameters:
task -
throwable -

manageFatalError

public void manageFatalError(java.lang.Throwable throwable)
Manage a fatal error during the batch execution that cause a crash

Parameters:
throwable -

pause

public void pause()
           throws java.lang.Exception
Suspends the execution of the batch/executor/schedule services. Called through JMX.

Throws:
java.lang.Exception

resume

public void resume()
            throws java.lang.Exception
Resume the execution of the batch/executor/schedule services. Called through JMX.

Throws:
java.lang.Exception

shutdown

public void shutdown(boolean waitForSubmittedTasks)
              throws java.lang.Exception
Stop the execution of the batch. Called through JMX.

Parameters:
waitForSubmittedTasks - if true, then waits for the execution of the submitted tasks before to terminate.
Throws:
java.lang.Exception

restart

public void restart()
             throws java.lang.Exception
Restart the execution of the batch. Called through JMX.

Throws:
BatchException
java.lang.Exception

getThreadPoolExecutor

public ITaskExecutor getThreadPoolExecutor()
Returns:
the executor used to execute tasks

getState

public BatchService.STATE getState()
Returns:
the current state of the batch service

setBatch

public void setBatch(IBatch batch)
Parameters:
batch - The batch to set.

getExecutionReport

public ExecutionReport getExecutionReport()
Returns:
Returns the executionReport.


Copyright © 2006 null. All Rights Reserved.