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.support;
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.

Author(s):
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.

Returns:
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.

Parameters:
context the new context to register
Returns:
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.

Returns:
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