org.springframework.batch.retry.policy
Class ExceptionClassifierRetryPolicy

java.lang.Object
  extended by org.springframework.batch.retry.policy.AbstractStatelessRetryPolicy
      extended by org.springframework.batch.retry.policy.ExceptionClassifierRetryPolicy
All Implemented Interfaces:
RetryPolicy

public class ExceptionClassifierRetryPolicy
extends AbstractStatelessRetryPolicy

A RetryPolicy that dynamically adapts to one of a set of injected policies according to the value of the latest exception.

Author:
Dave Syer

Constructor Summary
ExceptionClassifierRetryPolicy()
           
 
Method Summary
 boolean canRetry(RetryContext context)
          Delegate to the policy currently activated in the context.
 void close(RetryContext context)
          Delegate to the policy currently activated in the context.
 RetryContext open(RetryCallback callback, RetryContext parent)
          Create an active context that proxies a retry policy by chosing a target from the policy map.
 void registerThrowable(RetryContext context, Throwable throwable)
          Delegate to the policy currently activated in the context.
 void setExceptionClassifier(ExceptionClassifier exceptionClassifier)
          Setter for an exception classifier.
 void setPolicyMap(Map policyMap)
          Setter for policy map.
 
Methods inherited from class org.springframework.batch.retry.policy.AbstractStatelessRetryPolicy
handleRetryExhausted, shouldRethrow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExceptionClassifierRetryPolicy

public ExceptionClassifierRetryPolicy()
Method Detail

setPolicyMap

public void setPolicyMap(Map policyMap)
Setter for policy map. This property should not be changed dynamically - set it once, e.g. in configuration, and then don't change it during a running application.

Parameters:
policyMap - a map of String to RetryPolicy that will be applied to the result of the ExceptionClassifier to locate a policy.

setExceptionClassifier

public void setExceptionClassifier(ExceptionClassifier exceptionClassifier)
Setter for an exception classifier. The classifier is responsible for translating exceptions to keys in the policy map.

Parameters:
exceptionClassifier -

canRetry

public boolean canRetry(RetryContext context)
Delegate to the policy currently activated in the context.

Parameters:
context - the current retry status
Returns:
true if the operation can proceed
See Also:
RetryPolicy.canRetry(org.springframework.batch.retry.RetryContext)

close

public void close(RetryContext context)
Delegate to the policy currently activated in the context.

Parameters:
context - a retry status created by the RetryPolicy.open(RetryCallback, RetryContext) method of this manager.
See Also:
RetryPolicy.close(org.springframework.batch.retry.RetryContext)

open

public RetryContext open(RetryCallback callback,
                         RetryContext parent)
Create an active context that proxies a retry policy by chosing a target from the policy map.

Parameters:
callback - the RetryCallback that will execute the unit of work for this retry.
parent - the parent context if we are in a nested retry.
Returns:
a RetryContext object specific to this manager.
See Also:
RetryPolicy.open(org.springframework.batch.retry.RetryCallback, RetryContext)

registerThrowable

public void registerThrowable(RetryContext context,
                              Throwable throwable)
                       throws TerminatedRetryException
Delegate to the policy currently activated in the context.

Parameters:
context - the current status object.
Throws:
TerminatedRetryException - if the status is set to terminate only.
See Also:
RetryPolicy.registerThrowable(org.springframework.batch.retry.RetryContext, java.lang.Throwable)


Copyright © 2008 SpringSource. All Rights Reserved.