Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2006-2007 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.springframework.batch.retry.policy;
 
 import java.util.Map;
 
A org.springframework.batch.retry.RetryPolicy that dynamically adapts to one of a set of injected policies according to the value of the latest exception.

Author(s):
Dave Syer
 
 public class ExceptionClassifierRetryPolicy implements RetryPolicy {
 
 			new NeverRetryPolicy());

Setter for policy map used to create a classifier. Either this property or the exception classifier directly should be set, but not both.

Parameters:
policyMap a map of Throwable class to org.springframework.batch.retry.RetryPolicy that will be used to create a org.springframework.batch.classify.Classifier to locate a policy.
 
 	public void setPolicyMap(Map<Class<? extends Throwable>, RetryPolicypolicyMap) {
 				policyMap, (RetryPolicynew NeverRetryPolicy());
 		this. = subclassClassifier;
 	}

Setter for an exception classifier. The classifier is responsible for translating exceptions to concrete retry policies. Either this property or the policy map should be used, but not both.

Parameters:
exceptionClassifier ExceptionClassifier to use
 
 	public void setExceptionClassifier(Classifier<ThrowableRetryPolicyexceptionClassifier) {
 		this. = exceptionClassifier;
 	}

Delegate to the policy currently activated in the context.

 
 	public boolean canRetry(RetryContext context) {
 		RetryPolicy policy = (RetryPolicycontext;
 		return policy.canRetry(context);
 	}

Delegate to the policy currently activated in the context.

 
 	public void close(RetryContext context) {
 		RetryPolicy policy = (RetryPolicycontext;
 		policy.close(context);
 	}

Create an active context that proxies a retry policy by chosing a target from the policy map.

 
 	public RetryContext open(RetryContext parent) {
 	}

	public void registerThrowable(RetryContext contextThrowable throwable) {
		RetryPolicy policy = (RetryPolicycontext;
		policy.registerThrowable(contextthrowable);
		((RetryContextSupportcontext).registerThrowable(throwable);
	}
	private static class ExceptionClassifierRetryContext extends RetryContextSupport implements RetryPolicy {
		// Dynamic: depends on the latest exception:
		// Dynamic: depends on the policy:
				Classifier<ThrowableRetryPolicyexceptionClassifier) {
			super(parent);
			this. = exceptionClassifier;
		}
		public boolean canRetry(RetryContext context) {
			if (this. == null) {
				// there was no error yet
				return true;
			}
			return .canRetry(this.);
		}
		public void close(RetryContext context) {
			// Only close those policies that have been used (opened):
			for (RetryPolicy policy : .keySet()) {
				policy.close(getContext(policycontext.getParent()));
			}
		}
		public RetryContext open(RetryContext parent) {
			return this;
		}
		public void registerThrowable(RetryContext contextThrowable throwable) {
			Assert.notNull("Could not locate policy for exception=[" + throwable + "].");
			this. = getContext(context.getParent());
			.registerThrowable(this.throwable);
		}
		private RetryContext getContext(RetryPolicy policyRetryContext parent) {
			RetryContext context = .get(policy);
			if (context == null) {
				context = policy.open(parent);
				.put(policycontext);
			}
			return context;
		}
	}
New to GrepCode? Check out our FAQ X