org.springframework.batch.repeat.policy
Class TimeoutTerminationPolicy

java.lang.Object
  extended by org.springframework.batch.repeat.policy.CompletionPolicySupport
      extended by org.springframework.batch.repeat.policy.TimeoutTerminationPolicy
All Implemented Interfaces:
CompletionPolicy

public class TimeoutTerminationPolicy
extends CompletionPolicySupport

Termination policy that times out after a fixed period. Allows graceful exit from a batch if the latest result comes in after the timeout expires (i.e. does not throw a timeout exception).
N.B. It may often be the case that the batch governed by this policy will be transactional, and the transaction might have its own timeout. In this case the transaction might throw a timeout exception on commit if its timeout threshold is lower than the termination policy.

Author:
Dave Syer

Nested Class Summary
protected  class TimeoutTerminationPolicy.TimeoutBatchContext
           
 
Field Summary
static long DEFAULT_TIMEOUT
          Default timeout value in millisecs (the value equivalent to 30 seconds).
 
Constructor Summary
TimeoutTerminationPolicy()
          Default constructor.
TimeoutTerminationPolicy(long timeout)
          Construct a TimeoutTerminationPolicy with the specified timeout value (in milliseconds).
 
Method Summary
 boolean isComplete(RepeatContext context)
          Check the timeout and complete gracefully if it has expires.
 RepeatContext start(RepeatContext context)
          Start the clock on the timeout.
 
Methods inherited from class org.springframework.batch.repeat.policy.CompletionPolicySupport
isComplete, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TIMEOUT

public static final long DEFAULT_TIMEOUT
Default timeout value in millisecs (the value equivalent to 30 seconds).

See Also:
Constant Field Values
Constructor Detail

TimeoutTerminationPolicy

public TimeoutTerminationPolicy()
Default constructor.


TimeoutTerminationPolicy

public TimeoutTerminationPolicy(long timeout)
Construct a TimeoutTerminationPolicy with the specified timeout value (in milliseconds).

Parameters:
timeout -
Method Detail

isComplete

public boolean isComplete(RepeatContext context)
Check the timeout and complete gracefully if it has expires.

Specified by:
isComplete in interface CompletionPolicy
Overrides:
isComplete in class CompletionPolicySupport
Parameters:
context - the current batch context.
Returns:
true if the batch should terminate.
See Also:
CompletionPolicy.isComplete(org.springframework.batch.repeat.RepeatContext)

start

public RepeatContext start(RepeatContext context)
Start the clock on the timeout.

Specified by:
start in interface CompletionPolicy
Overrides:
start in class CompletionPolicySupport
Parameters:
context - the current context if one is already in progress.
Returns:
a context object that can be used by the implementation to store internal state for a batch.
See Also:
CompletionPolicy.start(RepeatContext)


Copyright © 2009 SpringSource. All Rights Reserved.