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
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
Global variable support for retry clients. Normally it is not necessary for clients to be aware of the surrounding environment because a org.springframework.batch.retry.RetryCallback can always use the context it is passed by the enclosing org.springframework.batch.retry.RetryOperations. But occasionally it might be helpful to have lower level access to the ongoing org.springframework.batch.retry.RetryContext so we provide a global accessor here. The mutator methods (clear() and register(org.springframework.batch.retry.RetryContext) should not be used except internally by org.springframework.batch.retry.RetryOperations implementations.

Dave Syer
public final class RetrySynchronizationManager {
	private static final ThreadLocal<RetryContextcontext = new ThreadLocal<RetryContext>();

Public accessor for the locally enclosing org.springframework.batch.retry.RetryContext.

the current retry context, or null if there isn't one
	public static RetryContext getContext() {
		return result;

Method for registering a context - should only be used by org.springframework.batch.retry.RetryOperations implementations to ensure that getContext() always returns the correct value.

context the new context to register
the old context if there was one
	public static RetryContext register(RetryContext context) {
		RetryContext oldContext = getContext();
		return oldContext;

Clear the current context at the end of a batch - should only be used by org.springframework.batch.repeat.RepeatOperations implementations.

the old value if there was one.
	public static RetryContext clear() {
		RetryContext value = getContext();
		RetryContext parent = value == null ? null : value.getParent();
		return value;
New to GrepCode? Check out our FAQ X