C# Class Summer.Batch.Infrastructure.Repeat.Support.RepeatTemplate

Simple implementation and base class for batch templates implementing RepeatOperations. Provides a framework including interceptors and policies. Subclasses just need to provide a method that gets the next result and one that waits for all the results to be returned from concurrent processes or threads. N.B. the template accumulates thrown exceptions during the iteration, and they are all processed together when the main loop ends (i.e. finished processing the items). Clients that do not want to stop execution when an exception is thrown can use a specific ICompletionPolicy that does not finish when exceptions are received. This is not the default behaviour. Clients that want to take some business action when an exception is thrown by the IRepeatCallback can consider using a custom IRepeatListener instead of trying to customise the ICompletionPolicy. This is generally a friendlier interface to implement, and the IRepeatListener#After(RepeatContext, RepeatStatus) method is passed in the result of the callback, which would be an instance of Exception if the business processing had thrown an exception. If the exception is not to be propagated to the caller, then a non-default ICompletionPolicy needs to be provided as well, but that could be off the shelf, with the business action implemented only in the interceptor.
Inheritance: IRepeatOperations
Mostrar archivo Open project: SummerBatch/SummerBatch

Protected Properties

Property Type Description
Logger NLog.Logger

Public Methods

Method Description
Iterate ( RepeatCallback callback ) : RepeatStatus

Execute the batch callback until the completion policy decides that we are finished. Wait for the whole batch to finish before returning even if the task executor is asynchronous.

RegisterListener ( IRepeatListener listener ) : void

Registers given listener.

SetListeners ( IRepeatListener listeners ) : void

Registers array of listeners.

Protected Methods

Method Description
CanContinue ( RepeatStatus value ) : bool

Check return value from batch operation.

CreateInternalState ( IRepeatContext context ) : IRepeatInternalState

Create an internal state object that is used to store data needed internally in the scope of an iteration. Used by subclasses to manage the queueing and retrieval of asynchronous results. The default just provides an accumulation of exceptions instances for processing at the end of the batch.

ExecuteAfterInterceptors ( IRepeatContext context, RepeatStatus value ) : void

Convenience method to execute after interceptors on a callback result.

GetNextResult ( IRepeatContext context, RepeatCallback callback, IRepeatInternalState state ) : RepeatStatus

Get the next completed result, possibly executing several callbacks until one finally finishes. Normally a subclass would have to override both this method and CreateInternalState because the implementation of this method would rely on the details of the internal state.

IsComplete ( IRepeatContext context ) : bool

Delegates to the Completion policy.

IsComplete ( IRepeatContext context, RepeatStatus result ) : bool

Delegates to the Completion policy.

Start ( ) : IRepeatContext

Delegates the start to the Completion policy.

Update ( IRepeatContext context ) : void

Delegates to the completion policy.

WaitForResults ( IRepeatInternalState state ) : bool

If necessary, wait for results to come back from remote or concurrent processes. By default does nothing and returns true.

Private Methods

Method Description
DoHandle ( System exception, IRepeatContext context, ICollection deferred ) : void

Handling exceptions.

ExecuteInternal ( RepeatCallback callback ) : RepeatStatus

HandleFinally ( ICollection deferred, IRepeatListener listeners, IRepeatContext context ) : void

Handling the finally from ExecuteInternal.

IsMarkedComplete ( IRepeatContext context ) : bool

Check that given context is marked as completed.

Rethrow ( System exception ) : void

rethrow the exception wrapped into a RepeatException.

UnwrapIfRethrown ( System exception ) : System.Exception

Unwrap the exception id it has been wrapped into a RepeatException.

Method Details

CanContinue() protected method

Check return value from batch operation.
protected CanContinue ( RepeatStatus value ) : bool
value RepeatStatus
return bool

CreateInternalState() protected method

Create an internal state object that is used to store data needed internally in the scope of an iteration. Used by subclasses to manage the queueing and retrieval of asynchronous results. The default just provides an accumulation of exceptions instances for processing at the end of the batch.
protected CreateInternalState ( IRepeatContext context ) : IRepeatInternalState
context IRepeatContext
return IRepeatInternalState

ExecuteAfterInterceptors() protected method

Convenience method to execute after interceptors on a callback result.
protected ExecuteAfterInterceptors ( IRepeatContext context, RepeatStatus value ) : void
context IRepeatContext
value RepeatStatus
return void

GetNextResult() protected method

Get the next completed result, possibly executing several callbacks until one finally finishes. Normally a subclass would have to override both this method and CreateInternalState because the implementation of this method would rely on the details of the internal state.
 
protected GetNextResult ( IRepeatContext context, RepeatCallback callback, IRepeatInternalState state ) : RepeatStatus
context IRepeatContext
callback RepeatCallback
state IRepeatInternalState
return RepeatStatus

IsComplete() protected method

Delegates to the Completion policy.
protected IsComplete ( IRepeatContext context ) : bool
context IRepeatContext
return bool

IsComplete() protected method

Delegates to the Completion policy.
protected IsComplete ( IRepeatContext context, RepeatStatus result ) : bool
context IRepeatContext
result RepeatStatus
return bool

Iterate() public method

Execute the batch callback until the completion policy decides that we are finished. Wait for the whole batch to finish before returning even if the task executor is asynchronous.
public Iterate ( RepeatCallback callback ) : RepeatStatus
callback RepeatCallback
return RepeatStatus

RegisterListener() public method

Registers given listener.
public RegisterListener ( IRepeatListener listener ) : void
listener IRepeatListener
return void

SetListeners() public method

Registers array of listeners.
public SetListeners ( IRepeatListener listeners ) : void
listeners IRepeatListener
return void

Start() protected method

Delegates the start to the Completion policy.
protected Start ( ) : IRepeatContext
return IRepeatContext

Update() protected method

Delegates to the completion policy.
protected Update ( IRepeatContext context ) : void
context IRepeatContext
return void

WaitForResults() protected method

If necessary, wait for results to come back from remote or concurrent processes. By default does nothing and returns true.
protected WaitForResults ( IRepeatInternalState state ) : bool
state IRepeatInternalState
return bool

Property Details

Logger protected_oe static_oe property

Logger
protected static Logger,NLog Logger
return NLog.Logger